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('toLand') 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 # 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') #o['requestAction'] = 'fak_offboard' 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: #killact(3) #killact(4) #killact(5) #killact(6) #killact(7) #if STANCE == 0: o['requestAction'] ='reg_jump' #print('jump') #if STANCE == 1: #own['requestAction'] ='fak_jump' #print('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 #o.linearVelocity.x = linvel.x #o.linearVelocity.y = linvel.y #own['walk_jump_timer'] = 6 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 #====================================