Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

player.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import bge
  2. import FSM
  3. from mathutils import Vector
  4. dict = bge.logic.globalDict
  5. class Player:
  6. def __init__(self, cont):
  7. self.cont = cont
  8. self.obj = cont.owner
  9. self.FSM = FSM.PlayerFSM(self)
  10. self.walking = True
  11. #print(self.obj.childrenRecursive)
  12. #self.arm = self.obj.childrenRecursive['Char4']
  13. self.arm = None
  14. def update(self):
  15. self.FSM.Execute()
  16. def get_ground_ray(self):
  17. axis = 2
  18. distance = -2
  19. start = self.obj.worldPosition
  20. end = Vector.copy(self.obj.worldPosition + (self.obj.worldOrientation.col[axis] * distance))
  21. ray = self.obj.rayCast(end, start, 0, 'ground', 1, 0, 0)
  22. #print(ray)
  23. return ray
  24. def get_ground_dist(self, groundray):
  25. pass
  26. def walk_movement(self):
  27. moving = False
  28. o = self.obj
  29. if dict['kb_w'] == 2 or dict['lUD'] < -.05:
  30. #walk_blend(self)
  31. if o.linearVelocity.x < dict['max_walk_vel']:
  32. o.applyForce([-dict['walk_force'], 0, 0], True)
  33. if (dict['kb_lsh'] == 2 or dict['aBut'] == 1) and o.linearVelocity.y < dict['max_run_vel']:
  34. #self.run_speed = 1.5
  35. o.applyForce([-dict['run_force'], 0, 0], True)
  36. if dict['kb_s'] == 2 or dict['lUD'] > .06:
  37. o.applyForce([10, 0, 0], True)
  38. #print('w')
  39. if dict['kb_a'] == 2 or dict['lLR'] < -.03:
  40. o.applyRotation([0, 0, dict['walk_turn_amt']], True)
  41. #print('w')
  42. if dict['kb_d'] == 2 or dict['lLR'] > .03:
  43. o.applyRotation([0, 0, -dict['walk_turn_amt']], True)
  44. o.linearVelocity.y *= .9
  45. o.linearVelocity.x *= .95
  46. return moving
  47. def update(cont):
  48. #print('-------------player updating----------------')
  49. dict = bge.logic.globalDict
  50. #own = cont.owner
  51. if 'player_class' not in dict:
  52. #dict['playerFSM'] = FSM.PlayerFSM(own)
  53. dict['player_class'] = Player(cont)
  54. #dict['playerFSM'].Execute()
  55. dict['player_class'].update()