Mercurial > touhou
annotate pytouhou/game/item.pyx @ 612:73f134f84c7f
Request a RGB888 context, since SDL2’s default of RGB332 sucks.
On X11/GLX, it will select the first config available, that is the best
one, while on EGL it will iterate over them to select the one closest
to what the application requested.
Of course, anything lower than RGB888 looks bad and we really don’t
want that.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Mar 2015 20:20:37 +0100 |
parents | 3c2f96f1d715 |
children | a6af3ff86612 |
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 |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
15 from libc.math cimport cos, sin, atan2, M_PI as pi |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
16 |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
18 cdef class Indicator(Element): |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
19 def __init__(self, Item item): |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
20 Element.__init__(self) |
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
21 |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
22 self._item = item |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
23 self.sprite = item._item_type.indicator_sprite.copy() |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
24 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
25 self.x = self._item.x |
527
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
502
diff
changeset
|
26 self.y = self.sprite._texcoords[3] / 2. |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
27 |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
28 |
468
feecdb4a8928
Add “except *” to cdef void functions, and type some more.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
29 cdef void update(self) nogil: |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
30 #TODO: alpha |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
31 self.x = self._item.x |
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 |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
35 cdef class Item(Element): |
502
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
36 def __init__(self, start_pos, long _type, ItemType item_type, Game game, |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
37 double angle=pi/2, player=None, end_pos=None, |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
38 target=None): |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
39 Element.__init__(self, start_pos) |
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
40 |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
150
diff
changeset
|
41 self._game = game |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
42 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
|
43 self._item_type = item_type |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
44 self.sprite = item_type.sprite |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
45 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
46 self.frame = 0 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
47 self.angle = angle |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
48 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
|
49 |
502
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
50 # The only player allowed to collect that item. If not None, |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
51 # autocollection is disabled too. |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
52 self.player = player |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
53 |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
54 # The player who has autocollected that item. |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
55 # TODO: do we allow stealing in case another player is in the way? |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
56 self.target = target |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
57 |
502
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
58 #TODO: find the formulae in the binary. |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
59 self.speed_interpolator = None |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
60 if end_pos: |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
61 self.pos_interpolator = Interpolator(start_pos, 0, |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
62 end_pos, 60) |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
63 else: |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
64 self.speed_interpolator = Interpolator((-2.,), 0, |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
65 (0.,), 60) |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
66 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
67 self.sprite.angle = angle |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
68 |
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
69 |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
70 property objects: |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
71 def __get__(self): |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
72 if self.indicator is not None: |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
73 return [self.indicator] |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
74 return [self] |
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 |
606
3c2f96f1d715
Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
590
diff
changeset
|
77 cdef void autocollect(self, Player player) except *: |
502
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
78 if self.target is None and self.player is None: |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
79 self.target = player |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
80 self.speed = player.sht.autocollection_speed |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
81 |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
82 |
606
3c2f96f1d715
Fix compilation under Cython 0.22, by making the pyx and the pxd declarations’ except clause similar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
590
diff
changeset
|
83 cdef void on_collect(self, Player player) except *: |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
84 cdef long level, poc |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
85 |
502
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
86 if not (self.player is None or self.player is player): |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
87 return |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
88 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
89 old_power = player.power |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
90 score = 0 |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
91 label = None |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
92 color = 'white' |
343
94fdb6c782c1
Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
327
diff
changeset
|
93 player.play_sound('item00') |
197
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 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
|
96 if old_power < 128: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
97 player.power_bonus = 0 |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
98 score = 10 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
99 player.power += (1 if self._type == 0 else 8) |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
100 if player.power > 128: |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
101 player.power = 128 |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
102 for level in (8, 16, 32, 48, 64, 96): |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
103 if old_power < level and player.power >= level: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
472
diff
changeset
|
104 label = self._game.new_label((self.x, self.y), b':') # Actually a “PowerUp” character. |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
105 color = 'blue' |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
106 label.set_color(color) |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
107 labeled = True |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
108 else: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
109 bonus = player.power_bonus + (1 if self._type == 0 else 8) |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
110 if bonus > 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
111 bonus = 30 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
112 if bonus < 9: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
113 score = (bonus + 1) * 10 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
114 elif bonus < 18: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
115 score = (bonus - 8) * 100 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
116 elif bonus < 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
117 score = (bonus - 17) * 1000 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
118 elif bonus == 30: |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
119 score = 51200 |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
120 color = 'yellow' |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
121 player.power_bonus = bonus |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
122 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
|
123 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
124 elif self._type == 1: # point |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
125 player.points += 1 |
229
5afc75f71fed
Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
220
diff
changeset
|
126 poc = player.sht.point_of_collection |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
127 if player.y < poc: |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
128 score = 100000 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
129 self._game.modify_difficulty(+30) |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
130 color = 'yellow' |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
131 else: |
571
e992927f07a8
Give point items a score even when collected bellow the Point of Collection.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
527
diff
changeset
|
132 score = (728 - int(self.y)) * 100 #TODO: check the formula some more. |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
133 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
|
134 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
135 elif self._type == 3: # bomb |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
136 if player.bombs < 8: |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
137 player.bombs += 1 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
138 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
|
139 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
140 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
|
141 score = 1000 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
142 player.power = 128 |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
143 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
144 elif self._type == 5: # 1up |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
145 if player.lives < 8: |
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
146 player.lives += 1 |
198
13918723d1bc
Modify difficulty when it has to.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
197
diff
changeset
|
147 self._game.modify_difficulty(+200) |
343
94fdb6c782c1
Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
327
diff
changeset
|
148 player.play_sound('extend') |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
149 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
150 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
|
151 score = 500 |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
152 |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
153 if old_power < 128 and player.power == 128: |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
154 #TODO: display “full power”. |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
155 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
|
156 |
264
3ac8b135592c
Homogenise score increase in item collection, in prevision for text handling.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
229
diff
changeset
|
157 if score > 0: |
494
6be9c99a3a24
Merge PlayerState into Player, fix player respawn position.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
473
diff
changeset
|
158 player.score += score |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
159 if label is None: |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
571
diff
changeset
|
160 label = self._game.new_label((self.x, self.y), str(score).encode()) |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
161 if color != 'white': |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
315
diff
changeset
|
162 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
|
163 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
264
diff
changeset
|
164 self.removed = True |
197
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
165 |
e1bc8c4cbb1a
Do the right action when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
156
diff
changeset
|
166 |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
167 cpdef update(self): |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
168 cdef bint offscreen |
384
690b5faaa0e6
Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
343
diff
changeset
|
169 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
170 if self.frame == 60: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
171 self.speed_interpolator = Interpolator((0.,), 60, |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
172 (3.,), 180) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
173 |
502
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
174 if self.target is not None: |
3d3285918ba1
Disallow collection of items dropped by the other player in netplay, also fixes a longstanding bug where autocollection worked with those items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
494
diff
changeset
|
175 self.angle = atan2(self.target.y - self.y, self.target.x - self.x) |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
176 self.x += cos(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
177 self.y += sin(self.angle) * self.speed |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
178 elif self.speed_interpolator is None: |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
179 self.pos_interpolator.update(self.frame) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
180 self.x, self.y = self.pos_interpolator.values |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
181 else: |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
182 self.speed_interpolator.update(self.frame) |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
183 self.speed, = self.speed_interpolator.values |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
184 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
|
185 self.x += dx |
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
186 self.y += dy |
150
4f46717390aa
Introduce items, implement ECL instruction 83
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
187 |
527
db28538cd399
Use Sprite C arrays instead of their tuple representation where it makes sense.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
502
diff
changeset
|
188 offscreen = self.y < -self.sprite._texcoords[3] / 2. |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
189 if offscreen: |
446
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
190 if self.indicator is None: |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
191 self.indicator = Indicator(self) |
3a33ed7f3b85
Make pytouhou.game.item an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
445
diff
changeset
|
192 self.indicator.update() |
315
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
193 else: |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
194 self.indicator = None |
e935ed8dc5e6
Add out-of-screen item indicators.
Thibaut Girka <thib@sitedethib.com>
parents:
306
diff
changeset
|
195 |
153
37df8c618c2e
Add falling items.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
152
diff
changeset
|
196 self.frame += 1 |