123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- import bge
- cont = bge.logic.getCurrentController()
- own = cont.owner
-
-
- os = 'Windows'
- from sys import platform
- if platform != "win32":
- os = 'Linux'
- def onWindows():
- return os == 'Windows'
-
- reduction = 400000
- axisTh = 0.03
-
- #Sensor logic bricks connected to the python Controller
- aXis = cont.sensors["sControla"]
- bUtt = cont.sensors["sControlb"]
-
- onW = onWindows()
-
- # windows stuff
- lar_lts = 0
- uad_lts = 1
- lt = 4 if onW else 2
- lar_rts = 2 if onW else 3
- uad_rts = 3 if onW else 4
- rt = 5
-
- # These are the numerical values associated with the buttons on the Xbox Controller
- # Called with - SensorName.getButtonStatus(buttonnumber) -
- # A joystick sensor logic brick (with the 'Button' Event Type; 'All Events' selected; and 'Tap' enabled) must be connected to the Python Controller logic brick to call these buttons
-
- a_but = 0 if onW else 0
- b_but = 1 if onW else 1
- x_but = 2 if onW else 2
- y_but = 3 if onW else 3
- l_bump = 9 if onW else 4
- r_bump = 10 if onW else 5
- bk_but = 4 if onW else 6
- st_but = 6 if onW else 7
- xb_but = 5 if onW else 8
- lts_pr = 7 if onW else 9
- rts_pr = 8 if onW else 10
- l_dp = 13 if onW else 11
- r_dp = 14 if onW else 12
- u_dp = 11 if onW else 13
- d_dp = 12 if onW else 14
-
- lLR = aXis.axisValues[lar_lts] / reduction
- lUD = aXis.axisValues[uad_lts] / reduction
- rLR = aXis.axisValues[lar_rts] / reduction
- rUD = aXis.axisValues[uad_rts] / reduction
- lTrig = aXis.axisValues[lt] / reduction
- rTrig = aXis.axisValues[rt] / reduction
- aBut = bUtt.getButtonStatus(a_but)
- bBut = bUtt.getButtonStatus(b_but)
- xBut = bUtt.getButtonStatus(x_but)
- yBut = bUtt.getButtonStatus(y_but)
- lBump = bUtt.getButtonStatus(l_bump)
- rBump = bUtt.getButtonStatus(r_bump)
- bkBut = bUtt.getButtonStatus(bk_but)
- stBut = bUtt.getButtonStatus(st_but)
- xbBut = bUtt.getButtonStatus(xb_but)
- ltsBut = bUtt.getButtonStatus(lts_pr)
- rtsBut = bUtt.getButtonStatus(rts_pr)
- ldPad = bUtt.getButtonStatus(l_dp)
- rdPad = bUtt.getButtonStatus(r_dp)
- udPad = bUtt.getButtonStatus(u_dp)
- ddPad = bUtt.getButtonStatus(d_dp)
- #print(lUD)
- axis_sens = .06
- #print(aBut)
- lasta = own["lasta"]
-
- if lUD > axis_sens: down = 1
- else: down = 0
- if lUD < -axis_sens:
- up = 1
- #print("up")
- else: up = 0
- #print(down, up)
- if lLR > axis_sens: right = 1
- else: right = 0
- if lLR < -axis_sens: left = 1
- else: left = 0
-
- fileName = "Settings.dat"
- scenes = bge.logic.getSceneList()
- #print(scenes)
- main_scene = [scene for scene in scenes if scene.name=="main"][0]
- main_empty = main_scene.objects['Empty']
-
- def main():
-
- cont = bge.logic.getCurrentController()
- own = cont.owner
- #down = cont.sensors["down"]
- #up = cont.sensors["up"]
- #bBut = cont.sensors["bBut"]
- #aBut = cont.sensors["aBut"]
- pstate = own["pstate"]
- scene = bge.logic.getCurrentScene()
- resume = scene.objects["resume"]
- settings = scene.objects["settings"]
- level = scene.objects["level"]
- levelselect = scene.objects["levelselect"]
- restart = scene.objects["restart"]
- exit = scene.objects["exit"]
- submenu_on = own["submenu_on"]
- level_text = scene.objects["level_text"]
- level_text.resolution = 8
- lastup = own["lastup"]
- lastdown = own["lastdown"]
- lastleft = own["lastleft"]
- lastright = own["lastright"]
- lastpstate = own["lastpstate"]
- playspeed = 2
- #sSelect = cont.actuators["sSelect"]
- cont.deactivate(own.actuators['restart'])
- #joy down
- if down == 1 and lastdown != 1:
- #own.stopAction(0)
- pstate = own["pstate"]
-
- if pstate == 0 and submenu_on == 0:
- resume.playAction("p_resume", 10,0, layer=1, priority=0, play_mode=0, speed=playspeed)
- if pstate == 1 and submenu_on == 0:
- settings.playAction("p_settings", 10,0, layer=1, priority=0, play_mode=0, speed=playspeed)
- if pstate == 2 and submenu_on == 0:
- level.playAction("p_level", 10,0, layer=1, priority=0, play_mode=0, speed=playspeed)
- #level.playAction("p_level_select", 10,0, layer=1, priority=0, play_mode=0, speed=playspeed)
- if pstate == 3 and submenu_on == 0:
- restart.playAction("p_restart", 10,0, layer=1, priority=0, play_mode=0, speed=playspeed)
- if pstate == 4 and submenu_on == 0:
- exit.playAction("p_exit", 10,0, layer=1, priority=0, play_mode=0, speed=playspeed)
-
- if pstate < 4 and submenu_on == 0:
- own["pstate"] = own["pstate"] + 1
- if pstate == 4 and submenu_on == 0:
- own["pstate"] = 0
- pstate = own["pstate"]
- #print(pstate)
- cont.activate(own.actuators['sSelect'])
- #joy up
- if up == 1 and lastup != 1:
- pstate = own["pstate"]
-
- if pstate == 0 and submenu_on == 0:
- resume.playAction("p_resume", 10,0, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 1 and submenu_on == 0:
- settings.playAction("p_settings", 10,0, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 2 and submenu_on == 0:
- level.playAction("p_level", 10,0, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 3 and submenu_on == 0:
- restart.playAction("p_restart", 10,0, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 4 and submenu_on == 0:
- exit.playAction("p_exit", 10,0, layer=0, priority=0, play_mode=0, speed=playspeed)
-
-
- if pstate > 0 and submenu_on == 0:
- own["pstate"] = own["pstate"] - 1
- if pstate == 0 and submenu_on == 0:
- own["pstate"] = 4
- pstate = own["pstate"]
- #print(pstate)
- cont.activate(own.actuators['sSelect'])
- if right == 1 and lastright !=1:
- cont.activate(own.actuators['sSelect'])
- if left == 1 and lastleft != 1:
- cont.activate(own.actuators['sSelect'])
-
- #level*****************************************************
-
- if own["submenu"] == "level":
- #print("submenu is level")
- active_level_select = own["active_level_select"]
-
- import Settings
- if left == 1 and lastleft != 1:
- if active_level_select >= 0:
- active_level_select -= 1
- if active_level_select < 0:
- active_level_select = 8
- #if active_level_select == -1:
- #active_level_select = 0
- #print(active_level_select)
- #move up
- #play up
- if right == 1 and lastright != 1:
- if active_level_select < 9:
- active_level_select += 1
- if active_level_select == 9:
- active_level_select = 0
- if active_level_select == -1:
- active_level_select = 0
- print(active_level_select)
- #move down
- #play down
- if active_level_select == 0:
- level_text.text = "Empty Lot"
- if active_level_select == 1:
- level_text.text = "Waterfall"
- if active_level_select == 2:
- level_text.text = "Warehouse"
- if active_level_select == 3:
- level_text.text = "City"
- if active_level_select == 4:
- level_text.text = "Training"
- if active_level_select == 5:
- level_text.text = "Spine"
- if active_level_select == 6:
- level_text.text = "Apricot Park"
- if active_level_select == 7:
- level_text.text = "Waiting Room"
- if active_level_select == 8:
- level_text.text = "8 (n/a)"
- own["active_level_select"] = active_level_select
- #indoor
- if aBut == False and active_level_select == 0 and lasta == 1:
- level_text.text = ""
- cont.activate(own.actuators['loading'])
- level = "lot"
- main_empty["level"] = "lot"
- own["level"] = level
- Settings.writeSettings()
- print("not")
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else:
-
- cont.deactivate(own.actuators['restart'])
- #woodbowl
- if aBut == False and active_level_select == 1 and lasta == 1:
- level_text.text = ""
- cont.activate(own.actuators['loading'])
- level = "mini_scene"
- main_empty["level"] = "mini_scene"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- #mini
- if aBut == False and active_level_select == 2 and lasta == 1:
- level_text.text = ""
- cont.activate(own.actuators['loading'])
- level = "warehouse"
- main_empty["level"] = "warehouse"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- #level3
- if aBut == False and active_level_select == 3 and lasta == 1:
- level_text.text = ""
- level = "level3"
- main_empty["level"] = "city2"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- #hubbas rail
- if aBut == False and active_level_select == 4 and lasta == 1:
- level_text.text = ""
- level = "train"
- main_empty["level"] = "train"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- #training
- if aBut == False and active_level_select == 5 and lasta == 1:
- level_text.text = ""
- level = "level3"
- main_empty["level"] = "spine"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- if aBut == False and active_level_select == 6 and lasta == 1:
- level_text.text = ""
- level = "gt"
- main_empty["level"] = "gt"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- if aBut == False and active_level_select == 7 and lasta == 1:
- level_text.text = ""
- level = "store"
- main_empty["level"] = "store"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- if aBut == False and active_level_select == 8 and lasta == 1:
- level_text.text = ""
- level = "level3"
- main_empty["level"] = "spine"
- own["level"] = level
- Settings.writeSettings()
- Settings.readSettings()
- cont.activate(own.actuators['restart'])
- #Settings.loadlevel()
- else: cont.deactivate(own.actuators['restart'])
- else:
- own["active_level_select"] = -1
- if bBut == True:
- levelselect.playAction("p_level_select", 10,0, layer=3, priority=0, play_mode=0, speed=playspeed)
- #**********************************************************
-
-
-
- if bBut == 1:
- cont.activate(own.actuators['sBack'])
- #cont.activate(own.actuators['exit'])
- print("bbut")
- #go to level submenu
- if aBut == True and pstate == 2:
- cont.activate(own.actuators['sEnter'])
- #cont.activate(own.actuators['quit'])
- #print("level")
- own["submenu_on"] = 1
- own["submenu"] = "level"
- level_text.text = "<choose>"
- levelselect.playAction("p_level_select", -10,10, layer=3, priority=0, play_mode=0, speed=playspeed)
- #exit submenu
- if bBut and submenu_on == 1:
- own["submenu_on"] = 0
- own["submenu"] = None
- level_text.text = ""
-
- #exit
- if aBut == 1 and pstate == 4:
- cont.activate(own.actuators['sEnter'])
- cont.activate(own.actuators['quit'])
- print("bbut")
-
- if pstate == 0 and submenu_on == 0 and lastpstate != 0:
- resume.playAction("p_resume", -10,10, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 1 and submenu_on == 0 and lastpstate != 1:
- settings.playAction("p_settings", -10,10, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 2 and submenu_on == 0 and lastpstate != 2:
- level.playAction("p_level", -10,10, layer=0, priority=0, play_mode=0, speed=playspeed)
- #level.playAction("p_level_select", -10,10, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 3 and submenu_on == 0 and lastpstate != 3:
- restart.playAction("p_restart", -10,10, layer=0, priority=0, play_mode=0, speed=playspeed)
- if pstate == 4 and submenu_on == 0 and lastpstate != 4:
- exit.playAction("p_exit", -10,10, layer=0, priority=0, play_mode=0, speed=playspeed)
-
-
- #find the scene and object
- scenes = bge.logic.getSceneList()
- for scene in scenes :
- #if scene.name == 'lot' or scene.name == 'train' or scene.name == 'mini_scene' or scene.name == 'city' or scene.name == 'city2' or scene.name == 'spine':
- #if scene.name == main_empty["level"]:
- if scene.name == 'lot':
- #print("*****stop sounds")
- cc = scene.objects['control_cube.002']
- cc.actuators["sroll"].volume = .0001
- #cc.deactivate(own.actuators["sroll"])
- cc.actuators["sroll"].stopSound()
-
-
-
- #print(pstate)
- own["lastup"] = up
- own["lastdown"] = down
- own["lastleft"] = left
- own["lastright"] = right
- own["lasta"] = aBut
- own["lastpstate"] = own["pstate"]
- main()
|