Mercurial > touhou
annotate pytouhou/game/item.py @ 218:9634eefd2063
Minor changes to the setup script
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 05 Dec 2011 23:57:58 +0100 |
parents | d07506a2e16e |
children | 0595315d3880 |
rev | line source |
---|---|
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
16 from math import cos, sin, atan2, pi |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
18 from pytouhou.utils.interpolator import Interpolator |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
19 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 class Item(object): |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
22 def __init__(self, start_pos, _type, item_type, game, angle=pi/2, speed=8., player=None, end_pos=None): |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
23 self._game = game |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
24 self._sprite = item_type.sprite |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
25 self._removed = False |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
26 self._type = _type |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
27 self._item_type = item_type |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
28 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
29 self.hitbox_half_size = item_type.hitbox_size / 2. |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
30 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
31 self.frame = 0 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
32 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
33 self.player = player |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
35 self.x, self.y = start_pos |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
36 self.angle = angle |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
37 self.speed = speed |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
38 dx, dy = cos(angle) * speed, sin(angle) * speed |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
39 self.delta = dx, dy |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
40 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
41 if not player: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
42 #TODO: find the formulae in the binary. |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
43 self.speed_interpolator = None |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
44 if end_pos: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
45 self.pos_interpolator = Interpolator(start_pos, 0, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
46 end_pos, 60) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
47 else: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
48 self.speed_interpolator = Interpolator((-2.,), 0, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
49 (0.,), 60) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
50 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 self._sprite.angle = angle |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
52 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
53 |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
54 def autocollect(self, player): |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
55 self.player = player |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
56 self.speed = 8. |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
57 |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
58 |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
59 def on_collect(self, player_state): |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
60 old_power = player_state.power |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
61 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
62 if self._type == 0 or self._type == 2: # power or big power |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
63 if old_power < 128: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
64 player_state.power_bonus = 0 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
65 score = 10 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
66 player_state.power += (1 if self._type == 0 else 8) |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
67 if player_state.power > 128: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
68 player_state.power = 128 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
69 else: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
70 bonus = player_state.power_bonus + (1 if self._type == 0 else 8) |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
71 if bonus > 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
72 bonus = 30 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
73 if bonus < 9: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
74 score = (bonus + 1) * 10 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
75 elif bonus < 18: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
76 score = (bonus - 8) * 100 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
77 elif bonus < 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
78 score = (bonus - 17) * 1000 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
79 elif bonus == 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
80 score = 51200 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
81 player_state.power_bonus = bonus |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
82 player_state.score += score |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
83 self._game.modify_difficulty(+1) |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
84 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
85 elif self._type == 1: # point |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
86 player_state.points += 1 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
87 if player_state.y < 128: #TODO: find the exact poc. |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
88 score = 100000 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
89 self._game.modify_difficulty(+30) |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
90 else: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
91 score = 0 #TODO: find the formula. |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
92 self._game.modify_difficulty(+3) |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
93 player_state.score += score |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
94 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
95 elif self._type == 3: # bomb |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
96 if player_state.bombs < 8: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
97 player_state.bombs += 1 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
98 self._game.modify_difficulty(+5) |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
99 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
100 elif self._type == 4: # full power |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
101 player_state.score += 1000 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
102 player_state.power = 128 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
103 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
104 elif self._type == 5: # 1up |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
105 if player_state.lives < 8: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
106 player_state.lives += 1 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
107 self._game.modify_difficulty(+200) |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
108 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
109 elif self._type == 6: # star |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
110 player_state.score += 500 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
111 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
112 if old_power < 128 and player_state.power >= 128: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
113 #TODO: display “full power”. |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
114 self._game.change_bullets_into_star_items() |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
115 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
116 self._removed = True |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
117 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
118 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
119 def update(self): |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
120 dx, dy = self.delta |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
121 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
122 if self.frame == 60: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
123 self.speed_interpolator = Interpolator((0.,), 60, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
124 (3.,), 180) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
125 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
126 if self.player is not None: |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
127 self.angle = atan2(self.player.y - self.y, self.player.x - self.x) |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
128 self.x += cos(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
129 self.y += sin(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
130 elif self.speed_interpolator is None: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
131 self.pos_interpolator.update(self.frame) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
132 self.x, self.y = self.pos_interpolator.values |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
133 else: |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
134 self.speed_interpolator.update(self.frame) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
135 self.speed, = self.speed_interpolator.values |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
136 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
137 self.delta = dx, dy |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
138 self.x += dx |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
139 self.y += dy |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
140 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
141 self.frame += 1 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 |