Commits

Dominic Kexel committed b75eba1 Draft

leveling

Comments (0)

Files changed (4)

     self.time_to_go = 20
     self.spawn = True
   
+  def next_level(self):
+    self.level += 1
+    self.time_to_go = 10 + self.level * 10
+    self.spawn = True
+    
   def tick(self):
     if self.time_to_go >= 1:
       self.time_to_go -= 1
 
 class Shrapnel(Actor):
   
-  def __init__(self, **kwargs):
+  def __init__(self, mass=1, force=None, **kwargs):
     super(Shrapnel, self).__init__(**kwargs)
     self._color = rc()
     self._current = kwargs['start_pos']
-    mass = 1
     self.radius = kwargs['size']
     inertia = pymunk.moment_for_circle(mass, 0, self.radius)
     self.body = pymunk.Body(mass, inertia)
     shape = pymunk.Circle(self.body, self.radius)
     space.add(self.body, shape)
     self.shape = shape
-    self.body.apply_impulse((r(-200, 201), r(-75, 301)))
+    if force:
+      self.body.apply_force(force)
+    else:
+      self.body.apply_impulse((r(-200, 201), r(-75, 301)))
 
   def draw(self, screen):
     final_position = to_pygame(self.body.position)
     self._enemy_timeout = r(10, 300)
     self.paused = False
     HUD(scene=self)
-    
+  
   def _handle_key(self, event):
     if event.key == pygame.K_SPACE:
       self.paused = not self.paused
     
-  def enter(self):
-    if self._initialized: return
-    for inx, city in enumerate(self._state.cities):
-      self._cities[inx] = City(scene=self, inx=inx)
-    for inx, silo in enumerate(self._state.silos):
-      self._silos[inx] = Silo(scene=self, inx=inx)
-    self._initialized = True
+  def enter(self, **kwargs):
+    if 'backnav' in kwargs: 
+      for s in self._silos:
+        if not self._silos[s]._hit:
+          self._silos[s].rockets += 10
+    else:
+      if self._initialized: return
+      for inx, city in enumerate(self._state.cities):
+        self._cities[inx] = City(scene=self, inx=inx)
+      for inx, silo in enumerate(self._state.silos):
+        self._silos[inx] = Silo(scene=self, inx=inx)
+      self._initialized = True
 
   def _fire_rocket(self, event):
     if self.paused: return 
 import pygame
 
-from scene import Scene
+from scene import Scene, NavigateBackException
 from constants import *
 from sound import play_dark
 from resource import render_cached
     self._back_step = 0
     self._back_timer = 3
     self._added = False
-    
+    self._event_handler = {pygame.MOUSEBUTTONUP: self._next_level,
+                           pygame.KEYUP: self._next_level}
+
+  def _next_level(self, event):
+    if self._back_step < 20: return
+    self._state.next_level()
+    raise NavigateBackException()
+                           
   def enter(self, **kwargs):
+    self._back_step = 0
+    self._added = False
     self._state = kwargs['state']
     self._background = kwargs['copy']
     self._background_org = kwargs['copy']
     menu, battle, intermediate = Menu(self), Battle(self), Intermediate(self)
     self._scenes.register(menu)
     self._scenes.register(battle, menu)
-    self._scenes.register(intermediate)
+    self._scenes.register(intermediate, battle)
   
   def stop(self):
     self._running = False
     self._scenes.append([scene, parent])
   
   def navigate(self, key, **kwargs):
+    self._stack.append(self._current)
     self._current.leave()
     self._current = next(s for (s, p) in self._scenes if s.key == key)
     self._current.enter(**kwargs)
-
+    
   def _go_back(self):
     self._current.leave()
     self._current = self._stack.pop()
-    self._current.enter()
+    self._current.enter(backnav=True)
     
   def handle_event(self, event):
     try: