Commits

Dominic Kexel  committed f5186d4 Draft

rockets can split up

  • Participants
  • Parent commits caa654d

Comments (0)

Files changed (1)

 from art import get_art, build_surface
 from actor import Actor
 
+r = random.randint
+rc = lambda: random.choice(GREENS)
+
 class GameState(object):
   
   def __init__(self):
 
 class Rocket(Actor):
   
-  def __init__(self, speed=1, target=None, **kwargs):
+  def __init__(self, speed=1, target=None, can_split=200, **kwargs):
     super(Rocket, self).__init__(**kwargs)
     self._start = kwargs['start_pos']
     self._current = kwargs['start_pos']
-    self._vector = mul_scalar(kwargs['vector'], speed*0.5)
+    self._vector = mul_scalar(kwargs['vector'], speed*0.4)
     self._target = magnitude(sub(target, self._start)) if target else None
     self._moving = True
     self.z = -1
+    self._splits = r(0, 1000) <= can_split
 
   def update(self):
     if not self._moving: return
     c = map(int, self._current)
     explode = False
 
+    if not self._target and self._splits and magnitude(sub(self._current, self._start)) > r(80, 100):
+      target = self.scene._get_random_rocket_target()
+      Rocket(start_pos=c, 
+             speed=5,
+             vector=normalize(sub(target.to_hit_pos, c)), 
+             scene=self.scene)
+      self._splits = False
+
     if self._target and magnitude(sub(self._current, self._start)) > self._target:
         explode = True
     if self._current[1] >= SCREEN_HEIGHT:
     for p in starmap(lambda a,b: [x+a, y+b], product((-1, 0, 1), (-1, 0, 1))):
       screen.set_at(p, RED)
 
-r = random.randint
-rc = lambda: random.choice(GREENS)
-
 class Shrapnel(Actor):
   
   def __init__(self, mass=1, force=None, **kwargs):
     silo = self._silos[n]
     silo.fire()
   
+  def _get_random_rocket_target(self):
+    return random.choice(list(self._cities.values()) + list(self._silos.values()))
+  
   def _check_spawn_missile(self):
     if not self._state.spawn: return
     self._enemy_timeout -= 1