Commits

Dominic Kexel  committed 1f99a3d Draft

let silos handle firing of rockets

  • Participants
  • Parent commits ff338bd

Comments (0)

Files changed (1)

     self.scene = kwargs['scene']
     self._on_die = on_die
     self.z = 0
-    self.spawn(self)
+    self.scene.create(self)
     
   def die(self):
     self.scene.destroy(self)
     if self._on_die: self._on_die()
 
-  def spawn(self, obj):
-    self.scene.create(self)
-
   def update(self):
     pass
     
     super(Silo, self).__init__(**kwargs)
     self._inx = kwargs['inx']
     self.hit = False
+    self.rockets = 10
   
   @property
   def inx(self):
       
   def draw(self, screen):
     cpos = self._get_silo_pos(self._inx)
-    v = [e*25 for e in self._get_firing_vetor(self._inx)]
-    pygame.draw.line(screen, MALLARD, cpos, add(cpos, v), 2)
+    if self.rockets:
+      v = [e*22 for e in self._get_firing_vetor(self._inx)]
+      pygame.draw.line(screen, RED, cpos, add(cpos, v), 2)
     r = 20
     pygame.draw.circle(screen, HIGHLAND, cpos, r, 0)
 
+  def fire(self):
+    if not self.rockets: return
+    self.rockets -= 1
+
+    v = [e*25 for e in self.firing_vetor]
+    Rocket(start_pos=self.pos, 
+           target=pygame.mouse.get_pos(), 
+           vector=v, 
+           scene=self.scene)
+
 class Battle(Scene):
   
   key = 'battle'
   def _fire_rocket(self, event):
     n = event.button -1
     if n not in (0, 1, 2): return
-    if not self._state.silos[n]: return
-    self._state.silos[n] -= 1
     silo = self._silos[n]
-    start_pos = silo.pos
-    v = [e*25 for e in silo.firing_vetor]
-    Rocket(start_pos=start_pos, 
-           target=pygame.mouse.get_pos(), 
-           vector=v, 
-           scene=self)
+    silo.fire()
   
   def update_state(self):
     super(Battle, self).update_state()