comparison pytouhou/game/player.py @ 196:1e501e3b6645

Add a subclass for each character, and implement player attacks.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 29 Oct 2011 14:21:42 -0700
parents 9f58e2a6e950
children e1bc8c4cbb1a
comparison
equal deleted inserted replaced
195:52c0b9399413 196:1e501e3b6645
13 ## 13 ##
14 14
15 15
16 from pytouhou.game.sprite import Sprite 16 from pytouhou.game.sprite import Sprite
17 from pytouhou.vm.anmrunner import ANMRunner 17 from pytouhou.vm.anmrunner import ANMRunner
18 from pytouhou.game.bullettype import BulletType
19
20 from math import pi
18 21
19 22
20 SQ2 = 2. ** 0.5 / 2. 23 SQ2 = 2. ** 0.5 / 2.
21 24
22 25
38 self.invulnerable_time = 240 41 self.invulnerable_time = 240
39 self.touchable = True 42 self.touchable = True
40 43
41 44
42 class Player(object): 45 class Player(object):
43 def __init__(self, state, character, game): 46 def __init__(self, state, game, anm_wrapper, speed=4., hitbox_size=2.5, graze_hitbox_size=42.):
44 self._sprite = None 47 self._sprite = None
45 self._anmrunner = None 48 self._anmrunner = None
46 self._game = game 49 self._game = game
50 self.anm_wrapper = anm_wrapper
47 51
48 self.hitbox_half_size = character.hitbox_size / 2. 52 self.speed = speed
49 self.graze_hitbox_half_size = character.graze_hitbox_size / 2. 53 self.focused_speed = speed/2.
54
55 self.hitbox_size = hitbox_size
56 self.hitbox_half_size = self.hitbox_size / 2.
57 self.graze_hitbox_size = graze_hitbox_size
58 self.graze_hitbox_half_size = self.graze_hitbox_size / 2.
59
60 self.bullet_type = BulletType(anm_wrapper, 64, 96, 0, 0, 0, hitbox_size=4, damage=48)
61 self.bullet_launch_interval = 5
62 self.bullet_speed = 12.
63 self.bullet_launch_angle = -pi/2
64 self.fire_time = 0
50 65
51 self.state = state 66 self.state = state
52 self.character = character
53 self.anm_wrapper = character.anm_wrapper
54 self.direction = None 67 self.direction = None
55 68
56 self.set_anim(0) 69 self.set_anim(0)
57 70
58 self.death_time = 0 71 self.death_time = 0
96 32|64: (-SQ2, SQ2), 32|128: (SQ2, SQ2)}[keystate & (16|32|64|128)] 109 32|64: (-SQ2, SQ2), 32|128: (SQ2, SQ2)}[keystate & (16|32|64|128)]
97 except KeyError: 110 except KeyError:
98 speed = 0.0 111 speed = 0.0
99 dx, dy = 0.0, 0.0 112 dx, dy = 0.0, 0.0
100 else: 113 else:
101 speed = self.character.focused_speed if keystate & 4 else self.character.speed 114 speed = self.focused_speed if keystate & 4 else self.speed
102 dx, dy = dx * speed, dy * speed 115 dx, dy = dx * speed, dy * speed
103 116
104 if dx < 0 and self.direction != -1: 117 if dx < 0 and self.direction != -1:
105 self.set_anim(1) 118 self.set_anim(1)
106 self.direction = -1 119 self.direction = -1
122 self._sprite.color = (255, 255, 255) 135 self._sprite.color = (255, 255, 255)
123 self._sprite._changed = True 136 self._sprite._changed = True
124 elif m == 2: 137 elif m == 2:
125 self._sprite.color = (64, 64, 64) 138 self._sprite.color = (64, 64, 64)
126 self._sprite._changed = True 139 self._sprite._changed = True
140
141 if keystate & 1 and self.fire_time == 0:
142 self.fire_time = 30
143 if self.fire_time > 0:
144 self.fire()
145 self.fire_time -= 1
127 146
128 if self.death_time: 147 if self.death_time:
129 time = self._game.frame - self.death_time 148 time = self._game.frame - self.death_time
130 if time == 6: # too late, you are dead :( 149 if time == 6: # too late, you are dead :(
131 self.state.touchable = False 150 self.state.touchable = False