Shuvit game release repo.
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.

ai_manager.py 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. def printplaying(skater,deck):
  2. splaying_layers = "S: "
  3. playing_layers = "D: "
  4. tplaying_layers = "T: "
  5. for x in range(9999):
  6. if skater.isPlayingAction(x):
  7. #if trucks.isPlayingAction(x):
  8. #if skater.isPlayingAction(x):
  9. splaying_layers += str(x)
  10. splaying_layers += " "
  11. if deck.isPlayingAction(x):
  12. #if trucks.isPlayingAction(x):
  13. #if skater.isPlayingAction(x):
  14. playing_layers += str(x)
  15. playing_layers += " "
  16. print(splaying_layers, playing_layers)
  17. def main():
  18. frame_rate = 60 #Set this to the framerate of your game.
  19. optimization = 1 #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
  20. #recording_cutoff = 6974#7300 #3600 #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
  21. recorder_state = 1 #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
  22. allow_playback_break = True #Allow the player to resume playing from the position in the recording.
  23. from bge import logic
  24. import aiRecord
  25. import aiSortData
  26. import npcChangeAnim
  27. from mathutils import Vector
  28. import math
  29. cont = logic.getCurrentController()
  30. own = cont.owner
  31. scene = logic.getCurrentScene()
  32. dict = logic.globalDict
  33. own['valueIndex'] = own['valueIndex'] + 20
  34. #dict['recorder_on'] = recorder_on
  35. npc_index = own['npc_index']
  36. skater = dict['spawned_npcs'][npc_index]
  37. recorder_on = dict.get('recorder_on')
  38. own['recorder_on'] = recorder_on
  39. #print("recorder on: ", recorder_on)
  40. own["playback"] = True
  41. recording_cutoff = own['replay_length']
  42. idle_timer = own['idle_timer']
  43. npc_playback = own['npc_playback']
  44. if 'data_loaded' not in own:
  45. own['data_loaded'] = 1
  46. aiRecord.loadData(cont, own)
  47. if npc_playback == True:
  48. cube = own
  49. aiRecord.loadData(cont, own)
  50. #own['move'] = False
  51. #....................
  52. valueIndex = own['valueIndex']
  53. n = (valueIndex / recording_cutoff) * 1000
  54. n = int(round(n))
  55. #print(own['valueIndex'])
  56. if own['objIndex'] < (recording_cutoff-3):
  57. own['objIndex'] = own['objIndex'] + 2
  58. else:
  59. own['objIndex'] = 4
  60. print('replay end')
  61. # try:
  62. # tActu = cont.actuators['npcSteering']
  63. # cont.deactivate(tActu)
  64. #
  65. # except:
  66. # print('no target to delete')
  67. npcChangeAnim.main(cont)
  68. #own['npc_replay_name'] = '30secA.dat'
  69. own['inited'] = False
  70. own['rotate_in'] = True
  71. own['move_to'] = True
  72. own['rotate_out'] = True
  73. aiRecord.loadData(cont, own)
  74. else:
  75. if idle_timer < 5:
  76. idle_timer += 1
  77. #print('idling', idle_timer)
  78. else:
  79. idle_timer = 0
  80. own['npc_rotate'] = True
  81. # if own['npc_rotate'] == True:
  82. # xyz = own.localOrientation.to_euler()
  83. # rotz = math.degrees(xyz[2])
  84. # print (rotz, own['rpStartZ'], '---rotations')
  85. # num = rotz - own['rpStartZ']
  86. # amt = .05
  87. # amt2 = 2
  88. # if abs(num) < amt2:
  89. # own['npc_playback'] = True
  90. # own['npc_rotate'] = False
  91. # print('----starting replay', num)
  92. # elif rotz > own['rpStartZ']:
  93. # own.applyRotation([0,0,-amt], True)
  94. # elif rotz < own['rpStartZ']:
  95. # own.applyRotation([0,0,amt], True)
  96. if own['move'] == True:
  97. speed = .15
  98. target = own['rpStartLoc']
  99. my_vector = Vector([target[0], target[1], target[2]])
  100. length = (own.worldPosition - my_vector).length
  101. obj = own['target_object_name']
  102. vect = own.getVectTo(obj)
  103. if length < .1:
  104. own['move'] = False
  105. obj = own['target_object_name']
  106. own['idle_timer'] = idle_timer
  107. try:
  108. obj = own['target_object_name']
  109. #print(obj.worldPosition)
  110. except:
  111. pass
  112. #11111111
  113. if own['rotate_in'] == False and own['move_to'] == False and own['rotate_out'] == False:
  114. own['npc_playback'] = True
  115. #obj = own['target_object_name']
  116. #obj.endObject()
  117. #print('ending target')
  118. if own['rotate_in'] == True:
  119. tActu = cont.actuators['npcTracking']
  120. tActu.object = own['target_object_name']
  121. try:
  122. own['rotate_in_timer'] = own['rotate_in_timer'] + 1
  123. except:
  124. own['rotate_in_timer'] = 0
  125. if own['rotate_in_timer'] < 120:
  126. cont.activate(tActu)
  127. skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
  128. else:
  129. cont.deactivate(tActu)
  130. own['rotate_in'] = False
  131. own['rotate_in_timer'] = 0
  132. skater.stopAction(2)
  133. elif own['move_to'] == True:
  134. target = own['rpStartLoc']
  135. #print(target, 'target', own.worldPosition, '++++++')
  136. my_vector = Vector([target[0], target[1], target[2]])
  137. length = (own.worldPosition - my_vector).length
  138. sActu = cont.actuators['npcSteering']
  139. sActu.target = own['target_object_name']
  140. #length = round(length, 7)
  141. if length > .1:
  142. #print(length, 'length < .1')
  143. #pass
  144. cont.activate(sActu)
  145. skater.playAction('reg_nwalk', 0,35, layer=2, play_mode=1, speed=.5)
  146. else:
  147. cont.deactivate(sActu)
  148. own['move_to'] = False
  149. print(length, 'length met')
  150. skater.stopAction(2)
  151. elif own['rotate_out'] == True:
  152. #own['rpStartZ'] = 180
  153. #print(own['rpStartZ'], 'start')
  154. xyz = own.localOrientation.to_euler()
  155. #print(xyz[2], 'non euler')
  156. rotz = math.degrees(xyz[2])
  157. xyz[2] = xyz[2] + 1.57
  158. rotz_b = rotz + 180
  159. if rotz_b > 360:
  160. rotz_b -= 360
  161. srotz_b = own['rpStartZ'] + 180
  162. if srotz_b > 360:
  163. srotz_b -= 360
  164. #print (rotz_b, srotz_b, '---rotations')
  165. #print (rotz, own['rpStartZ'], '---rotations')
  166. num = rotz - (own['rpStartZ'])
  167. amt = .03
  168. amt2 = 1
  169. local = own.worldOrientation.inverted() * ( own['target_object_name'].worldPosition - own.worldPosition)
  170. if local.x >0:
  171. #target is in front
  172. #print('in front')
  173. pass
  174. else:
  175. #target is behind
  176. #print('behind')
  177. pass
  178. if local.y > 0:
  179. #object on right
  180. #print('on right')
  181. rot = 'right'
  182. else:
  183. #object is on left
  184. #print('on left')
  185. rot = 'left'
  186. skater.playAction('reg_idle1', 0,120, layer=2, play_mode=1, speed=.5)
  187. if abs(num) < amt2:
  188. own['npc_playback'] = True
  189. own['npc_rotate'] = False
  190. print('----starting replay', num)
  191. own['rotate_out'] = False
  192. obj = own['target_object_name']
  193. obj.endObject()
  194. print('ending target')
  195. skater.stopAction(2)
  196. #elif rotz > own['rpStartZ']:
  197. elif rot == 'right':
  198. own.applyRotation([0,0,amt], True)
  199. own.worldPosition = own['rpStartLoc']
  200. #elif rotz < own['rpStartZ']:
  201. elif rot == 'left':
  202. own.applyRotation([0,0,-amt], True)
  203. own.worldPosition = own['rpStartLoc']
  204. #print(own['rotate_in'], own['move_to'], own['rotate_out'])
  205. main()