123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- 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
-
- #====================================
|