changeset 315:e935ed8dc5e6

Add out-of-screen item indicators.
author Thibaut Girka <thib@sitedethib.com>
date Fri, 23 Mar 2012 16:27:07 +0100
parents 0f88ae611d37
children f0be7ea62330
files pytouhou/game/item.py pytouhou/ui/gamerenderer.pyx
diffstat 2 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/item.py
+++ b/pytouhou/game/item.py
@@ -14,21 +14,42 @@
 
 
 from math import cos, sin, atan2, pi
+from copy import copy
 
 from pytouhou.utils.interpolator import Interpolator
 
 
+class Indicator(object):
+    def __init__(self, item):
+        self._item = item
+
+        self.sprite = copy(item._item_type.indicator_sprite)
+        self.removed = False
+
+        self.frame = 0
+        self.x = self._item.x
+        self.y = self.sprite.texcoords[2] / 2.
+
+
+    def update(self):
+        #TODO: alpha
+        self.x = self._item.x
+        self.frame += 1
+
+
+
 class Item(object):
     def __init__(self, start_pos, _type, item_type, game, angle=pi/2, player=None, end_pos=None):
         self._game = game
+        self._type = _type
         self._item_type = item_type
         self.sprite = item_type.sprite
         self.removed = False
-        self._type = _type
 
         self.frame = 0
         self.x, self.y = start_pos
         self.angle = angle
+        self.indicator = None
 
         if player:
             self.autocollect(player)
@@ -137,5 +158,14 @@ class Item(object):
             self.x += dx
             self.y += dy
 
+        offscreen = self.y < -(self.sprite.texcoords[2] / 2.)
+        if offscreen:
+            self.indicator = self.indicator or Indicator(self)
+        else:
+            self.indicator = None
+
+        if self.indicator:
+            self.indicator.update()
+
         self.frame += 1
 
--- a/pytouhou/ui/gamerenderer.pyx
+++ b/pytouhou/ui/gamerenderer.pyx
@@ -88,7 +88,9 @@ cdef class GameRenderer(Renderer):
                                        game.players,
                                        game.msg_sprites(),
                                        *(player.objects() for player in game.players)))
-            self.render_elements(chain(game.bullets, game.lasers, game.cancelled_bullets, game.items))
+            self.render_elements(chain(game.bullets, game.lasers,
+                                       game.cancelled_bullets, game.items,
+                                       (item.indicator for item in game.items if item.indicator)))
             #TODO: display item indicators
             glEnable(GL_FOG)