Bullets now hit things.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 21:54:27 +0000 (23:54 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 21:54:27 +0000 (23:54 +0200)
koperkapel/gamelib/enemy_roach.py
koperkapel/scenes/level.py

index 2e51ef09df745f31f649c9fc5f4483fe91eea5ab..90695b3916f99e2594fd8e1833a251046b9404fa 100644 (file)
@@ -10,7 +10,7 @@ from ..roaches import t32_roaches, WorldRoach
 
 def get_enemy_roach(level):
     roach = t32_roaches.assemble(WorldRoach(), color=(255, 0, 0, 255))
-    roach.anchor = (0, 0)
+    roach.anchor = (-16, -16)  # this should center them on the tile
     roach.game_pos = (0, 0)
     roach.health = 5
     roach.level = level
index b17beb61231f1e2d817fe411d529e8e52eb535bc..73573ac61f79204d4e758c227a2d7b2ab7d592d5 100644 (file)
@@ -204,6 +204,13 @@ class GameLevelScene(BaseLevelScene):
         bullet.level_layer = self._level_layer
         self._bullets.add(bullet)
 
+    def _check_for_bullet_hits(self):
+        for bullet in list(self._bullets):
+            for enemy in list(self._enemies):
+                if enemy.collidepoint(bullet.pos):
+                    self._hit_enemy(enemy, bullet.weapon)
+                    self._bullets.remove(bullet)
+
     def _update_bullet(self, bullet, dt):
         bullet.dt += dt
         if bullet.dt > 0.1:
@@ -253,6 +260,7 @@ class GameLevelScene(BaseLevelScene):
             bullet.pos = self.calc_offset(
                 bullet.game_pos[0] * TILE_SIZE + (TILE_SIZE // 2),
                 bullet.game_pos[1] * TILE_SIZE + (TILE_SIZE // 2))
+        self._check_for_bullet_hits()
         more = self._check_held_keys(dt)
         if more:
             events.extend(more)