changeset 164:5271789c067d

Implement player bullets rendering and updating.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 16 Oct 2011 08:01:28 -0700
parents ee0bbde02c48
children c8c60291c56f
files pytouhou/game/bullettype.py pytouhou/game/game.py pytouhou/opengl/gamerenderer.pyx
diffstat 3 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/bullettype.py
+++ b/pytouhou/game/bullettype.py
@@ -3,7 +3,8 @@ class BulletType(object):
                  launch_anim2_index, launch_anim4_index, launch_anim8_index,
                  hitbox_size,
                  launch_anim_penalties=(0.5, 0.4, 1./3.),
-                 launch_anim_offsets=(0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 0)):
+                 launch_anim_offsets=(0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 0),
+                 damage=0):
         self.anm_wrapper = anm_wrapper
         self.anim_index = anim_index
         self.cancel_anim_index = cancel_anim_index
@@ -13,4 +14,5 @@ class BulletType(object):
         self.hitbox_size = hitbox_size
         self.launch_anim_penalties = launch_anim_penalties
         self.launch_anim_offsets = launch_anim_offsets
+        self.damage = damage
 
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -37,6 +37,7 @@ class Game(object):
         self.enemies = []
         self.bullets = []
         self.cancelled_bullets = []
+        self.players_bullets = []
         self.items = []
 
         self.stage = stage
@@ -104,6 +105,9 @@ class Game(object):
         for bullet in self.cancelled_bullets:
             bullet.update()
 
+        for bullet in self.players_bullets:
+            bullet.update()
+
         for item in self.items:
             item.update()
 
@@ -147,6 +151,23 @@ class Game(object):
                         or by2 < py1 or by1 > py2):
                     player.collect(item)
 
+        for enemy in self.enemies:
+            ex, ey = enemy.x, enemy.y
+            ehalf_size_x, ehalf_size_y = enemy.hitbox_half_size
+            ex1, ex2 = ex - ehalf_size_x, ex + ehalf_size_x
+            ey1, ey2 = ey - ehalf_size_y, ey + ehalf_size_y
+
+            for bullet in self.players_bullets:
+                half_size = bullet.hitbox_half_size
+                bx, by = bullet.x, bullet.y
+                bx1, bx2 = bx - half_size, bx + half_size
+                by1, by2 = by - half_size, by + half_size
+
+                if not (bx2 < ex1 or bx1 > ex2
+                        or by2 < ey1 or by1 > ey2):
+                    bullet.collide()
+                    enemy.life -= bullet._bullet_type.damage
+
         # 5. Cleaning
         self.cleanup()
 
@@ -167,6 +188,7 @@ class Game(object):
         # TODO: was_visible thing
         self.bullets = [bullet for bullet in self.bullets if bullet.is_visible(384, 448)]
         self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if bullet.is_visible(384, 448)]
+        self.players_bullets = [bullet for bullet in self.players_bullets if bullet.is_visible(384, 448)]
 
         # Disable boss mode if it is dead/it has timeout
         if self.boss and self.boss._removed:
--- a/pytouhou/opengl/gamerenderer.pyx
+++ b/pytouhou/opengl/gamerenderer.pyx
@@ -153,6 +153,7 @@ cdef class GameRenderer:
             self.render_elements(game.players)
             self.render_elements(game.bullets)
             self.render_elements(game.cancelled_bullets)
+            self.render_elements(game.players_bullets)
             self.render_elements(game.items)
             #TODO: display item indicators
             glEnable(GL_FOG)