annotate pytouhou/game/bullet.py @ 121:1bc0ad774ed4

More impressive data, use a wider range of things, and document things!
author Thibaut Girka <thib@sitedethib.com>
date Fri, 09 Sep 2011 21:36:53 +0200
parents 4300a832f033
children 174324a4da51
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):
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
23 __slots__ = ('x', 'y', 'angle', 'speed', 'frame', 'grazed',
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24 'flags', 'attributes', 'anim_idx', 'sprite_idx_offset', 'player',
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
25 'speed_interpolator',
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
26 '_game_state', '_sprite', '_anmrunner',
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
27 '_removed', '_launched')
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
28
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29 def __init__(self, pos, anim_idx, sprite_idx_offset,
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
30 angle, speed, attributes, flags, player, game_state):
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
31 self._game_state = game_state
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
32 self._sprite = None
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
33 self._anmrunner = None
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34 self._removed = False
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
35 self._launched = False
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
37 self.speed_interpolator = None
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
38 self.frame = 0
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
39 self.grazed = False
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
40
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 self.player = player
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 self.anim_idx = anim_idx
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
44 self.sprite_idx_offset = sprite_idx_offset
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46 #TODO
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47 #if flags & (2|4|8):
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
48 # if flags & 2: #TODO: Huh?!
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
49 # index = 14
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
50 # elif flags & 4:
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
51 # index = 15
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
52 # else:
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
53 # index = 19
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54 # self._sprite = Sprite()
106
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
55 # self._anmrunner = ANMRunner(self._game_state.resource_loader.get_anm_wrapper(('etama3.anm',)), #TODO
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
56 # index, self._sprite, 0) #TODO: offset
c7847bfed427 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
57 # self._anmrunner.run_frame()
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
59 self.flags = flags
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60 self.attributes = list(attributes)
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
61
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
62 self.x, self.y = pos
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
63 self.angle = angle
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64 self.speed = speed
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
66 if flags & 1:
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
67 self.speed_interpolator = Interpolator((speed + 5.,))
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
68 self.speed_interpolator.set_interpolation_start(0, (speed + 5.,))
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
69 self.speed_interpolator.set_interpolation_end(16, (speed,))
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
70 if flags & 448:
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
71 self.speed_interpolator = Interpolator((speed,))
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
72 self.speed_interpolator.set_interpolation_start(0, (speed,))
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
73 self.speed_interpolator.set_interpolation_end(attributes[0] - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set.
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
74
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
75
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
76 def get_player_angle(self):
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
77 return atan2(self.player.y - self.y, self.player.x - self.x)
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
78
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
79
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80 def is_visible(self, screen_width, screen_height):
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81 if self._sprite:
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
82 tx, ty, tw, th = self._sprite.texcoords
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
83 if self._sprite.corner_relative_placement:
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
84 raise Exception #TODO
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85 else:
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
86 tx, ty, tw, th = 0., 0., 0., 0.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88 max_x = tw / 2.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
89 max_y = th / 2.
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
90 min_x = -max_x
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
91 min_y = -max_y
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
92
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
93 if any((min_x > screen_width - self.x,
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
94 max_x < -self.x,
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
95 min_y > screen_height - self.y,
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
96 max_y < -self.y)):
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
97 return False
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
98 return True
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
99
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
100
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
101 def set_anim(self, anim_idx=None, sprite_idx_offset=None):
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
102 if anim_idx is not None:
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
103 self.anim_idx = anim_idx
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
104
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
105 if sprite_idx_offset is not None:
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
106 self.sprite_idx_offset = sprite_idx_offset
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
108 self._sprite = Sprite()
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
109 anm_wrapper = self._game_state.resource_loader.get_anm_wrapper(('etama3.anm',)) #TODO
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
110 self._anmrunner = ANMRunner(anm_wrapper, self.anim_idx,
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
111 self._sprite, self.sprite_idx_offset)
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
112
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
113
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
114 def update(self):
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
115 if not self._sprite or self._sprite._removed:
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
116 self._launched = True
107
5d9052b9a4e8 (almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents: 106
diff changeset
117 self.set_anim()
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
118
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
119 sprite = self._sprite
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
121 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
122 self._anmrunner = None
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
123 if sprite.automatic_orientation and sprite.angle != self.angle:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
124 sprite.angle = self.angle
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 114
diff changeset
125 sprite._changed = True
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127 #TODO: flags
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128 x, y = self.x, self.y
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
129
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
130 if self.flags & 16:
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
131 frame, count = self.attributes[0:2]
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
132 length, angle = self.attributes[4:6]
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
133 angle = self.angle if angle < -900.0 else angle #TODO: is that right?
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
134 dx = cos(self.angle) * self.speed + cos(angle) * length
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
135 dy = sin(self.angle) * self.speed + sin(angle) * length
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
136 self.speed = (dx ** 2 + dy ** 2) ** 0.5
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
137 self.angle = atan2(dy, dx)
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
138 if self.frame == frame: #TODO: include last frame, or not?
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
139 if count > 0:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
140 self.attributes[1] -= 1
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
141 self.frame = 0
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
142 else:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
143 self.flags ^= 16
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
144 elif self.flags & 32:
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
145 #TODO: check
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
146 frame, count = self.attributes[0:2]
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
147 acceleration, angular_speed = self.attributes[4:6]
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
148 self.speed += acceleration
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
149 self.angle += angular_speed
114
92772413b5a6 Fix special bullet function/flags handling
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
150 if self.frame != 0 and self.frame % frame == 0:
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
151 if count > 0:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
152 self.attributes[1] -= 1
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
153 else:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
154 self.flags ^= 32
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
155 elif self.flags & 448:
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
156 #TODO: check
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
157 frame, count = self.attributes[0:2]
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
158 angle, speed = self.attributes[4:6]
114
92772413b5a6 Fix special bullet function/flags handling
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
159 if self.frame != 0 and self.frame % frame == 0:
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
160 count = count - 1
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
161
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
162 if self.flags & 64:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
163 self.angle = self.angle + angle
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
164 elif self.flags & 128:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
165 self.angle = self.get_player_angle() + angle
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
166 elif self.flags & 256:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
167 self.angle = angle
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
168
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
169 if count:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
170 self.speed_interpolator.set_interpolation_start(self.frame, (speed,))
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
171 self.speed_interpolator.set_interpolation_end(self.frame + frame - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set.
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
172 else:
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
173 self.flags &= ~448
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
174 self.speed = speed
88
2cc60137d368 Ugly implementation of three new attack flags.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 86
diff changeset
175
89
1513f5626656 Fix attack flags implementation
Thibaut Girka <thib@sitedethib.com>
parents: 88
diff changeset
176 self.attributes[1] = count
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
177 #TODO: other flags
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
178
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
179 if self.speed_interpolator:
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
180 self.speed_interpolator.update(self.frame)
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
181 self.speed, = self.speed_interpolator.values
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
182
84
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
183 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
184 self.x, self.y = x + dx, y + dy
1a0c78e5a941 Oops O:)
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
185
86
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
186 self.frame += 1
a87a3c080585 Handle a few attack flags
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
187