changeset 143:ea21bb37febe

Add max bullets limit
author Thibaut Girka <thib@sitedethib.com>
date Sun, 25 Sep 2011 21:00:43 +0200
parents c7f0fd9d2145
children cadfc5e5ad7a
files pytouhou/game/enemy.py pytouhou/game/game.py pytouhou/game/games.py
diffstat 3 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -108,11 +108,15 @@ class Enemy(object):
             launch_angle -= angle * (bullets_per_shot - 1) / 2.
 
         bullets = self._game_state.bullets
+        nb_bullets_max = self._game_state.nb_bullets_max
 
         for shot_nb in range(number_of_shots):
             shot_speed = speed if shot_nb == 0 else speed + (speed2 - speed) * float(shot_nb) / float(number_of_shots)
             bullet_angle = launch_angle
             for bullet_nb in range(bullets_per_shot):
+                if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
+                    break
+
                 if type_ == 75: # 102h.exe@0x4138cf
                     bullet_angle = self._game_state.prng.rand_double() * (launch_angle - angle) + angle
                 if type_ in (74, 75): # 102h.exe@0x4138cf
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -23,15 +23,16 @@ from pytouhou.game.enemy import Enemy
 
 class GameState(object):
     __slots__ = ('resource_loader', 'bullets', 'players', 'rank', 'difficulty', 'frame',
-                 'stage', 'boss', 'prng', 'bullet_types', 'characters')
+                 'stage', 'boss', 'prng', 'bullet_types', 'characters', 'nb_bullets_max')
     def __init__(self, resource_loader, players, stage, rank, difficulty,
-                 bullet_types, characters):
+                 bullet_types, characters, nb_bullets_max):
         self.resource_loader = resource_loader
 
         self.bullet_types = bullet_types
         self.characters = characters
 
         self.bullets = []
+        self.nb_bullets_max = nb_bullets_max
 
         self.stage = stage
         self.players = players
@@ -45,10 +46,10 @@ class GameState(object):
 
 class Game(object):
     def __init__(self, resource_loader, player_states, stage, rank, difficulty,
-                 bullet_types, characters):
+                 bullet_types, characters, nb_bullets_max=None):
         self.game_state = GameState(resource_loader, player_states, stage,
                                     rank, difficulty,
-                                    bullet_types, characters)
+                                    bullet_types, characters, nb_bullets_max)
 
         self.players = [Player(player_state, characters[player_state.character]) for player_state in player_states]
         self.enemies = []
--- a/pytouhou/game/games.py
+++ b/pytouhou/game/games.py
@@ -39,5 +39,5 @@ class EoSDGame(Game):
                       Character(player01, 5., 2.5, 2.5)]
 
         Game.__init__(self, resource_loader, players, stage, rank, difficulty,
-                      bullet_types, characters)
+                      bullet_types, characters, nb_bullets_max=640)