annotate pytouhou/game/enemy.pyx @ 551:0d7a16e0f834

Don’t display spellcard backgrounds either with the SDL backend.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 27 May 2014 17:41:52 +0200
parents e35bef07290d
children a0fa01cd9f70
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
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
15 from libc.math cimport cos, sin, atan2, M_PI as pi
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
16
547
e35bef07290d Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 545
diff changeset
17 from pytouhou.vm import ANMRunner
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18 from pytouhou.game.sprite import Sprite
448
3bc37791f0a2 Make Bullet.state an enum.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 447
diff changeset
19 from pytouhou.game.bullet cimport Bullet, LAUNCHED
471
06f0eeb519bb Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 468
diff changeset
20 from pytouhou.game.laser cimport Laser, PlayerLaser
443
cae83b963695 Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 441
diff changeset
21 from pytouhou.game.effect cimport Effect
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
24 cdef class Callback:
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
25 def __init__(self, function=None, args=()):
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
26 self.function = function
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
27 self.args = args
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
28
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
29 def __nonzero__(self):
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
30 return self.function is not None
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
31
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
32 cpdef enable(self, function, tuple args):
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
33 self.function = function
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
34 self.args = args
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
35
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
36 cpdef disable(self):
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
37 self.function = None
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
38
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
39 cpdef fire(self):
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
40 if self.function is not None:
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
41 self.function(*self.args)
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
42 self.function = None
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
43
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
44
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
45 cdef class Enemy(Element):
447
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 443
diff changeset
46 def __init__(self, pos, long life, long _type, long bonus_dropped, long die_score, anms, Game game):
440
b9d2db93972f Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 437
diff changeset
47 Element.__init__(self)
b9d2db93972f Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 437
diff changeset
48
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
49 self._game = game
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 408
diff changeset
50 self._anms = anms
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
51 self._type = _type
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
52
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 311
diff changeset
53 self.process = None
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
54 self.visible = True
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
55 self.was_visible = False
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
56 self.bonus_dropped = bonus_dropped
319
9a4119e2cc74 Use Enemy.die_score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 318
diff changeset
57 self.die_score = die_score
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
58
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
59 self.frame = 0
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
60
270
7a9135b88853 Partially fix some of Flandre's spellcards.
Thibaut Girka <thib@sitedethib.com>
parents: 268
diff changeset
61 self.x, self.y, self.z = pos
209
005ea47e11e0 Create enemy with negative life as it should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 207
diff changeset
62 self.life = 1 if life < 0 else life
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
63 self.touchable = True
210
f5be441d2c42 Implement collidable boolean of enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 209
diff changeset
64 self.collidable = True
67
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
65 self.damageable = True
e2cb9d434dc2 Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents: 62
diff changeset
66 self.death_flags = 0
177
6e8653ff2b23 Fix boss mode and don’t suicide the boss when she just want to kill the other enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 173
diff changeset
67 self.boss = False
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
68 self.difficulty_coeffs = (-.5, .5, 0, 0, 0, 0)
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
69 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.)
274
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
70 self.current_laser_id = 0
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
71 self.laser_by_id = {}
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
72 self.bullet_attributes = None
36
f46c18872796 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
73 self.bullet_launch_offset = (0, 0)
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
74 self.low_life_trigger = -1
268
dd621ad72beb Fix callback handling and damage dealing.
Thibaut Girka <thib@sitedethib.com>
parents: 253
diff changeset
75 self.timeout = -1
350
b3049fb5c448 Fix remaining lives display issue
Thibaut Girka <thib@sitedethib.com>
parents: 346
diff changeset
76 self.remaining_lives = 0
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
77
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
78 self.death_callback = Callback()
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
79 self.boss_callback = Callback()
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
80 self.low_life_callback = Callback()
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
81 self.timeout_callback = Callback()
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
82
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
83 self.automatic_orientation = False
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
84
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
85 self.bullet_launch_interval = 0
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
86 self.bullet_launch_timer = 0
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
87 self.delay_attack = False
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88
167
e483b5a7e84b Fix default death animation.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 166
diff changeset
89 self.death_anim = 0
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
90 self.movement_dependant_sprites = None
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
91 self.direction = 0
20
6ebf9539c077 Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents: 18
diff changeset
92 self.interpolator = None #TODO
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
93 self.speed_interpolator = None
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
94 self.update_mode = 0
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
95 self.angle = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
96 self.speed = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
97 self.rotation_speed = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
98 self.acceleration = 0.
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
99
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
100 self.hitbox_half_size[:] = [0, 0]
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
101 self.screen_box = None
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
102
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
103 self.aux_anm = 8 * [None]
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
104
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
105
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
106 property objects:
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
107 def __get__(self):
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
108 return [self] + [anm for anm in self.aux_anm if anm is not None]
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
109
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
110
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
111 cpdef play_sound(self, index):
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
112 name = {
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
113 5: 'power0',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
114 6: 'power1',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
115 7: 'tan00',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
116 8: 'tan01',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
117 9: 'tan02',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
118 14: 'cat00',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
119 16: 'lazer00',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
120 17: 'lazer01',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
121 18: 'enep01',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
122 22: 'tan00', #XXX
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
123 24: 'tan02', #XXX
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
124 25: 'kira00',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
125 26: 'kira01',
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
126 27: 'kira02'
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
127 }[index]
379
e0e284fcb288 Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 366
diff changeset
128 self._game.sfx_player.play('%s.wav' % name)
343
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
129
94fdb6c782c1 Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 335
diff changeset
130
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
131 cpdef set_hitbox(self, double width, double height):
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
132 self.hitbox_half_size[:] = [width / 2, height / 2]
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
133
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
134
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
135 cpdef set_bullet_attributes(self, type_, anim, sprite_idx_offset,
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
136 unsigned long bullets_per_shot,
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
137 unsigned long number_of_shots, double speed,
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
138 double speed2, launch_angle, angle, flags):
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
139 cdef double speed_a, speed_b
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
140 cdef long nb_a, nb_b, shots_a, shots_b
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
141
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
142 # Apply difficulty-specific modifiers
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
143 speed_a, speed_b, nb_a, nb_b, shots_a, shots_b = self.difficulty_coeffs
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
144 diff_coeff = self._game.difficulty / 32.
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
145
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
146 speed += speed_a * (1. - diff_coeff) + speed_b * diff_coeff
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
147 speed2 += (speed_a * (1. - diff_coeff) + speed_b * diff_coeff) / 2.
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
148 bullets_per_shot += <long>(nb_a * (1. - diff_coeff) + nb_b * diff_coeff)
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
149 number_of_shots += <long>(shots_a * (1. - diff_coeff) + shots_b * diff_coeff)
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
150
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
151 self.bullet_attributes = (type_, anim, sprite_idx_offset, bullets_per_shot,
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
152 number_of_shots, speed, speed2, launch_angle,
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
153 angle, flags)
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
154 if not self.delay_attack:
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
155 self.fire()
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
156
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
157
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
158 cpdef set_bullet_launch_interval(self, long value, unsigned long start=0):
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
159 # Apply difficulty-specific modifiers:
329
1bb78c469f64 Fix difficulty influence on bullet launch interval, and fix instruction 77's rand usage
Thibaut Girka <thib@sitedethib.com>
parents: 328
diff changeset
160 #TODO: check every value possible! Look around 102h.exe@0x408720
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
161 value -= value * (self._game.difficulty - 16) // 80
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
162
329
1bb78c469f64 Fix difficulty influence on bullet launch interval, and fix instruction 77's rand usage
Thibaut Girka <thib@sitedethib.com>
parents: 328
diff changeset
163 self.bullet_launch_interval = value
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
164 self.bullet_launch_timer = start % value if value > 0 else 0
182
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
165
20843875ad8f (Hopefully) use difficulty as it should.
Thibaut Girka <thib@sitedethib.com>
parents: 181
diff changeset
166
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
167 cpdef fire(self, offset=None, bullet_attributes=None, tuple launch_pos=None):
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
168 cdef unsigned long type_, bullets_per_shot, number_of_shots
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
169 cdef double speed, speed2, launch_angle, angle
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
170
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
171 (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots,
207
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 202
diff changeset
172 speed, speed2, launch_angle, angle, flags) = bullet_attributes or self.bullet_attributes
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
173
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
174 bullet_type = self._game.bullet_types[type_idx]
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
175
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
176 if launch_pos is None:
207
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 202
diff changeset
177 ox, oy = offset or self.bullet_launch_offset
709f42eaa55e Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 202
diff changeset
178 launch_pos = self.x + ox, self.y + oy
109
e93a7ed4f203 Implement bullet_launch_offset thing
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
179
270
7a9135b88853 Partially fix some of Flandre's spellcards.
Thibaut Girka <thib@sitedethib.com>
parents: 268
diff changeset
180 if speed < 0.3 and speed != 0.0:
253
ea4832f843aa Fix initial bullet speed
Thibaut Girka <thib@sitedethib.com>
parents: 251
diff changeset
181 speed = 0.3
104
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
182 if speed2 < 0.3:
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
183 speed2 = 0.3
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
184
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
185 self.bullet_launch_timer = 0
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
186
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
187 player = self.select_player()
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
188
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
189 if type_ in (67, 69, 71):
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
190 launch_angle += self.get_player_angle(launch_pos, player)
247
fb3a263213d1 Fix instruction 70 to always fire to the right.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 242
diff changeset
191 if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2:
79
ffe2c2b9912c Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
192 launch_angle += pi / bullets_per_shot
104
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
193 if type_ != 75:
6c59d0eeb5fa Implement ECL instruction 75 in the same exact way as 102h.exe
Thibaut Girka <thib@sitedethib.com>
parents: 103
diff changeset
194 launch_angle -= angle * (bullets_per_shot - 1) / 2.
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
195
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
196 bullets = self._game.bullets
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
197 nb_bullets_max = self._game.nb_bullets_max
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
198
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
199 for shot_nb in xrange(number_of_shots):
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
200 shot_speed = speed if shot_nb == 0 else speed + (speed2 - speed) * float(shot_nb) / float(number_of_shots)
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
201 bullet_angle = launch_angle
311
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
202 if type_ in (69, 70, 71, 74):
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
203 launch_angle += angle
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
204 for bullet_nb in xrange(bullets_per_shot):
143
ea21bb37febe Add max bullets limit
Thibaut Girka <thib@sitedethib.com>
parents: 135
diff changeset
205 if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
ea21bb37febe Add max bullets limit
Thibaut Girka <thib@sitedethib.com>
parents: 135
diff changeset
206 break
ea21bb37febe Add max bullets limit
Thibaut Girka <thib@sitedethib.com>
parents: 135
diff changeset
207
135
c53d91300c1c Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 134
diff changeset
208 if type_ == 75: # 102h.exe@0x4138cf
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
209 bullet_angle = self._game.prng.rand_double() * (launch_angle - angle) + angle
135
c53d91300c1c Implement instruction 74.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 134
diff changeset
210 if type_ in (74, 75): # 102h.exe@0x4138cf
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
211 shot_speed = self._game.prng.rand_double() * (speed - speed2) + speed2
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
212 bullets.append(Bullet(launch_pos, bullet_type, sprite_idx_offset,
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
213 bullet_angle, shot_speed,
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 105
diff changeset
214 self.extended_bullet_attributes,
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 143
diff changeset
215 flags, player, self._game))
311
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
216
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
217 if type_ in (69, 70, 71, 74):
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
218 bullet_angle += 2. * pi / bullets_per_shot
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
219 else:
550ec10cccbc Fix angle between salves of circle-distributed bullets.
Thibaut Girka <thib@sitedethib.com>
parents: 309
diff changeset
220 bullet_angle += angle
48
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
221
8353c33d53d4 Support a few more instructions
Thibaut Girka <thib@sitedethib.com>
parents: 46
diff changeset
222
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
223 cpdef new_laser(self, unsigned long variant, laser_type, sprite_idx_offset,
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
224 double angle, speed, start_offset, end_offset, max_length,
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
225 width, start_duration, duration, end_duration,
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
226 grazing_delay, grazing_extra_duration, unknown,
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
227 tuple offset=None):
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
228 cdef double ox, oy
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
229
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
230 if offset is None:
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
231 offset = self.bullet_launch_offset
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
232 ox, oy = offset
277
219edad0f395 Fix initial laser offset.
Thibaut Girka <thib@sitedethib.com>
parents: 274
diff changeset
233 launch_pos = self.x + ox, self.y + oy
274
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
234 if variant == 86:
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
235 angle += self.get_player_angle(launch_pos)
274
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
236 laser = Laser(launch_pos, self._game.laser_types[laser_type],
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
237 sprite_idx_offset, angle, speed,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
238 start_offset, end_offset, max_length, width,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
239 start_duration, duration, end_duration, grazing_delay,
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
240 grazing_extra_duration, self._game)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
241 self._game.lasers.append(laser)
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
242 self.laser_by_id[self.current_laser_id] = laser
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
243
f037bca24f2d Partially implement lasers.
Thibaut Girka <thib@sitedethib.com>
parents: 270
diff changeset
244
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
245 cpdef Player select_player(self, list players=None):
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
246 if players is None:
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
247 players = self._game.players
486
2f53be1b2f60 Merge netplay branch.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 479 471
diff changeset
248 return min(players, key=self.select_player_key)
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
249
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
250
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
251 cpdef double get_player_angle(self, tuple pos=None, Player player=None):
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
252 cdef double x, y
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
253 if player is None:
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
254 player = self.select_player()
132
fba45c37ec99 Fix initial angle of bullets with bullet_launch_offset enabled.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 130
diff changeset
255 x, y = pos or (self.x, self.y)
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
256 return atan2(player.y - y, player.x - x)
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
257
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
258
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
259 cpdef set_anim(self, index):
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 408
diff changeset
260 entry = 0 if index in self._anms[0].scripts else 1
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
261 self.sprite = Sprite()
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 408
diff changeset
262 self.anmrunner = ANMRunner(self._anms[entry], index, self.sprite)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
263
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
264
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
265 cdef void die_anim(self):
248
77b83064b57e Use the correct animation for player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 247
diff changeset
266 anim = {0: 3, 1: 4, 2: 5}[self.death_anim % 256] # The TB is wanted, if index isn’t in these values the original game crashs.
77b83064b57e Use the correct animation for player death.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 247
diff changeset
267 self._game.new_effect((self.x, self.y), anim)
379
e0e284fcb288 Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 366
diff changeset
268 self._game.sfx_player.play('enep00.wav')
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
269
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
270
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
271 cdef void drop_particles(self, long number, long color):
190
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
272 if color == 0:
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
273 if self._game.stage in [1, 2, 7]:
dbe6b7b2d3fc Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 184
diff changeset
274 color = 3
388
ac2891afb0bb Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
275 color += 9
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
276 for i in xrange(number):
388
ac2891afb0bb Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 384
diff changeset
277 self._game.new_particle((self.x, self.y), color, 256) #TODO: find the real size.
154
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
278
364935f6e313 Implement enemy killing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 152
diff changeset
279
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
280 cpdef set_aux_anm(self, long number, long index):
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 408
diff changeset
281 entry = 0 if index in self._anms[0].scripts else 1
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 408
diff changeset
282 self.aux_anm[number] = Effect((self.x, self.y), index, self._anms[entry])
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
283
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
284
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
285 cpdef set_pos(self, double x, double y, double z):
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
286 self.x, self.y = x, y
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
287 self.update_mode = 1
437
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
288 self.interpolator = Interpolator((x, y), self._game.frame)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
289
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
290
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
291 cpdef move_to(self, unsigned long duration, double x, double y, double z,
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
292 formula):
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
293 frame = self._game.frame
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
294 self.speed_interpolator = None
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
295 self.update_mode = 1
437
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
296 self.interpolator = Interpolator((self.x, self.y), frame,
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
297 (x, y), frame + duration - 1,
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
298 formula)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
299
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
300 self.angle = atan2(y - self.y, x - self.x)
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
301
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
302
509
292fea5c584e Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 507
diff changeset
303 cpdef stop_in(self, unsigned long duration, formula):
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
304 frame = self._game.frame
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
305 self.interpolator = None
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
306 self.update_mode = 1
437
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
307 self.speed_interpolator = Interpolator((self.speed,), frame,
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
308 (0.,), frame + duration - 1,
d778db08190f Make Interpolator an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 433
diff changeset
309 formula)
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 73
diff changeset
310
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
311
545
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
312 cpdef set_boss(self, bint enable):
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
313 if enable:
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
314 self.boss = True
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
315 self._game.boss = self
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
316 self._game.interface.set_boss_life()
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
317 else:
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
318 self.boss = False
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
319 self._game.boss = None
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
320
bcff39c920ab Set boss mode directly from the enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 540
diff changeset
321
447
78e1c3864e73 Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 443
diff changeset
322 cdef bint is_visible(self, long screen_width, long screen_height):
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
323 if self.sprite is not None:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
324 if self.sprite.corner_relative_placement:
73
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
325 raise Exception #TODO
527
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
326 tw, th = self.sprite._texcoords[2], self.sprite._texcoords[3]
73
e4af16a019d3 Do not remove enemies as soon as they lose their animation (Daiyousei...)
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
327 else:
527
db28538cd399 Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 509
diff changeset
328 tw, th = 0., 0.
29
afa91be769ae Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents: 23
diff changeset
329
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
330 x, y = self.x, self.y
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
331 max_x = tw / 2
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
332 max_y = th / 2
29
afa91be769ae Don't lose time updating off-screen enemies' sprites
Thibaut Girka <thib@sitedethib.com>
parents: 23
diff changeset
333
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
334 if (max_x < x - screen_width
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
335 or max_x < -x
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
336 or max_y < y - screen_height
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
337 or max_y < -y):
23
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
338 return False
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
339 return True
444ac7bca7bc Refacto ECL stuff, add support for a few instructions, and add some culling
Thibaut Girka <thib@sitedethib.com>
parents: 22
diff changeset
340
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
341
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
342 cdef void check_collisions(self):
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
343 cdef Bullet bullet
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
344 cdef Player player
471
06f0eeb519bb Make Laser and Orb extension types, and use that where possible.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 468
diff changeset
345 cdef PlayerLaser laser
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
346 cdef long damages
540
53fa73932e9a Fix warnings introduced in Cython 0.20, when more than one pointer is defined on the same line.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 527
diff changeset
347 cdef double half_size[2]
53fa73932e9a Fix warnings introduced in Cython 0.20, when more than one pointer is defined on the same line.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 527
diff changeset
348 cdef double phalf_size
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
349
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
350 # Check for collisions
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
351 ex, ey = self.x, self.y
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
352 ehalf_size_x = self.hitbox_half_size[0]
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
353 ehalf_size_y = self.hitbox_half_size[1]
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
354 ex1, ex2 = ex - ehalf_size_x, ex + ehalf_size_x
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
355 ey1, ey2 = ey - ehalf_size_y, ey + ehalf_size_y
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
356
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
357 damages = 0
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
358
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
359 # Check for enemy-bullet collisions
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
360 for bullet in self._game.players_bullets:
335
2350147cf043 Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents: 329
diff changeset
361 if bullet.state != LAUNCHED:
2350147cf043 Fix bullet cancellation and removal
Thibaut Girka <thib@sitedethib.com>
parents: 329
diff changeset
362 continue
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
363 half_size[0] = bullet.hitbox[0]
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
364 half_size[1] = bullet.hitbox[1]
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
365 bx, by = bullet.x, bullet.y
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 212
diff changeset
366 bx1, bx2 = bx - half_size[0], bx + half_size[0]
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 212
diff changeset
367 by1, by2 = by - half_size[1], by + half_size[1]
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
368
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
369 if not (bx2 < ex1 or bx1 > ex2
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
370 or by2 < ey1 or by1 > ey2):
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
371 bullet.collide()
408
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
372 damages += bullet.damage
379
e0e284fcb288 Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 366
diff changeset
373 self._game.sfx_player.play('damage00.wav')
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
374
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
375 # Check for enemy-laser collisions
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
376 for laser in self._game.players_lasers:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
377 if not laser:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
378 continue
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
379
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
380 half_size[0] = laser.hitbox[0]
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
381 lx, ly = laser.x, laser.y * 2.
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
382 lx1, lx2 = lx - half_size[0], lx + half_size[0]
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
383
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
384 if not (lx2 < ex1 or lx1 > ex2
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
385 or ly < ey1):
408
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
386 damages += laser.damage
379
e0e284fcb288 Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 366
diff changeset
387 self._game.sfx_player.play('damage00.wav')
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 320
diff changeset
388 self.drop_particles(1, 1) #TODO: don’t call each frame.
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 282
diff changeset
389
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
390 # Check for enemy-player collisions
212
78e9957ad344 Hopefully fix enemy-player collision
Thibaut Girka <thib@sitedethib.com>
parents: 210
diff changeset
391 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3.
78e9957ad344 Hopefully fix enemy-player collision
Thibaut Girka <thib@sitedethib.com>
parents: 210
diff changeset
392 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3.
210
f5be441d2c42 Implement collidable boolean of enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 209
diff changeset
393 if self.collidable:
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
394 for player in self._game.players:
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
395 px, py = player.x, player.y
390
b11953cf1d3b Use only half-size hitboxes for player.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 388
diff changeset
396 phalf_size = player.sht.hitbox
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
397 px1, px2 = px - phalf_size, px + phalf_size
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
398 py1, py2 = py - phalf_size, py + phalf_size
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
399
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
400 #TODO: box-box or point-in-box?
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
401 if not (ex2 < px1 or ex1 > px2 or ey2 < py1 or ey1 > py2):
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
402 if not self.boss:
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
403 damages += 10
212
78e9957ad344 Hopefully fix enemy-player collision
Thibaut Girka <thib@sitedethib.com>
parents: 210
diff changeset
404 player.collide()
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
405
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
406 # Adjust damages
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
407 damages = min(70, damages)
300
da53bc29b94a Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 294
diff changeset
408 score = (damages // 5) * 10
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
409 self._game.players[0].score += score #TODO: better distribution amongst the players.
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
410
408
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
411 if self.damageable:
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
412 if self._game.spellcard is not None:
408
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
413 #TODO: there is a division by 3, somewhere... where is it?
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
414 if damages <= 7:
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
415 damages = 1 if damages else 0
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
416 else:
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
417 damages //= 7
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
418
507
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
419 nb_players = len(self._game.players)
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
420 if nb_players > 1:
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
421 if damages <= nb_players:
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
422 damages = 1 if damages else 0
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
423 else:
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
424 damages //= nb_players
507d446dc6cf Divide the damages inflicted by the number of players.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 497
diff changeset
425
408
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
426 # Apply damages
c689ff1743bf Do the correct score calculation even when the enemy isn’t damageable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 390
diff changeset
427 self.life -= damages
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
428
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
429
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
430 cdef void handle_callbacks(self):
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
431 #TODO: implement missing callbacks and clean up!
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
432 if self.life <= 0 and self.touchable:
354
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
433 self.timeout = -1 #TODO: not really true, the timeout is frozen
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
434 self.timeout_callback.disable()
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
435 death_flags = self.death_flags & 7
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
436
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
437 self.die_anim()
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
438
319
9a4119e2cc74 Use Enemy.die_score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 318
diff changeset
439 #TODO: verify if the score is added with all the different flags.
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
440 self._game.players[0].score += self.die_score #TODO: better distribution amongst the players.
319
9a4119e2cc74 Use Enemy.die_score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 318
diff changeset
441
320
1a4ffdda8735 Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 319
diff changeset
442 #TODO: verify if that should really be there.
1a4ffdda8735 Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 319
diff changeset
443 if self.boss:
1a4ffdda8735 Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 319
diff changeset
444 self._game.change_bullets_into_bonus()
1a4ffdda8735 Cancel the bullets when a boss is killed and transfer them to the score.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 319
diff changeset
445
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
446 if death_flags < 4:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
447 if self.bonus_dropped > -1:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
448 self.drop_particles(7, 0)
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
449 self._game.drop_bonus(self.x, self.y, self.bonus_dropped)
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
450 elif self.bonus_dropped == -1:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
451 if self._game.deaths_count % 3 == 0:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
452 self.drop_particles(10, 0)
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
453 self._game.drop_bonus(self.x, self.y, self._game.bonus_list[self._game.next_bonus])
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
454 self._game.next_bonus = (self._game.next_bonus + 1) % 32
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
455 else:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
456 self.drop_particles(4, 0)
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
457 self._game.deaths_count += 1
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
458 else:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
459 self.drop_particles(4, 0)
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
460
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
461 if death_flags == 0:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
462 self.removed = True
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
463 return
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
464
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
465 if death_flags == 1:
357
26f78fc7acea Fix Koakuma
Thibaut Girka <thib@sitedethib.com>
parents: 354
diff changeset
466 if self.boss:
26f78fc7acea Fix Koakuma
Thibaut Girka <thib@sitedethib.com>
parents: 354
diff changeset
467 self.boss = False #TODO: really?
26f78fc7acea Fix Koakuma
Thibaut Girka <thib@sitedethib.com>
parents: 354
diff changeset
468 self._game.boss = None
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
469 self.touchable = False
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
470 elif death_flags == 2:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
471 pass # Just that?
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
472 elif death_flags == 3:
357
26f78fc7acea Fix Koakuma
Thibaut Girka <thib@sitedethib.com>
parents: 354
diff changeset
473 if self.boss:
26f78fc7acea Fix Koakuma
Thibaut Girka <thib@sitedethib.com>
parents: 354
diff changeset
474 self.boss = False #TODO: really?
26f78fc7acea Fix Koakuma
Thibaut Girka <thib@sitedethib.com>
parents: 354
diff changeset
475 self._game.boss = None
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
476 self.damageable = False
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
477 self.life = 1
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
478 self.death_flags = 0
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
479
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
480 if death_flags != 0:
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
481 self.death_callback.fire()
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
482 elif self.life <= self.low_life_trigger and self.low_life_callback:
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
483 self.low_life_callback.fire()
354
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
484 self.low_life_trigger = -1
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
485 self.timeout_callback.disable()
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
486 elif self.timeout != -1 and self.frame == self.timeout:
366
7dc012f631dc Fix Rumia on timeout
Thibaut Girka <thib@sitedethib.com>
parents: 358
diff changeset
487 self.frame = 0
354
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
488 self.timeout = -1
358
488c094ed51d Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents: 357
diff changeset
489 self._game.kill_enemies()
488c094ed51d Make bosses clean their mess when timeouting
Thibaut Girka <thib@sitedethib.com>
parents: 357
diff changeset
490 self._game.cancel_bullets()
354
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
491
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
492 if self.low_life_trigger > 0:
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
493 self.life = self.low_life_trigger
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
494 self.low_life_trigger = -1
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
495
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
496 if self.timeout_callback:
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
497 self.timeout_callback.fire()
354
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
498 #TODO: this is only done under certain (unknown) conditions!
89ee09453906 Fix callbacks
Thibaut Girka <thib@sitedethib.com>
parents: 350
diff changeset
499 # but it shouldn't hurt anyway, as the only option left is to crash!
497
3da7395f39e3 Make enemy callbacks programmables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 494
diff changeset
500 elif self.death_callback:
366
7dc012f631dc Fix Rumia on timeout
Thibaut Girka <thib@sitedethib.com>
parents: 358
diff changeset
501 self.life = 0 #TODO: do this next frame? Bypass self.touchable?
318
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
502 else:
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
503 raise Exception('What the hell, man!')
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
504
1366cefd0334 Move callbacks handling inside Enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 316
diff changeset
505
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
506 cdef void update(self):
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
507 cdef double x, y, speed
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
508
468
feecdb4a8928 Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 448
diff changeset
509 if self.process is not None:
316
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 311
diff changeset
510 self.process.run_iteration()
f0be7ea62330 Fix a bug with ECL instruction 96, and fix overall ECL handling.
Thibaut Girka <thib@sitedethib.com>
parents: 311
diff changeset
511
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
512 x, y = self.x, self.y
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
513
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
514 if self.update_mode == 1:
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
515 speed = 0.
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
516 if self.interpolator:
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
517 self.interpolator.update(self._game.frame)
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
518 x, y = self.interpolator.values
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
519 if self.speed_interpolator:
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
520 self.speed_interpolator.update(self._game.frame)
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
521 speed, = self.speed_interpolator.values
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
522 else:
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
523 speed = self.speed
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
524 self.speed += self.acceleration
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
525 self.angle += self.rotation_speed
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
526
251
4b549894ef6b Change position/speed interpoletor handling to match the original game more closely.
Thibaut Girka <thib@sitedethib.com>
parents: 248
diff changeset
527 dx, dy = cos(self.angle) * speed, sin(self.angle) * speed
49
cbe1cb50f2fd Refactor ECLRunner/EnemyManager so that all VM stuff goes to ECLRunner
Thibaut Girka <thib@sitedethib.com>
parents: 48
diff changeset
528 if self._type & 2:
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
529 x -= dx
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
530 else:
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
531 x += dx
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
532 y += dy
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
533
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
534 if self.movement_dependant_sprites is not None:
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
535 #TODO: is that really how it works? Almost.
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
536 # Sprite determination is done only once per changement, and is
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 56
diff changeset
537 # superseeded by ins_97.
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
538 end_left, end_right, left, right = self.movement_dependant_sprites
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
539 if x < self.x and self.direction != -1:
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
540 self.set_anim(left)
22
fa87db09fc3a Fix Rumia's animations
Thibaut Girka <thib@sitedethib.com>
parents: 21
diff changeset
541 self.direction = -1
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
542 elif x > self.x and self.direction != +1:
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
543 self.set_anim(right)
22
fa87db09fc3a Fix Rumia's animations
Thibaut Girka <thib@sitedethib.com>
parents: 21
diff changeset
544 self.direction = +1
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
545 elif x == self.x and self.direction != 0:
62
1f591adcea04 Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents: 57
diff changeset
546 self.set_anim({-1: end_left, +1: end_right}[self.direction])
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
547 self.direction = 0
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
548
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
549
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
550 if self.screen_box is not None:
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
551 xmin, ymin, xmax, ymax = self.screen_box
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
552 x = max(xmin, min(x, xmax))
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
553 y = max(ymin, min(y, ymax))
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
554
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 49
diff changeset
555
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
556 self.x, self.y = x, y
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
557
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
558 #TODO
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
559 if self.anmrunner is not None and not self.anmrunner.run_frame():
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
560 self.anmrunner = None
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
561
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
562 if self.sprite is not None and self.visible:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
563 if self.sprite.removed:
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
564 self.sprite = None
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 68
diff changeset
565 else:
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
566 self.sprite.update_orientation(self.angle,
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 300
diff changeset
567 self.automatic_orientation)
36
f46c18872796 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
568
83
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
569
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
570 if self.bullet_launch_interval != 0:
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
571 self.bullet_launch_timer += 1
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
572 if self.bullet_launch_timer == self.bullet_launch_interval:
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
573 self.fire()
fc0294c745b6 Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents: 79
diff changeset
574
202
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
575 # Check collisions
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
576 if self.touchable:
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
577 self.check_collisions()
d348892ef012 Handle enemy collisions and damages in a way closer to the original game.
Thibaut Girka <thib@sitedethib.com>
parents: 197
diff changeset
578
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
579 for anm in self.aux_anm:
441
e8dc95a2a287 Make pytouhou.game.enemy an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 440
diff changeset
580 if anm is not None:
282
dbb1a86c0235 Rename Animations to ANM0 and prepare AnmWrapper for dialogs and interface.
Thibaut Girka <thib@sitedethib.com>
parents: 277
diff changeset
581 anm.x, anm.y = self.x, self.y
242
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
582 anm.update()
1d3c8c7473a2 Implement auxiliary animations of enemies like magic circles, and interruptions from ecl.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 234
diff changeset
583
328
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 320
diff changeset
584 self.handle_callbacks()
56523a16db1d Fix some replay synchronization issues and update the TODO.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 320
diff changeset
585
18
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
586 self.frame += 1
ca26a84916cb Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
587
486
2f53be1b2f60 Merge netplay branch.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 479 471
diff changeset
588
494
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
589 def select_player_key(self, player):
6be9c99a3a24 Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 492
diff changeset
590 return ((player.x - self.x) ** 2 + (player.y - self.y) ** 2, player.character)