annotate pytouhou/game/bullet.py @ 142:c7f0fd9d2145

Simple collision detection
author Thibaut Girka <thib@sitedethib.com>
date Sun, 25 Sep 2011 20:56:14 +0200
parents 81e05aed8db5
children 30338dc33a7b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
2 ##
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
4 ##
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
8 ##
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
12 ## GNU General Public License for more details.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
13 ##
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
14
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15 from math import cos, sin, atan2, pi
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
16
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
17 from pytouhou.utils.interpolator import Interpolator
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18 from pytouhou.vm.anmrunner import ANMRunner
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19 from pytouhou.game.sprite import Sprite
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
20
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
21
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22 class Bullet(object):
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
23 def __init__(self, pos, bullet_type, sprite_idx_offset,
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24 angle, speed, attributes, flags, player, game_state):
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25 self._game_state = game_state
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
26 self._sprite = None
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
27 self._anmrunner = None
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28 self._removed = False
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29 self._launched = False
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
30 self._bullet_type = bullet_type
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
31
142
c7f0fd9d2145 Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents: 127
diff changeset
32 self.hitbox_half_size = bullet_type.hitbox_size / 2.
c7f0fd9d2145 Simple collision detection
Thibaut Girka <thib@sitedethib.com>
parents: 127
diff changeset
33
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
34 self.speed_interpolator = None
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
35 self.frame = 0
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
36 self.grazed = False
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
37
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38 self.player = player
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40 self.sprite_idx_offset = sprite_idx_offset
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42 self.flags = flags
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 self.attributes = list(attributes)
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
44
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45 self.x, self.y = pos
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46 self.angle = angle
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47 self.speed = speed
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
48 dx, dy = cos(angle) * speed, sin(angle) * speed
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
49 self.delta = dx, dy
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
51 #TODO
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
52 if flags & 14:
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
53 if flags & 2:
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
54 index = bullet_type.launch_anim2_index
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
55 launch_mult = bullet_type.launch_anim_penalties[0]
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
56 elif flags & 4:
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
57 index = bullet_type.launch_anim4_index
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
58 launch_mult = bullet_type.launch_anim_penalties[1]
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
59 else:
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
60 index = bullet_type.launch_anim8_index
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
61 launch_mult = bullet_type.launch_anim_penalties[2]
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
62 self.launch_delta = dx * launch_mult, dy * launch_mult
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
63 self._sprite = Sprite()
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
64 self._anmrunner = ANMRunner(bullet_type.anm_wrapper,
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
65 index, self._sprite,
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
66 bullet_type.launch_anim_offsets[sprite_idx_offset])
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
67 self._anmrunner.run_frame()
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
68 else:
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
69 self.launch()
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
70
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
71 self._sprite.angle = angle
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
72
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
74 def is_visible(self, screen_width, screen_height):
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
75 tx, ty, tw, th = self._sprite.texcoords
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
76 x, y = self.x, self.y
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78 max_x = tw / 2.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
79 max_y = th / 2.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80
123
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
81 if (max_x < x - screen_width
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
82 or max_x < -x
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
83 or max_y < y - screen_height
d1c82d43bbf3 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
84 or max_y < -y):
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85 return False
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
86 return True
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
89 def set_anim(self, sprite_idx_offset=None):
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
90 if sprite_idx_offset is not None:
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
91 self.sprite_idx_offset = sprite_idx_offset
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
92
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
93 bt = self._bullet_type
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
94 self._sprite = Sprite()
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
95 self._sprite.angle = self.angle
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
96 self._anmrunner = ANMRunner(bt.anm_wrapper, bt.anim_index,
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
97 self._sprite, self.sprite_idx_offset)
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
98 self._anmrunner.run_frame()
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
99
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
100
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
101 def launch(self):
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
102 self._launched = True
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
103 self.update = self.update_full
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
104 self.set_anim()
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
105 if self.flags & 1:
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
106 self.speed_interpolator = Interpolator((self.speed + 5.,), 0,
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
107 (self.speed,), 16)
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
108
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
109
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
110 def update(self):
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
111 dx, dy = self.launch_delta
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
112 self.x += dx
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
113 self.y += dy
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
114
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
115 if not self._anmrunner.run_frame():
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
116 self.launch()
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
117
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
118
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
119 def update_simple(self):
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
120 dx, dy = self.delta
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
121 self.x += dx
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
122 self.y += dy
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
123
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
124
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
125 def update_full(self):
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
126 sprite = self._sprite
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
127
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
128 if self._anmrunner is not None and not self._anmrunner.run_frame():
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
129 self._anmrunner = None
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
130
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
131 #TODO: flags
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
132 x, y = self.x, self.y
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
133 dx, dy = self.delta
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
135 if self.flags & 16:
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
136 frame, count = self.attributes[0:2]
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
137 length, angle = self.attributes[4:6]
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
138 angle = self.angle if angle < -900.0 else angle #TODO: is that right?
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
139 dx, dy = dx + cos(angle) * length, dy + sin(angle) * length
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
140 self.delta = dx, dy
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
141 if self.frame == frame: #TODO: include last frame, or not?
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
142 if count > 0:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
143 self.attributes[1] -= 1
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
144 self.frame = 0
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
145 else:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
146 self.flags ^= 16
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
147 elif self.flags & 32:
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
148 #TODO: check
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
149 frame, count = self.attributes[0:2]
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
150 acceleration, angular_speed = self.attributes[4:6]
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
151 self.speed += acceleration
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
152 self.angle += angular_speed
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
153 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
154 self.delta = dx, dy
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
155 sprite.angle = self.angle
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
156 if sprite.automatic_orientation:
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
157 sprite._changed = True
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
158 if self.frame % frame == 0:
127
81e05aed8db5 Fix bullets
Thibaut Girka <thib@sitedethib.com>
parents: 124
diff changeset
159 if count >= 0:
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
160 self.attributes[1] -= 1
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
161 else:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
162 self.flags ^= 32
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
163 elif self.flags & 448:
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
164 #TODO: check
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
165 frame, count = self.attributes[0:2]
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
166 angle, speed = self.attributes[4:6]
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
167 if self.frame % frame == 0:
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
168 count = count - 1
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
169
124
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
170 if self.frame != 0:
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
171 self.speed = speed
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
172
124
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
173 if self.flags & 64:
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
174 self.angle += angle
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
175 elif self.flags & 128:
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
176 self.angle = atan2(self.player.y - y, self.player.x - x) + angle
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
177 elif self.flags & 256:
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
178 self.angle = angle
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
179
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
180 dx, dy = cos(self.angle) * speed, sin(self.angle) * speed
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
181 self.delta = dx, dy
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
182 sprite.angle = self.angle
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
183 if sprite.automatic_orientation:
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
184 sprite._changed = True
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
185
127
81e05aed8db5 Fix bullets
Thibaut Girka <thib@sitedethib.com>
parents: 124
diff changeset
186 if count >= 0:
124
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
187 self.speed_interpolator = Interpolator((self.speed,), self.frame,
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
188 (0.,), self.frame + frame - 1)
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
189 else:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
190 self.flags &= ~448
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
191
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
192 self.attributes[1] = count
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
193 #TODO: other flags
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
194 elif not self.speed_interpolator and self._anmrunner is None:
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
195 self.update = self.update_simple
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
196
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
197 if self.speed_interpolator:
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
198 self.speed_interpolator.update(self.frame)
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
199 self.speed, = self.speed_interpolator.values
124
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
200 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
f06e96dbed4e Fix a few things with special bullet flags
Thibaut Girka <thib@sitedethib.com>
parents: 123
diff changeset
201 self.delta = dx, dy
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
202
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
203 self.x, self.y = x + dx, y + dy
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
204
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
205 self.frame += 1
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
206