comparison pytouhou/game/game.py @ 130:11ab06f4c4c6

Introduce characters!
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Sep 2011 22:48:56 +0200
parents d1c82d43bbf3
children e9ac3640280b
comparison
equal deleted inserted replaced
129:284ac8f97a96 130:11ab06f4c4c6
15 15
16 from pytouhou.utils.random import Random 16 from pytouhou.utils.random import Random
17 17
18 from pytouhou.vm.eclrunner import ECLMainRunner 18 from pytouhou.vm.eclrunner import ECLMainRunner
19 19
20 from pytouhou.game.player import Player
20 from pytouhou.game.enemy import Enemy 21 from pytouhou.game.enemy import Enemy
21 22
22 23
23 class GameState(object): 24 class GameState(object):
24 __slots__ = ('resource_loader', 'bullets', 'players', 'rank', 'difficulty', 'frame', 25 __slots__ = ('resource_loader', 'bullets', 'players', 'rank', 'difficulty', 'frame',
25 'stage', 'boss', 'prng', 'bullet_types') 26 'stage', 'boss', 'prng', 'bullet_types', 'characters')
26 def __init__(self, resource_loader, players, stage, rank, difficulty, bullet_types): 27 def __init__(self, resource_loader, players, stage, rank, difficulty,
28 bullet_types, characters):
27 self.resource_loader = resource_loader 29 self.resource_loader = resource_loader
28 30
29 self.bullet_types = bullet_types 31 self.bullet_types = bullet_types
32 self.characters = characters
30 33
31 self.bullets = [] 34 self.bullets = []
32 35
33 self.stage = stage 36 self.stage = stage
34 self.players = players 37 self.players = players
39 self.frame = 0 42 self.frame = 0
40 43
41 44
42 45
43 class Game(object): 46 class Game(object):
44 def __init__(self, resource_loader, players, stage, rank, difficulty, bullet_types): 47 def __init__(self, resource_loader, player_states, stage, rank, difficulty,
45 self.game_state = GameState(resource_loader, players, stage, rank, difficulty, bullet_types) 48 bullet_types, characters):
49 self.game_state = GameState(resource_loader, player_states, stage,
50 rank, difficulty,
51 bullet_types, characters)
46 52
53 self.players = [Player(player_state, characters[player_state.character]) for player_state in player_states]
47 self.enemies = [] 54 self.enemies = []
48 55
49 self.bonuses = [] 56 self.bonuses = []
50 57
51 self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage, 58 self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage,
66 73
67 # 2. Filter out destroyed enemies 74 # 2. Filter out destroyed enemies
68 self.enemies = [enemy for enemy in self.enemies if not enemy._removed] 75 self.enemies = [enemy for enemy in self.enemies if not enemy._removed]
69 76
70 # 3. Let's play! 77 # 3. Let's play!
78 for player in self.players:
79 player.update(keystate) #TODO: differentiate keystates
80 if player.state.x < 8.:
81 player.state.x = 8.
82 if player.state.x > 384.-8: #TODO
83 player.state.x = 384.-8
84 if player.state.y < 16.:
85 player.state.y = 16.
86 if player.state.y > 448.-16: #TODO
87 player.state.y = 448.-16
88
71 for enemy in self.enemies: 89 for enemy in self.enemies:
72 enemy.update() 90 enemy.update()
73 91
74 for bullet in self.game_state.bullets: 92 for bullet in self.game_state.bullets:
75 bullet.update() 93 bullet.update()