comparison pytouhou/game/bullet.pyx @ 440:b9d2db93972f

Add a base Element class for every object in pytouhou.game.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 Aug 2013 14:16:08 +0200
parents 1222341ea22c
children 6b4c3e250bd6
comparison
equal deleted inserted replaced
439:723a3e67a223 440:b9d2db93972f
15 from math import cos, sin, atan2, pi 15 from math import cos, sin, atan2, pi
16 16
17 from pytouhou.utils.interpolator import Interpolator 17 from pytouhou.utils.interpolator import Interpolator
18 from pytouhou.vm.anmrunner import ANMRunner 18 from pytouhou.vm.anmrunner import ANMRunner
19 from pytouhou.game.sprite import Sprite 19 from pytouhou.game.sprite import Sprite
20 from pytouhou.game.element cimport Element
20 21
21 22
22 LAUNCHING, LAUNCHED, CANCELLED = range(3) 23 LAUNCHING, LAUNCHED, CANCELLED = range(3)
23 24
24 cdef class Bullet(object): 25 cdef class Bullet(Element):
25 cdef public unsigned int state, flags, frame, sprite_idx_offset 26 cdef public unsigned int state, flags, frame, sprite_idx_offset
26 cdef public double dx, dy, angle, speed #TODO 27 cdef public double dx, dy, angle, speed #TODO
27 cdef public object player_bullet, target 28 cdef public object player_bullet, target
28 cdef public object _game, _bullet_type 29 cdef public object _game, _bullet_type
29 cdef public object sprite, anmrunner, removed, was_visible, objects 30 cdef public object was_visible
30 cdef public object attributes, damage, hitbox, speed_interpolator, grazed 31 cdef public object attributes, damage, hitbox, speed_interpolator, grazed
31 cdef public object x, y #TODO
32 32
33 def __init__(self, pos, bullet_type, sprite_idx_offset, 33 def __init__(self, pos, bullet_type, sprite_idx_offset,
34 angle, speed, attributes, flags, target, game, 34 angle, speed, attributes, flags, target, game,
35 player_bullet=False, damage=0, hitbox=None): 35 player_bullet=False, damage=0, hitbox=None):
36 Element.__init__(self, pos)
37
36 self._game = game 38 self._game = game
37 self._bullet_type = bullet_type 39 self._bullet_type = bullet_type
38 self.state = LAUNCHING 40 self.state = LAUNCHING
39 self.sprite = None
40 self.anmrunner = None
41 self.removed = False
42 self.was_visible = True 41 self.was_visible = True
43 self.objects = [self]
44 42
45 if hitbox: 43 if hitbox:
46 self.hitbox = (hitbox[0], hitbox[1]) 44 self.hitbox = (hitbox[0], hitbox[1])
47 else: 45 else:
48 self.hitbox = (bullet_type.hitbox_size, bullet_type.hitbox_size) 46 self.hitbox = (bullet_type.hitbox_size, bullet_type.hitbox_size)
56 self.sprite_idx_offset = sprite_idx_offset 54 self.sprite_idx_offset = sprite_idx_offset
57 55
58 self.flags = flags 56 self.flags = flags
59 self.attributes = list(attributes) 57 self.attributes = list(attributes)
60 58
61 self.x, self.y = pos
62 self.angle = angle 59 self.angle = angle
63 self.speed = speed 60 self.speed = speed
64 self.dx, self.dy = cos(angle) * speed, sin(angle) * speed 61 self.dx, self.dy = cos(angle) * speed, sin(angle) * speed
65 62
66 self.player_bullet = player_bullet 63 self.player_bullet = player_bullet