comparison pytouhou/game/game.py @ 150:4f46717390aa

Introduce items, implement ECL instruction 83
author Thibaut Girka <thib@sitedethib.com>
date Tue, 04 Oct 2011 23:09:41 +0200
parents ea21bb37febe
children 5cf927cbd9c5
comparison
equal deleted inserted replaced
149:3673d55a8448 150:4f46717390aa
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.player import Player
21 from pytouhou.game.enemy import Enemy 21 from pytouhou.game.enemy import Enemy
22 from pytouhou.game.item import Item
22 23
23 24
24 class GameState(object): 25 class GameState(object):
25 __slots__ = ('resource_loader', 'bullets', 'players', 'rank', 'difficulty', 'frame', 26 __slots__ = ('resource_loader', 'bullets', 'items', 'players', 'rank', 'difficulty', 'frame',
26 'stage', 'boss', 'prng', 'bullet_types', 'characters', 'nb_bullets_max') 27 'stage', 'boss', 'prng', 'bullet_types', 'item_types', 'characters', 'nb_bullets_max')
27 def __init__(self, resource_loader, players, stage, rank, difficulty, 28 def __init__(self, resource_loader, players, stage, rank, difficulty,
28 bullet_types, characters, nb_bullets_max): 29 bullet_types, item_types, characters, nb_bullets_max):
29 self.resource_loader = resource_loader 30 self.resource_loader = resource_loader
30 31
31 self.bullet_types = bullet_types 32 self.bullet_types = bullet_types
33 self.item_types = item_types
32 self.characters = characters 34 self.characters = characters
33 35
34 self.bullets = [] 36 self.bullets = []
37 self.items = []
35 self.nb_bullets_max = nb_bullets_max 38 self.nb_bullets_max = nb_bullets_max
36 39
37 self.stage = stage 40 self.stage = stage
38 self.players = players 41 self.players = players
39 self.rank = rank 42 self.rank = rank
41 self.boss = None 44 self.boss = None
42 self.prng = Random() 45 self.prng = Random()
43 self.frame = 0 46 self.frame = 0
44 47
45 48
49 def change_bullets_into_star_items(self):
50 player = self.players[0] #TODO
51 item_type = self.item_types[6]
52 self.items.extend(Item((bullet.x, bullet.y), item_type, 0.0, item_type.speed, player, self) for bullet in self.bullets)
53 self.bullets = []
54
55
46 56
47 class Game(object): 57 class Game(object):
48 def __init__(self, resource_loader, player_states, stage, rank, difficulty, 58 def __init__(self, resource_loader, player_states, stage, rank, difficulty,
49 bullet_types, characters, nb_bullets_max=None): 59 bullet_types, item_types, characters, nb_bullets_max=None):
50 self.game_state = GameState(resource_loader, player_states, stage, 60 self.game_state = GameState(resource_loader, player_states, stage,
51 rank, difficulty, 61 rank, difficulty,
52 bullet_types, characters, nb_bullets_max) 62 bullet_types, item_types, characters, nb_bullets_max)
53 63
54 self.players = [Player(player_state, characters[player_state.character]) for player_state in player_states] 64 self.players = [Player(player_state, characters[player_state.character]) for player_state in player_states]
55 self.enemies = [] 65 self.enemies = []
56 66
57 self.bonuses = [] 67 self.bonuses = []
92 enemy.update() 102 enemy.update()
93 103
94 for bullet in self.game_state.bullets: 104 for bullet in self.game_state.bullets:
95 bullet.update() 105 bullet.update()
96 106
107 for item in self.game_state.items:
108 item.update()
109
97 # 4. Check for collisions! 110 # 4. Check for collisions!
98 #TODO 111 #TODO
99 for player in self.players: 112 for player in self.players:
100 px, py = player.x, player.y 113 px, py = player.x, player.y
101 phalf_size = player.hitbox_half_size 114 phalf_size = player.hitbox_half_size
108 by1, by2 = by - half_size, by + half_size 121 by1, by2 = by - half_size, by + half_size
109 122
110 if not (bx2 < px1 or bx1 > px2 123 if not (bx2 < px1 or bx1 > px2
111 or by2 < py1 or by1 > py2): 124 or by2 < py1 or by1 > py2):
112 print('collided!') #TODO 125 print('collided!') #TODO
126
127 #TODO: enemy-player collision
128 #TODO: item-player collision
113 129
114 # 5. Cleaning 130 # 5. Cleaning
115 self.cleanup() 131 self.cleanup()
116 132
117 self.game_state.frame += 1 133 self.game_state.frame += 1