Mercurial > touhou
comparison pytouhou/game/game.py @ 142:c7f0fd9d2145
Simple collision detection
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 25 Sep 2011 20:56:14 +0200 |
parents | e9ac3640280b |
children | ea21bb37febe |
comparison
equal
deleted
inserted
replaced
141:982b21222602 | 142:c7f0fd9d2145 |
---|---|
73 | 73 |
74 # 2. Filter out destroyed enemies | 74 # 2. Filter out destroyed enemies |
75 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] |
76 | 76 |
77 # 3. Let's play! | 77 # 3. Let's play! |
78 #TODO: check update orders | |
78 for player in self.players: | 79 for player in self.players: |
79 player.update(keystate) #TODO: differentiate keystates | 80 player.update(keystate) #TODO: differentiate keystates (multiplayer mode) |
80 if player.state.x < 8.: | 81 if player.state.x < 8.: |
81 player.state.x = 8. | 82 player.state.x = 8. |
82 if player.state.x > 384.-8: #TODO | 83 if player.state.x > 384.-8: #TODO |
83 player.state.x = 384.-8 | 84 player.state.x = 384.-8 |
84 if player.state.y < 16.: | 85 if player.state.y < 16.: |
90 enemy.update() | 91 enemy.update() |
91 | 92 |
92 for bullet in self.game_state.bullets: | 93 for bullet in self.game_state.bullets: |
93 bullet.update() | 94 bullet.update() |
94 | 95 |
95 # 4. Cleaning | 96 # 4. Check for collisions! |
97 #TODO | |
98 for player in self.players: | |
99 px, py = player.x, player.y | |
100 phalf_size = player.hitbox_half_size | |
101 px1, px2 = px - phalf_size, px + phalf_size | |
102 py1, py2 = py - phalf_size, py + phalf_size | |
103 for bullet in self.game_state.bullets: | |
104 half_size = bullet.hitbox_half_size | |
105 bx, by = bullet.x, bullet.y | |
106 bx1, bx2 = bx - half_size, bx + half_size | |
107 by1, by2 = by - half_size, by + half_size | |
108 | |
109 if not (bx2 < px1 or bx1 > px2 | |
110 or by2 < py1 or by1 > py2): | |
111 print('collided!') #TODO | |
112 | |
113 # 5. Cleaning | |
96 self.cleanup() | 114 self.cleanup() |
97 | 115 |
98 self.game_state.frame += 1 | 116 self.game_state.frame += 1 |
99 | 117 |
100 | 118 |