Commits

Dominic Kexel committed 9729bc2 Draft

custom cursor

  • Participants
  • Parent commits f5186d4

Comments (0)

Files changed (2)

 +####       +####
 +#######  +######
 +################
+""",
+'cursor':
+"""
+  =+ +=  
+   + +   
+=  + +  =
++++   +++
+    Y    
++++   +++
+=  + +  =
+   + +   
+  =+ +=  
 """}
 
 def get_art(key):
     if c == '#': return GREYGREEN
     if c == '+': return MALLARD
     if c == ' ': return COLORLESS
+    if c == '=': return BLACK
+    if c == 'Y': return YELLOW
     
     if not (tick / 60) % 2:
       if c == 'G': return GREEN
            speed=25,
            scene=self.scene)
 
+class Cursor(Actor):
+  
+  def __init__(self, **kwargs):
+    super(Cursor, self).__init__(**kwargs)
+    self._img = build_surface(0, get_art('cursor'))
+    self._pos = pygame.mouse.get_pos()
+    pygame.mouse.set_visible(False)
+    self._die_callback = lambda: pygame.mouse.set_visible(True)
+  
+
+  def draw(self, screen):
+    screen.blit(self._img, self._pos)
+
+  def update(self):
+    self._pos = sub(pygame.mouse.get_pos(), (self._img.get_width()/2, self._img.get_width()/2))
+
 class Battle(Scene):
   
   key = 'battle'
     self._enemy_timeout = r(10, 300)
     self.paused = False
     HUD(scene=self)
+    self._cursor = None
   
   def _handle_key(self, event):
     if event.key == pygame.K_SPACE:
       self.paused = not self.paused
+  
+  def leave(self):
+    self._cursor.die()
+  
+  def enter(self, **kwargs):
     
-  def enter(self, **kwargs):
+    self._cursor = Cursor(scene=self)
+    
     if 'backnav' in kwargs: 
       for s in self._silos:
         if not self._silos[s].is_hit:
                  speed=5,
                  vector=normalize(sub(target.to_hit_pos, pos)), 
                  scene=self)
+
   @property
   def _level_completed(self):
     return not self._state.spawn and not any(isinstance(a, Rocket) for a in self._actors)