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.

birds.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import bge
  2. import random
  3. def bird(cont):
  4. own = cont.owner
  5. if 'inited' not in own:
  6. own.worldPosition = own['start'].worldPosition
  7. own['inited'] = True
  8. act = cont.actuators['Steering']
  9. act.target = own['end']
  10. act.velocity = 2
  11. cont.activate(act)
  12. #print('doing bird')
  13. if own.getDistanceTo(own['end']) < 1:
  14. own.endObject()
  15. #print('kill bird')
  16. def main(cont, scene):
  17. def build_bird_list(scene,own):
  18. own['bird_list'] = []
  19. for x in scene.objects:
  20. if 'bird_target' in x.name:
  21. own['bird_list'].append(x)
  22. def do_birds(scene, own, cont):
  23. if own['life'] % 50 == 0:
  24. num = random.randint(0,2)
  25. if num == 1:
  26. #print('add bird')
  27. top = len(own['bird_list']) - 1
  28. start = random.randint(0, top)
  29. end = start
  30. while end == start:
  31. end = random.randint(0, top)
  32. obj = scene.addObject('bird_cont', own['bird_list'][start], 0)
  33. obj['start'] = own['bird_list'][start]
  34. obj['end'] = own['bird_list'][end]
  35. obj.worldPosition = obj['start'].worldPosition
  36. #print(obj['start'], obj['end'])
  37. def life(own):
  38. if 'life' in own:
  39. own['life'] += 1
  40. else:
  41. own['life'] = 0
  42. own = cont.owner
  43. if 'binited' not in own:
  44. build_bird_list(scene, own)
  45. own['binited'] = True
  46. life(own)
  47. do_birds(scene, own, cont)
  48. #print('birding')