comparison pytouhou/game/item.py @ 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 723a3e67a223
children b0abb05811f7
comparison
equal deleted inserted replaced
439:723a3e67a223 440:b9d2db93972f
13 ## 13 ##
14 14
15 15
16 from math import cos, sin, atan2, pi 16 from math import cos, sin, atan2, pi
17 17
18 from pytouhou.game.element import Element
18 from pytouhou.utils.interpolator import Interpolator 19 from pytouhou.utils.interpolator import Interpolator
19 20
20 21
21 class Indicator(object): 22 class Indicator(Element):
22 def __init__(self, item): 23 def __init__(self, item):
24 Element.__init__(self)
25
23 self._item = item 26 self._item = item
24 27
25 self.sprite = item._item_type.indicator_sprite.copy() 28 self.sprite = item._item_type.indicator_sprite.copy()
26 self.removed = False
27 29
28 self.frame = 0 30 self.frame = 0
29 self.x = self._item.x 31 self.x = self._item.x
30 self.y = self.sprite.texcoords[2] / 2. 32 self.y = self.sprite.texcoords[2] / 2.
31 33
35 self.x = self._item.x 37 self.x = self._item.x
36 self.frame += 1 38 self.frame += 1
37 39
38 40
39 41
40 class Item(object): 42 class Item(Element):
41 def __init__(self, start_pos, _type, item_type, game, angle=pi/2, player=None, end_pos=None): 43 def __init__(self, start_pos, _type, item_type, game, angle=pi/2, player=None, end_pos=None):
44 Element.__init__(self, start_pos)
45
42 self._game = game 46 self._game = game
43 self._type = _type 47 self._type = _type
44 self._item_type = item_type 48 self._item_type = item_type
45 self.sprite = item_type.sprite 49 self.sprite = item_type.sprite
46 self.removed = False
47 50
48 self.frame = 0 51 self.frame = 0
49 self.x, self.y = start_pos
50 self.angle = angle 52 self.angle = angle
51 self.indicator = None 53 self.indicator = None
52 54
53 if player: 55 if player:
54 self.autocollect(player) 56 self.autocollect(player)
153 self.removed = True 155 self.removed = True
154 156
155 157
156 @property 158 @property
157 def objects(self): 159 def objects(self):
158 if self.indicator: 160 if self.indicator is not None:
159 return [self.indicator] 161 return [self.indicator]
160 return [self] 162 return [self]
161 163
162 164
163 def update(self): 165 def update(self):