Mercurial > touhou
annotate pytouhou/game/item.py @ 329:1bb78c469f64
Fix difficulty influence on bullet launch interval, and fix instruction 77's rand usage
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 24 Jun 2012 17:00:07 +0200 |
parents | 13201d90bb22 |
children | 94fdb6c782c1 |
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 |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
17 from copy import copy |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
19 from pytouhou.utils.interpolator import Interpolator |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
20 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
22 class Indicator(object): |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
23 def __init__(self, item): |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
24 self._item = item |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
25 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
26 self.sprite = copy(item._item_type.indicator_sprite) |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
27 self.removed = False |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
28 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
29 self.frame = 0 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
30 self.x = self._item.x |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
31 self.y = self.sprite.texcoords[2] / 2. |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
32 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
33 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
34 def update(self): |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
35 #TODO: alpha |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
36 self.x = self._item.x |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
37 self.frame += 1 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
38 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
39 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
40 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
41 class Item(object): |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
42 def __init__(self, start_pos, _type, item_type, game, angle=pi/2, 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
|
43 self._game = game |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
44 self._type = _type |
306
52d791bb7c32
Rename a few attributes/methods to make a little more sense.
Thibaut Girka <thib@sitedethib.com>
parents:
304
diff
changeset
|
45 self._item_type = item_type |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
46 self.sprite = item_type.sprite |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
47 self.removed = False |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
48 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
49 self.frame = 0 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
50 self.x, self.y = start_pos |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 self.angle = angle |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
52 self.indicator = None |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
53 |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
54 if player: |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
55 self.autocollect(player) |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
56 else: |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
57 self.player = None |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
58 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
59 if not player: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
60 #TODO: find the formulae in the binary. |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
61 self.speed_interpolator = None |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
62 if end_pos: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
63 self.pos_interpolator = Interpolator(start_pos, 0, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
64 end_pos, 60) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
65 else: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
66 self.speed_interpolator = Interpolator((-2.,), 0, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
67 (0.,), 60) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
68 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
69 self.sprite.angle = angle |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
70 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
71 |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
72 def autocollect(self, player): |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
73 self.player = player |
229
5afc75f71fed
Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
220
diff
changeset
|
74 self.speed = player.sht.autocollection_speed |
208
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
75 |
d07506a2e16e
Implement autocollection of items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
198
diff
changeset
|
76 |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
77 def on_collect(self, player): |
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
78 player_state = player.state |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
79 old_power = player_state.power |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
80 score = 0 |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
81 label = None |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
82 color = 'white' |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
83 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
84 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
|
85 if old_power < 128: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
86 player_state.power_bonus = 0 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
87 score = 10 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
88 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
|
89 if player_state.power > 128: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
90 player_state.power = 128 |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
91 for level in (8, 16, 32, 48, 64, 96): |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
92 if old_power < level and player_state.power >= level: |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
93 label = self._game.new_label((self.x, self.y), ':') # Actually a “PowerUp” character. |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
94 color = 'blue' |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
95 label.set_color(color) |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
96 labeled = True |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
97 else: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
98 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
|
99 if bonus > 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
100 bonus = 30 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
101 if bonus < 9: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
102 score = (bonus + 1) * 10 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
103 elif bonus < 18: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
104 score = (bonus - 8) * 100 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
105 elif bonus < 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
106 score = (bonus - 17) * 1000 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
107 elif bonus == 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
108 score = 51200 |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
109 color = 'yellow' |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
110 player_state.power_bonus = bonus |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
111 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
|
112 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
113 elif self._type == 1: # point |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
114 player_state.points += 1 |
229
5afc75f71fed
Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
220
diff
changeset
|
115 poc = player.sht.point_of_collection |
220
0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
208
diff
changeset
|
116 if player_state.y < poc: |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
117 score = 100000 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
118 self._game.modify_difficulty(+30) |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
119 color = 'yellow' |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
120 else: |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
121 #score = #TODO: find the formula. |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
122 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
|
123 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
124 elif self._type == 3: # bomb |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
125 if player_state.bombs < 8: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
126 player_state.bombs += 1 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
127 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
|
128 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
129 elif self._type == 4: # full power |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
130 score = 1000 |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
131 player_state.power = 128 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
132 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
133 elif self._type == 5: # 1up |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
134 if player_state.lives < 8: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
135 player_state.lives += 1 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
136 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
|
137 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
138 elif self._type == 6: # star |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
139 score = 500 |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
140 |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
141 if old_power < 128 and player_state.power == 128: |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
142 #TODO: display “full power”. |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
143 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
|
144 |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
145 if score > 0: |
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
146 player_state.score += score |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
147 if not label: |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
148 label = self._game.new_label((self.x, self.y), str(score)) |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
149 if color != 'white': |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
150 label.set_color(color) |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
151 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
152 self.removed = True |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
153 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
154 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 def update(self): |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
156 if self.frame == 60: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
157 self.speed_interpolator = Interpolator((0.,), 60, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
158 (3.,), 180) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
159 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
160 if self.player is not None: |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
161 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
|
162 self.x += cos(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
163 self.y += sin(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
164 elif self.speed_interpolator is None: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
165 self.pos_interpolator.update(self.frame) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
166 self.x, self.y = self.pos_interpolator.values |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
167 else: |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
168 self.speed_interpolator.update(self.frame) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
169 self.speed, = self.speed_interpolator.values |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
170 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
|
171 self.x += dx |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
172 self.y += dy |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
173 |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
174 offscreen = self.y < -(self.sprite.texcoords[2] / 2.) |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
175 if offscreen: |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
176 self.indicator = self.indicator or Indicator(self) |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
177 else: |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
178 self.indicator = None |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
179 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
180 if self.indicator: |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
181 self.indicator.update() |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
182 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
183 self.frame += 1 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
184 |