Mercurial > touhou
comparison pytouhou/game/item.pyx @ 502:3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 23 Oct 2013 18:24:08 +0200 |
parents | 6be9c99a3a24 |
children | db28538cd399 |
comparison
equal
deleted
inserted
replaced
501:4778c482f24a | 502:3d3285918ba1 |
---|---|
31 self.x = self._item.x | 31 self.x = self._item.x |
32 | 32 |
33 | 33 |
34 | 34 |
35 cdef class Item(Element): | 35 cdef class Item(Element): |
36 def __init__(self, start_pos, long _type, ItemType item_type, Game game, double angle=pi/2, Player player=None, end_pos=None): | 36 def __init__(self, start_pos, long _type, ItemType item_type, Game game, |
37 double angle=pi/2, player=None, end_pos=None, | |
38 target=None): | |
37 Element.__init__(self, start_pos) | 39 Element.__init__(self, start_pos) |
38 | 40 |
39 self._game = game | 41 self._game = game |
40 self._type = _type | 42 self._type = _type |
41 self._item_type = item_type | 43 self._item_type = item_type |
43 | 45 |
44 self.frame = 0 | 46 self.frame = 0 |
45 self.angle = angle | 47 self.angle = angle |
46 self.indicator = None | 48 self.indicator = None |
47 | 49 |
48 if player is not None: | 50 # The only player allowed to collect that item. If not None, |
49 self.autocollect(player) | 51 # autocollection is disabled too. |
52 self.player = player | |
53 | |
54 # The player who has autocollected that item. | |
55 # TODO: do we allow stealing in case another player is in the way? | |
56 self.target = target | |
57 | |
58 #TODO: find the formulae in the binary. | |
59 self.speed_interpolator = None | |
60 if end_pos: | |
61 self.pos_interpolator = Interpolator(start_pos, 0, | |
62 end_pos, 60) | |
50 else: | 63 else: |
51 self.player = None | 64 self.speed_interpolator = Interpolator((-2.,), 0, |
52 | 65 (0.,), 60) |
53 #TODO: find the formulae in the binary. | |
54 self.speed_interpolator = None | |
55 if end_pos: | |
56 self.pos_interpolator = Interpolator(start_pos, 0, | |
57 end_pos, 60) | |
58 else: | |
59 self.speed_interpolator = Interpolator((-2.,), 0, | |
60 (0.,), 60) | |
61 | 66 |
62 self.sprite.angle = angle | 67 self.sprite.angle = angle |
63 | 68 |
64 | 69 |
65 property objects: | 70 property objects: |
68 return [self.indicator] | 73 return [self.indicator] |
69 return [self] | 74 return [self] |
70 | 75 |
71 | 76 |
72 cdef void autocollect(self, Player player): | 77 cdef void autocollect(self, Player player): |
73 if self.player is None: | 78 if self.target is None and self.player is None: |
74 self.player = player | 79 self.target = player |
75 self.speed = player.sht.autocollection_speed | 80 self.speed = player.sht.autocollection_speed |
76 | 81 |
77 | 82 |
78 cdef void on_collect(self, Player player): | 83 cdef void on_collect(self, Player player): |
79 cdef long level, poc | 84 cdef long level, poc |
85 | |
86 if not (self.player is None or self.player is player): | |
87 return | |
80 | 88 |
81 old_power = player.power | 89 old_power = player.power |
82 score = 0 | 90 score = 0 |
83 label = None | 91 label = None |
84 color = 'white' | 92 color = 'white' |
161 | 169 |
162 if self.frame == 60: | 170 if self.frame == 60: |
163 self.speed_interpolator = Interpolator((0.,), 60, | 171 self.speed_interpolator = Interpolator((0.,), 60, |
164 (3.,), 180) | 172 (3.,), 180) |
165 | 173 |
166 if self.player is not None: | 174 if self.target is not None: |
167 self.angle = atan2(self.player.y - self.y, self.player.x - self.x) | 175 self.angle = atan2(self.target.y - self.y, self.target.x - self.x) |
168 self.x += cos(self.angle) * self.speed | 176 self.x += cos(self.angle) * self.speed |
169 self.y += sin(self.angle) * self.speed | 177 self.y += sin(self.angle) * self.speed |
170 elif self.speed_interpolator is None: | 178 elif self.speed_interpolator is None: |
171 self.pos_interpolator.update(self.frame) | 179 self.pos_interpolator.update(self.frame) |
172 self.x, self.y = self.pos_interpolator.values | 180 self.x, self.y = self.pos_interpolator.values |