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 == 2: #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 super(Walk, self).Enter() def Execute(self): self.FSM.stateLife += 1 o = self.FSM.owner #print('walking') if self.FSM.stateLife == 2: if self.FSM.owner['stance']: self.FSM.owner.applyRotation([0,0,3], True) self.FSM.owner['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.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 #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 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(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 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 #====================================