123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- import bge
- dict = bge.logic.globalDict
- #====================================
-
- State = type("State", (object,), {})
- #====================================
- class State(object):
- def __init__(self, FSM):
- self.FSM = FSM
- self.timer = 0
- self.startTime = 0
- def Enter(self):
- self.timer = 0
- self.startTime = 0
- def Execute(self):
- print('Executing')
- def Exit(self):
- print('Exiting')
-
- #====================================
-
- class Example(State):
- def __init__(self,FSM):
- super(Example, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(Example, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toExample')
-
- def Exit(self):
- pass
-
- #====================================
-
- class Startup(State):
- def __init__(self,FSM):
- super(Startup, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(Startup, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
-
- if self.FSM.stateLife == 5:
- #Startup.main(self.FSM.owner['cont'])
-
- self.FSM.ToTransition('toWalk')
- print('player FSM')
-
- def Exit(self):
- pass
-
- #====================================
-
- class Walk(State):
- def __init__(self,FSM):
- super(Walk, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
-
- o = self.FSM.owner.obj
- c = self.FSM.owner
- if c.arm == None:
- print(o.childrenRecursive)
- c.arm = o.childrenRecursive['Char4']
-
- self.walk_weight = 1
- self.run_weight = 1
- self.run_speed = 1.0
- self.turn_weight = 0
-
- super(Walk, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- o = self.FSM.owner.obj
- c = self.FSM.owner
- #print('walking')
- if self.FSM.stateLife == 2:
- if o['stance']:
- o.applyRotation([0,0,3], True)
- o['stance'] = False
- o['requestAction'] = 'fak_offboard'
- print('request fak offboard')
- else:
- o['requestAction'] = 'reg_offboard'
- print('request reg offboard')
- if self.FSM.stateLife > 5:
- o['requestAction'] = 'reg_idle'
-
- self.check_onboard()
- self.check_jump()
- self.check_exit()
- ray = c.get_ground_ray()
- moving = c.walk_movement()
-
- self.idle_blend()
- self.get_walk_weight()
-
-
-
-
- #self.FSM.ToTransition('toLand')
- def check_onboard(self):
- if dict['walk'] == 0:
- self.FSM.ToTransition('toRoll')
- if dict['yBut'] == 1 and dict['last_yBut'] == 0:
- print('do the onboard')
-
- def check_jump(self):
- o = self.FSM.owner.obj
- #limit fall speed
- if o.linearVelocity.z < -10:
- o.linearVelocity.z = -10
- if dict['xBut'] == True or dict['kb_space'] == 1:
- if dict['last_xBut'] == 0:
- o['requestAction'] ='reg_jump'
- JUMPHEIGHT = 1100
- force = [ 0.0, 0.0, JUMPHEIGHT]
- # use local axis
- local = False
- # apply force -- limit jump speed
- if o.linearVelocity.z < 10:
- o.applyForce(force, local)
- o.linearVelocity.z += 5
-
- def check_exit(self):
- pass
- #own['walk'] == 1
-
-
-
-
- def idle_blend(self):
- arm = self.FSM.owner.arm
- arm.playAction('reg_idle1', 1,120, layer=6, play_mode=1, speed=1, blendin=10)
- if self.FSM.stateLife > 20:
- frame = arm.getActionFrame(7) + .5 * self.run_speed
- if frame > 30:
- frame = 0
- arm.stopAction(7)
- arm.playAction('reg_nwalk2', 0,30, layer=7, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=self.walk_weight)
- arm.setActionFrame(frame, 7)
- #print(self.walk_weight, frame)
-
-
-
- frame = arm.getActionFrame(8) + .5 * self.run_speed
- if frame > 30:
- frame = 0
- arm.stopAction(8)
- arm.playAction('reg_run.002', 0,30, layer=8, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=self.run_weight)
- arm.setActionFrame(frame, 8)
- #print(frame, 'frame')
- #print(self.run_weight, frame)
-
- # if self.turn_weight > 0:
- # tw = abs(self.turn_weight - 1)
- # #tw = self.turn_weight
- # arm.stopAction(4)
- # arm.playAction('bwalk_right', 1,60, layer=4, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=tw)
- # elif self.turn_weight < 0:
- # tw = abs(abs(self.turn_weight) - 1)
- # #tw = self.turn_weight
- # arm.stopAction(4)
- # arm.playAction('bwalk_left', 1,60, layer=4, play_mode=1, speed=self.run_speed, blendin=0, layer_weight=tw)
-
-
- def get_walk_weight(self):
- #print(self.FSM.owner.linearVelocity.y)
-
-
- o = self.FSM.owner.obj
- w = abs(o.linearVelocity.x)
- #wt = 3.5
- #yt = 8
- wt = 1.1
- yt = 3
- out2 = 0
- if w < wt:
- out = w / wt
- else:
- out = 1
- #print('running', w)
- out2 = w / yt
- out = abs(1 - out)
- out2 = abs(1 - out2)
- tgww = round(out, 3)
- tgrw = round(out2, 3)
- incer = .05
- if self.walk_weight < tgww:
- self.walk_weight += incer
- if self.walk_weight > tgww:
- self.walk_weight -= incer
- if self.run_weight <= tgrw:
- self.run_weight += incer
- if self.run_weight > tgrw:
- self.run_weight -= incer
- if self.walk_weight <= 0:
- self.walk_weight = 0
- if self.walk_weight > .95:
- self.walk_weight = 1
- if self.run_weight <= 0:
- self.run_weight = 0
- if self.run_weight > .95:
- self.run_weight = 1
-
-
- if dict['kb_lsh'] == 2 or dict['aBut'] == 1:
- self.run_speed = 1.3
- else:
- self.run_speed = .8
- print(self.run_speed, '---', self.walk_weight, 'walk weight', self.run_weight, 'run weight')
-
- def Exit(self):
- pass
-
-
- #====================================
-
- class WalkAir(State):
- def __init__(self,FSM):
- super(WalkAir, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(WalkAir, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
-
- class WalkJump(State):
- def __init__(self,FSM):
- super(WalkJump, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(WalkJump, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
-
- class WalkLand(State):
- def __init__(self,FSM):
- super(WalkLand, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(WalkLand, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
-
- class WalkHang(State):
- def __init__(self,FSM):
- super(WalkHang, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(WalkHang, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
-
- class WalkClimb(State):
- def __init__(self,FSM):
- super(WalkClimb, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(WalkClimb, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
-
- class WalkHurdle(State):
- def __init__(self,FSM):
- super(WalkHurdle, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(WalkHurdle, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
-
- #====================================
-
- class Roll(State):
- def __init__(self,FSM):
- super(Roll, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(Roll, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- if dict['walk'] == 1:
- self.FSM.ToTransition('toWalk')
- print('rolling')
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
|