annotate pytouhou/game/player.py @ 199:8ec34c56fed0

Implement orbs.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 31 Oct 2011 09:38:57 -0700
parents 13918723d1bc
children eca53abdfeab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
14
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
15
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
16 from pytouhou.game.sprite import Sprite
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
17 from pytouhou.vm.anmrunner import ANMRunner
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
18 from pytouhou.game.bullettype import BulletType
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
19 from pytouhou.utils.interpolator import Interpolator
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
20
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
21 from math import pi
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
22
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
23
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
24 SQ2 = 2. ** 0.5 / 2.
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
25
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
26
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
27 class PlayerState(object):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
28 def __init__(self, character=0, score=0, power=0, lives=0, bombs=0):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
29 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/...
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
30
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
31 self.score = score
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
32 self.lives = lives
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
33 self.bombs = bombs
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
34 self.power = power
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
35
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
36 self.graze = 0
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
37 self.points = 0
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
38
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39 self.x = 192.0
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40 self.y = 384.0
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
41
191
d2b58a26c908 Set the correct invulnerability time.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 190
diff changeset
42 self.invulnerable_time = 240
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
43 self.touchable = True
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
44 self.focused = False
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
45
197
e1bc8c4cbb1a Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 196
diff changeset
46 self.power_bonus = 0 # Never goes over 30.
e1bc8c4cbb1a Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 196
diff changeset
47
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
48
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
49 class Player(object):
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
50 def __init__(self, state, game, anm_wrapper, speed=4., hitbox_size=2.5, graze_hitbox_size=42.):
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
51 self._sprite = None
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
52 self._anmrunner = None
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
53 self._game = game
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
54 self.anm_wrapper = anm_wrapper
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
55
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
56 self.speed = speed
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
57 self.focused_speed = speed/2.
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
58
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
59 self.hitbox_size = hitbox_size
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
60 self.hitbox_half_size = self.hitbox_size / 2.
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
61 self.graze_hitbox_size = graze_hitbox_size
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
62 self.graze_hitbox_half_size = self.graze_hitbox_size / 2.
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
63
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
64 self.bullet_type = BulletType(anm_wrapper, 64, 96, 0, 0, 0, hitbox_size=4, damage=48)
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
65 self.bullet_launch_interval = 5
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
66 self.bullet_speed = 12.
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
67 self.bullet_launch_angle = -pi/2
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
68 self.fire_time = 0
142
c7f0fd9d2145 Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents: 130
diff changeset
69
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
70 self.state = state
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
71 self.direction = None
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
72
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
73 self.set_anim(0)
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
74
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
75 self.death_time = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
76
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
77 self.orb_dx_interpolator = None
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
78 self.orb_dy_interpolator = None
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
79
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
80
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
81 @property
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
82 def x(self):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
83 return self.state.x
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
84
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
85
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
86 @property
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
87 def y(self):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
88 return self.state.y
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
89
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
90
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
91 def objects(self):
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
92 return self.orbs if self.state.power >= 8 else []
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
93
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
94
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
95 def set_anim(self, index):
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
96 self._sprite = Sprite()
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
97 self._anmrunner = ANMRunner(self.anm_wrapper, index, self._sprite)
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
98 self._anmrunner.run_frame()
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
99
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
100
156
ebfd328e700c Rename a few functions, move a few things around...
Thibaut Girka <thib@sitedethib.com>
parents: 152
diff changeset
101 def collide(self):
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
102 if not self.state.invulnerable_time and not self.death_time and self.state.touchable: # Border Between Life and Death
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
103 self.death_time = self._game.frame
181
184196480f59 Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 176
diff changeset
104 self._game.new_death((self.state.x, self.state.y), 2)
198
13918723d1bc Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 197
diff changeset
105 self._game.modify_difficulty(-1600)
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
106 for i in range(16):
193
9f58e2a6e950 Fix particles, fix "random" item popping, change update order to match the original game's more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 191
diff changeset
107 self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range.
152
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 142
diff changeset
108
86807b8a63bd Add collisions with enemies and items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 142
diff changeset
109
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
110 def update(self, keystate):
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
111 if self.death_time == 0 or self._game.frame - self.death_time > 60:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
112 try:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
113 dx, dy = {16: (0.0, -1.0), 32: (0.0, 1.0), 64: (-1.0, 0.0), 128: (1.0, 0.0),
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
114 16|64: (-SQ2, -SQ2), 16|128: (SQ2, -SQ2),
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
115 32|64: (-SQ2, SQ2), 32|128: (SQ2, SQ2)}[keystate & (16|32|64|128)]
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
116 except KeyError:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
117 speed = 0.0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
118 dx, dy = 0.0, 0.0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
119 else:
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
120 speed = self.focused_speed if keystate & 4 else self.speed
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
121 dx, dy = dx * speed, dy * speed
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
122
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
123 if dx < 0 and self.direction != -1:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
124 self.set_anim(1)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
125 self.direction = -1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
126 elif dx > 0 and self.direction != +1:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
127 self.set_anim(3)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
128 self.direction = +1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
129 elif dx == 0 and self.direction is not None:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
130 self.set_anim({-1: 2, +1: 4}[self.direction])
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
131 self.direction = None
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
132
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
133 self.state.x += dx
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
134 self.state.y += dy
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
135
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
136 if not self.state.focused and keystate & 4:
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
137 self.orb_dx_interpolator = Interpolator((24,), self._game.frame,
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
138 (8,), self._game.frame + 8,
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
139 lambda x: x ** 2)
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
140 self.orb_dy_interpolator = Interpolator((0,), self._game.frame,
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
141 (-32,), self._game.frame + 8)
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
142 self.state.focused = True
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
143 elif self.state.focused and not keystate & 4:
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
144 self.orb_dx_interpolator = Interpolator((8,), self._game.frame,
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
145 (24,), self._game.frame + 8,
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
146 lambda x: x ** 2)
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
147 self.orb_dy_interpolator = Interpolator((-32,), self._game.frame,
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
148 (0,), self._game.frame + 8)
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
149 self.state.focused = False
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
150
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
151 if self.orb_dx_interpolator:
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
152 self.orb_dx_interpolator.update(self._game.frame)
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
153 dx, = self.orb_dx_interpolator.values
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
154 self.orbs[0].offset_x = -dx
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
155 self.orbs[1].offset_x = dx
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
156 if self.orb_dy_interpolator:
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
157 self.orb_dy_interpolator.update(self._game.frame)
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
158 dy, = self.orb_dy_interpolator.values
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
159 self.orbs[0].offset_y = dy
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
160 self.orbs[1].offset_y = dy
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
161
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
162 if self.state.invulnerable_time > 0:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
163 self.state.invulnerable_time -= 1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
164
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
165 m = self.state.invulnerable_time % 8
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
166 if m == 0:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
167 self._sprite.color = (255, 255, 255)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
168 self._sprite._changed = True
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
169 elif m == 2:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
170 self._sprite.color = (64, 64, 64)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
171 self._sprite._changed = True
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
172
196
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
173 if keystate & 1 and self.fire_time == 0:
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
174 self.fire_time = 30
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
175 if self.fire_time > 0:
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
176 self.fire()
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
177 self.fire_time -= 1
1e501e3b6645 Add a subclass for each character, and implement player attacks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 193
diff changeset
178
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
179 if self.death_time:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
180 time = self._game.frame - self.death_time
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
181 if time == 6: # too late, you are dead :(
175
5dc243bcf312 Don’t collect the items you drop while dying…
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
182 self.state.touchable = False
184
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
183 self.state.lives -= 1
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
184 if self.state.power > 16:
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
185 self.state.power -= 16
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
186 else:
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
187 self.state.power = 0
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
188
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
189 self._game.drop_bonus(self.state.x, self.state.y, 2,
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
190 end_pos=(self._game.prng.rand_double() * 288 + 48, # 102h.exe@0x41f3dc
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
191 self._game.prng.rand_double() * 192 - 64)) # @0x41f3
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
192 for i in range(5):
184
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
193 self._game.drop_bonus(self.state.x, self.state.y, 0,
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
194 end_pos=(self._game.prng.rand_double() * 288 + 48,
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
195 self._game.prng.rand_double() * 192 - 64))
54eb6b254b7b When touched, drop the items at the right place, and add precisions about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 181
diff changeset
196
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
197 elif time == 7:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
198 self._sprite.mirrored = False
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
199 self._sprite.fade(24, 128, lambda x: x)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
200 self._sprite.blendfunc = 1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
201 self._sprite.scale_in(24, 0., 2., lambda x: x)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
202
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
203 elif time == 31:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
204 self.state.x = 192.0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
205 self.state.y = 384.0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
206 self.direction = None
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
207
172
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
208 self._sprite = Sprite()
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
209 self._anmrunner = ANMRunner(self.anm_wrapper, 0, self._sprite)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
210 self._sprite.alpha = 128
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
211 self._sprite.rescale = 0., 2.
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
212 self._sprite.fade(30, 255, lambda x: x)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
213 self._sprite.blendfunc = 1
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
214 self._sprite.scale_in(30, 1., 1., lambda x: x)
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
215 self._anmrunner.run_frame()
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
216
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
217 elif time == 60: # respawned
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
218 self.state.touchable = True
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
219 self.state.invulnerable_time = 240
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
220 self._sprite.blendfunc = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
221
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
222 if time > 30:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
223 for bullet in self._game.bullets:
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
224 bullet.cancel()
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
225
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
226 if time > 90: # start the bullet hell again
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
227 self.death_time = 0
ea2ad94c33a0 Implement player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
228
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
229
199
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
230 for orb in self.orbs:
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
231 orb.update()
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
232
8ec34c56fed0 Implement orbs.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 198
diff changeset
233
130
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
234 self._anmrunner.run_frame()
11ab06f4c4c6 Introduce characters!
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
235