Mercurial > nagslang
annotate nagslang/game_object.py @ 647:aeb366d97774
Show splash image on startup
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 08 Sep 2013 02:02:09 +0200 |
parents | db960388b912 |
children | baacd0462d8e |
rev | line source |
---|---|
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
1 import pymunk |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
2 import pymunk.pygame_util |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
3 |
263 | 4 import math |
5 | |
281
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
6 from nagslang import environment |
201
3495a2025bc6
Break puzzlers out of game_object.py
Stefano Rivera <stefano@rivera.za.net>
parents:
196
diff
changeset
|
7 from nagslang import puzzle |
207 | 8 from nagslang import render |
609 | 9 from nagslang.mutators import FLIP_H, ImageOverlay, rotator, scaler |
107 | 10 from nagslang.constants import ( |
318
26d1978fa1da
BOX is no longer accurate
Stefano Rivera <stefano@rivera.za.net>
parents:
313
diff
changeset
|
11 COLLISION_TYPE_DOOR, COLLISION_TYPE_FURNITURE, COLLISION_TYPE_PROJECTILE, |
444 | 12 COLLISION_TYPE_SWITCH, COLLISION_TYPE_SHEEP, COLLISION_TYPE_SHEEP_PEN, |
13 COLLISION_TYPE_WEREWOLF_ATTACK, SWITCH_PUSHERS, ZORDER_FLOOR, ZORDER_LOW, | |
14 ZORDER_HIGH) | |
155
b455873020be
Crates look like crates.
Jeremy Thurgood <firxen@gmail.com>
parents:
145
diff
changeset
|
15 from nagslang.resources import resources |
628 | 16 from nagslang.events import DoorEvent, QuitEvent |
591 | 17 from nagslang.sound import sound |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
18 |
82 | 19 |
385
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
20 class Result(object): |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
21 ''' |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
22 Return from an update() function, to add new objects to the world, and/or |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
23 remove old objects. |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
24 ''' |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
25 def __init__(self, add=(), remove=()): |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
26 self.add = add |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
27 self.remove = remove |
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
28 |
393
8d961e05b7b6
Use Result to handle firing
Stefano Rivera <stefano@rivera.za.net>
parents:
390
diff
changeset
|
29 def merge(self, result): |
8d961e05b7b6
Use Result to handle firing
Stefano Rivera <stefano@rivera.za.net>
parents:
390
diff
changeset
|
30 if result is not None: |
8d961e05b7b6
Use Result to handle firing
Stefano Rivera <stefano@rivera.za.net>
parents:
390
diff
changeset
|
31 self.add += result.add |
8d961e05b7b6
Use Result to handle firing
Stefano Rivera <stefano@rivera.za.net>
parents:
390
diff
changeset
|
32 self.remove += result.remove |
8d961e05b7b6
Use Result to handle firing
Stefano Rivera <stefano@rivera.za.net>
parents:
390
diff
changeset
|
33 return self |
8d961e05b7b6
Use Result to handle firing
Stefano Rivera <stefano@rivera.za.net>
parents:
390
diff
changeset
|
34 |
385
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
35 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
36 def get_editable_game_objects(): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
37 classes = [] |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
38 for cls_name, cls in globals().iteritems(): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
39 if isinstance(cls, type) and hasattr(cls, 'requires'): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
40 classes.append((cls_name, cls)) |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
41 return classes |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
42 |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
43 |
59 | 44 class Physicser(object): |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
45 def __init__(self, space): |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
46 self._space = space |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
47 |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
48 def get_space(self): |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
49 return self._space |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
50 |
276
3153196517fc
Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
51 def set_space(self, new_space): |
3153196517fc
Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
52 self._space = new_space |
3153196517fc
Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
53 |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
54 def set_game_object(self, game_object): |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
55 self.game_object = game_object |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
56 |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
57 def get_shape(self): |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
58 raise NotImplementedError() |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
59 |
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
60 def add_to_space(self): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
61 shape = self.get_shape() |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
62 self.get_space().add(shape) |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
63 if not shape.body.is_static: |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
64 self.get_space().add(shape.body) |
59 | 65 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
66 def remove_from_space(self): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
67 shape = self.get_shape() |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
68 self.get_space().remove(shape) |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
69 if not shape.body.is_static: |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
70 self.get_space().remove(shape.body) |
59 | 71 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
72 def get_render_position(self, surface): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
73 pos = self.get_shape().body.position |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
74 return pymunk.pygame_util.to_pygame(pos, surface) |
63
7f038ee778ad
Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents:
62
diff
changeset
|
75 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
76 def get_angle(self): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
77 return self.get_shape().body.angle |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
78 |
217
d98daba73055
Composition-based renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
216
diff
changeset
|
79 def get_velocity(self): |
d98daba73055
Composition-based renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
216
diff
changeset
|
80 return self.get_shape().body.velocity |
d98daba73055
Composition-based renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
216
diff
changeset
|
81 |
216
f23ab2dd6ce8
Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents:
215
diff
changeset
|
82 def _get_position(self): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
83 return self.get_shape().body.position |
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
84 |
216
f23ab2dd6ce8
Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents:
215
diff
changeset
|
85 def _set_position(self, position): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
86 self.get_shape().body.position = position |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
87 |
216
f23ab2dd6ce8
Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents:
215
diff
changeset
|
88 position = property(_get_position, _set_position) |
f23ab2dd6ce8
Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents:
215
diff
changeset
|
89 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
90 def apply_impulse(self, j, r=(0, 0)): |
215
325c317cbfa1
Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents:
211
diff
changeset
|
91 return self.get_shape().body.apply_impulse(j, r) |
59 | 92 |
93 | |
94 class SingleShapePhysicser(Physicser): | |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
95 def __init__(self, space, shape): |
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
96 super(SingleShapePhysicser, self).__init__(space) |
59 | 97 self._shape = shape |
186
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
98 shape.physicser = self |
59 | 99 |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
100 def get_shape(self): |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
101 return self._shape |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
102 |
59 | 103 |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
104 class MultiShapePhysicser(Physicser): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
105 def __init__(self, space, shape, *extra_shapes): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
106 super(MultiShapePhysicser, self).__init__(space) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
107 self._shape = shape |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
108 self._extra_shapes = extra_shapes |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
109 shape.physicser = self |
610 | 110 for es in extra_shapes: |
111 es.physicser = self | |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
112 |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
113 def get_shape(self): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
114 return self._shape |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
115 |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
116 def add_to_space(self): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
117 shape = self.get_shape() |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
118 self.get_space().add(shape) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
119 if not shape.body.is_static: |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
120 self.get_space().add(shape.body) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
121 for s in self._extra_shapes: |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
122 self.get_space().add(s) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
123 |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
124 def remove_from_space(self): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
125 shape = self.get_shape() |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
126 self.get_space().remove(shape) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
127 if not shape.body.is_static: |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
128 self.get_space().remove(shape.body) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
129 for s in self._extra_shapes: |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
130 self.get_space().remove(s) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
131 |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
132 |
133 | 133 def damping_velocity_func(body, gravity, damping, dt): |
134 """Apply custom damping to this body's velocity. | |
135 """ | |
136 damping = getattr(body, 'damping', damping) | |
137 return pymunk.Body.update_velocity(body, gravity, damping, dt) | |
138 | |
139 | |
140 def make_body(mass, moment, position, damping=None): | |
141 body = pymunk.Body(mass, moment) | |
145
0c49627920eb
Load game objects from level.
Jeremy Thurgood <firxen@gmail.com>
parents:
143
diff
changeset
|
142 body.position = tuple(position) |
133 | 143 if damping is not None: |
144 body.damping = damping | |
145 body.velocity_func = damping_velocity_func | |
146 return body | |
147 | |
148 | |
59 | 149 class GameObject(object): |
150 """A representation of a thing in the game world. | |
151 | |
152 This has a rendery thing, physicsy things and maybe some other things. | |
153 """ | |
154 | |
162
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
155 zorder = ZORDER_LOW |
218
9e2ef2f15035
Better rendering and movement detection.
Jeremy Thurgood <firxen@gmail.com>
parents:
217
diff
changeset
|
156 is_moving = False # `True` if a movement animation should play. |
162
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
157 |
281
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
158 def __init__(self, physicser, renderer, puzzler=None, overlay=None, |
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
159 interactible=None): |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
160 self.lifetime = 0 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
161 self.physicser = physicser |
520 | 162 if physicser is not None: |
163 physicser.set_game_object(self) | |
164 self.physicser.add_to_space() | |
59 | 165 self.renderer = renderer |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
166 renderer.set_game_object(self) |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
167 self.puzzler = puzzler |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
168 if puzzler is not None: |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
169 puzzler.set_game_object(self) |
191 | 170 self.overlay = overlay |
171 if overlay is not None: | |
172 self.overlay.set_game_object(self) | |
281
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
173 self.interactible = interactible |
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
174 if interactible is not None: |
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
175 self.interactible.set_game_object(self) |
371 | 176 self._timers = {} |
177 self._active_timers = {} | |
178 | |
179 def add_timer(self, name, secs): | |
180 self._timers[name] = secs | |
181 | |
182 def start_timer(self, name, secs=None): | |
183 if secs is None: | |
184 secs = self._timers[name] | |
185 self._active_timers[name] = secs | |
186 | |
187 def check_timer(self, name): | |
188 return name in self._active_timers | |
59 | 189 |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
190 def set_stored_state_dict(self, stored_state): |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
191 """Override this to set up whatever state storage you want. |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
192 |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
193 The `stored_state` dict passed in contains whatever saved state we |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
194 might have for this object. If the return value of this method |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
195 evaluates to `True`, the contents of the `stored_state` dict will be |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
196 saved, otherwise it will be discarded. |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
197 """ |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
198 pass |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
199 |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
200 def get_space(self): |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
201 return self.physicser.get_space() |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
202 |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
203 def get_shape(self): |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
204 return self.physicser.get_shape() |
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
205 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
206 def get_render_position(self, surface): |
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
207 return self.physicser.get_render_position(surface) |
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
208 |
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
209 def get_render_angle(self): |
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
210 return self.physicser.get_angle() |
59 | 211 |
229
329b3044ddef
Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
224
diff
changeset
|
212 def get_facing_direction(self): |
329b3044ddef
Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
224
diff
changeset
|
213 """Used by rendererd that care what direction an object is facing. |
329b3044ddef
Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
224
diff
changeset
|
214 """ |
329b3044ddef
Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
224
diff
changeset
|
215 return None |
329b3044ddef
Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents:
224
diff
changeset
|
216 |
59 | 217 def render(self, surface): |
123
23b533d6f27e
Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
107
diff
changeset
|
218 return self.renderer.render(surface) |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
219 |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
220 def update(self, dt): |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
221 self.lifetime += dt |
371 | 222 for timer in self._active_timers.keys(): |
223 self._active_timers[timer] -= dt | |
224 if self._active_timers[timer] <= 0: | |
225 self._active_timers.pop(timer) | |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
226 self.renderer.update(dt) |
143
deac6a4008e7
Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents:
140
diff
changeset
|
227 |
302
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
228 def hit(self, weapon): |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
229 '''Was hit with a weapon (such as a bullet)''' |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
230 pass |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
231 |
256
2a0bad886956
Collision handlers get the protagonist.
Jeremy Thurgood <firxen@gmail.com>
parents:
235
diff
changeset
|
232 def collide_with_protagonist(self, protagonist): |
186
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
233 """Called as a `pre_solve` collision callback with the protagonist. |
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
234 |
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
235 You can return `False` to ignore the collision, anything else |
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
236 (including `None`) to process the collision as normal. |
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
237 """ |
192
3dc2b6290e66
Document collision handler a little better.
Jeremy Thurgood <firxen@gmail.com>
parents:
191
diff
changeset
|
238 return True |
186
d63c19003aec
Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents:
185
diff
changeset
|
239 |
319
01e98732de46
Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents:
318
diff
changeset
|
240 def collide_with_furniture(self, furniture): |
01e98732de46
Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents:
318
diff
changeset
|
241 return True |
01e98732de46
Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents:
318
diff
changeset
|
242 |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
243 def collide_with_claw_attack(self, claw_attack): |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
244 return True |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
245 |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
246 def environmental_movement(self, vec): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
247 self.physicser.apply_impulse(vec) |
416 | 248 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
249 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
250 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
251 """Hints for the level editor""" |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
252 return [("name", "string")] |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
253 |
477 | 254 @classmethod |
255 def movable(cls): | |
256 # Are we movable | |
257 hints = cls.requires() | |
258 for x in hints: | |
259 if 'position' in x: | |
260 return True | |
261 return False | |
262 | |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
263 |
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
264 class FloorSwitch(GameObject): |
162
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
265 zorder = ZORDER_FLOOR |
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
266 |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
267 def __init__(self, space, position): |
145
0c49627920eb
Load game objects from level.
Jeremy Thurgood <firxen@gmail.com>
parents:
143
diff
changeset
|
268 body = make_body(None, None, position) |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
269 self.shape = pymunk.Circle(body, 30) |
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
270 self.shape.collision_type = COLLISION_TYPE_SWITCH |
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
271 self.shape.sensor = True |
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
272 super(FloorSwitch, self).__init__( |
93
d6a49f0c1e6e
Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents:
91
diff
changeset
|
273 SingleShapePhysicser(space, self.shape), |
207 | 274 render.ImageStateRenderer({ |
162
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
275 True: resources.get_image('objects', 'sensor_on.png'), |
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
276 False: resources.get_image('objects', 'sensor_off.png'), |
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
277 }), |
201
3495a2025bc6
Break puzzlers out of game_object.py
Stefano Rivera <stefano@rivera.za.net>
parents:
196
diff
changeset
|
278 puzzle.CollidePuzzler(*SWITCH_PUSHERS), |
81
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
279 ) |
a1b4d09e6f23
Floor switch with horrible hackery.
davidsharpe@lantea.local
parents:
63
diff
changeset
|
280 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
281 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
282 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
283 return [("name", "string"), ("position", "coordinates")] |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
284 |
106
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
285 |
191 | 286 class Note(GameObject): |
287 zorder = ZORDER_FLOOR | |
288 | |
289 def __init__(self, space, position, message): | |
290 body = make_body(None, None, position) | |
291 self.shape = pymunk.Circle(body, 30) | |
292 self.shape.sensor = True | |
293 super(Note, self).__init__( | |
294 SingleShapePhysicser(space, self.shape), | |
207 | 295 render.ImageRenderer(resources.get_image('objects', 'note.png')), |
201
3495a2025bc6
Break puzzlers out of game_object.py
Stefano Rivera <stefano@rivera.za.net>
parents:
196
diff
changeset
|
296 puzzle.CollidePuzzler(), |
222
cc5f2a5ac501
Overlays belong in render
Stefano Rivera <stefano@rivera.za.net>
parents:
218
diff
changeset
|
297 render.TextOverlay(message), |
191 | 298 ) |
299 | |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
300 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
301 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
302 return [("name", "string"), ("position", "coordinates"), |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
303 ("message", "text")] |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
304 |
191 | 305 |
520 | 306 class EphemeralNote(GameObject): |
521
61e3e5d28a05
Sligthly pinker ephemeral notes
Stefano Rivera <stefano@rivera.za.net>
parents:
520
diff
changeset
|
307 def __init__(self, message, timeout, **kwargs): |
61e3e5d28a05
Sligthly pinker ephemeral notes
Stefano Rivera <stefano@rivera.za.net>
parents:
520
diff
changeset
|
308 kwargs.setdefault('bg_colour', (255, 180, 180, 192)) |
520 | 309 super(EphemeralNote, self).__init__( |
310 None, | |
311 render.NullRenderer(), | |
312 puzzle.YesPuzzler(), | |
521
61e3e5d28a05
Sligthly pinker ephemeral notes
Stefano Rivera <stefano@rivera.za.net>
parents:
520
diff
changeset
|
313 render.TextOverlay(message, **kwargs), |
520 | 314 ) |
315 self.add_timer('timeout', timeout) | |
316 self.start_timer('timeout') | |
317 | |
318 def update(self, dt): | |
319 super(EphemeralNote, self).update(dt) | |
320 if not self.check_timer('timeout'): | |
321 return Result(remove=[self]) | |
322 | |
323 | |
647
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
324 class SplashImage(GameObject): |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
325 def __init__(self, image, timeout): |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
326 super(SplashImage, self).__init__( |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
327 None, |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
328 render.NullRenderer(), |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
329 puzzle.YesPuzzler(), |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
330 render.ImageOverlay(image), |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
331 ) |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
332 self.add_timer('timeout', timeout) |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
333 self.start_timer('timeout') |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
334 |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
335 def update(self, dt): |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
336 super(SplashImage, self).update(dt) |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
337 if not self.check_timer('timeout'): |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
338 return Result(remove=[self]) |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
339 |
aeb366d97774
Show splash image on startup
Stefano Rivera <stefano@rivera.za.net>
parents:
628
diff
changeset
|
340 |
106
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
341 class FloorLight(GameObject): |
162
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
342 zorder = ZORDER_FLOOR |
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
343 |
106
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
344 def __init__(self, space, position, state_source): |
145
0c49627920eb
Load game objects from level.
Jeremy Thurgood <firxen@gmail.com>
parents:
143
diff
changeset
|
345 body = make_body(None, None, position) |
106
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
346 self.shape = pymunk.Circle(body, 10) |
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
347 self.shape.collision_type = COLLISION_TYPE_SWITCH |
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
348 self.shape.sensor = True |
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
349 super(FloorLight, self).__init__( |
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
350 SingleShapePhysicser(space, self.shape), |
207 | 351 render.ImageStateRenderer({ |
162
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
352 True: resources.get_image('objects', 'light_on.png'), |
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
353 False: resources.get_image('objects', 'light_off.png'), |
507df17cfbaf
Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents:
160
diff
changeset
|
354 }), |
201
3495a2025bc6
Break puzzlers out of game_object.py
Stefano Rivera <stefano@rivera.za.net>
parents:
196
diff
changeset
|
355 puzzle.StateProxyPuzzler(state_source), |
106
bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents:
104
diff
changeset
|
356 ) |
133 | 357 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
358 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
359 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
360 return [("name", "string"), ("position", "coordinates"), |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
361 ("state_source", "puzzler")] |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
362 |
133 | 363 |
364 class Box(GameObject): | |
365 def __init__(self, space, position): | |
366 body = make_body(10, 10000, position, damping=0.5) | |
367 self.shape = pymunk.Poly( | |
368 body, [(-20, -20), (20, -20), (20, 20), (-20, 20)]) | |
208
3d54fe7a2998
Fun with mass and friction.
Jeremy Thurgood <firxen@gmail.com>
parents:
207
diff
changeset
|
369 self.shape.friction = 0.5 |
318
26d1978fa1da
BOX is no longer accurate
Stefano Rivera <stefano@rivera.za.net>
parents:
313
diff
changeset
|
370 self.shape.collision_type = COLLISION_TYPE_FURNITURE |
133 | 371 super(Box, self).__init__( |
372 SingleShapePhysicser(space, self.shape), | |
207 | 373 render.ImageRenderer(resources.get_image('objects', 'crate.png')), |
133 | 374 ) |
176 | 375 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
376 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
377 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
378 return [("name", "string"), ("position", "coordinates"), |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
379 ("state_source", "puzzler")] |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
380 |
176 | 381 |
560 | 382 class SokoBox(GameObject): |
383 def __init__(self, space, position): | |
614
baff8131cd73
Heavier SokoBoxes are sturdier.
Jeremy Thurgood <firxen@gmail.com>
parents:
612
diff
changeset
|
384 body = make_body(5, pymunk.inf, position, 0.1) |
560 | 385 self.shape = pymunk.Poly( |
386 body, [(-40, -40), (40, -40), (40, 40), (-40, 40)]) | |
584
6d2f6fcd914d
Fuck you cargo bay!!!!!!
David Sharpe <decoydavid@gmail.com>
parents:
563
diff
changeset
|
387 self.shape.friction = 2.0 |
560 | 388 self.shape.collision_type = COLLISION_TYPE_FURNITURE |
563 | 389 super(SokoBox, self).__init__( |
560 | 390 SingleShapePhysicser(space, self.shape), |
391 render.ImageRenderer( | |
392 resources.get_image('objects', 'sokobox.png')), | |
393 ) | |
394 | |
395 @classmethod | |
396 def requires(cls): | |
397 return [("name", "string"), ("position", "coordinates"), | |
398 ("state_source", "puzzler")] | |
399 | |
400 | |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
401 class BaseDoor(GameObject): |
176 | 402 zorder = ZORDER_FLOOR |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
403 is_open = True |
176 | 404 |
263 | 405 def __init__(self, space, position, destination, dest_pos, angle, |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
406 renderer, condition): |
176 | 407 body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5) |
281
9b56e954c674
Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents:
276
diff
changeset
|
408 self.shape = pymunk.Circle(body, 30) |
176 | 409 self.shape.collision_type = COLLISION_TYPE_DOOR |
264 | 410 self.shape.body.angle = float(angle) / 180 * math.pi |
176 | 411 self.shape.sensor = True |
412 self.destination = destination | |
413 self.dest_pos = tuple(dest_pos) | |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
414 super(BaseDoor, self).__init__( |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
415 SingleShapePhysicser(space, self.shape), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
416 renderer, |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
417 puzzle.ParentAttrPuzzler('is_open'), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
418 interactible=environment.Interactible( |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
419 environment.Action(self._post_door_event, condition)), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
420 ) |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
421 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
422 def _post_door_event(self, protagonist): |
569
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
423 self.door_opened() |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
424 DoorEvent.post(self.destination, self.dest_pos) |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
425 |
569
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
426 def door_opened(self): |
591 | 427 sound.play_sound('robotstep2.ogg') |
569
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
428 |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
429 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
430 class Door(BaseDoor): |
628 | 431 |
432 image_name = "door.png" | |
433 | |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
434 def __init__(self, space, position, destination, dest_pos, angle): |
176 | 435 super(Door, self).__init__( |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
436 space, position, destination, dest_pos, angle, |
628 | 437 render.ImageRenderer( |
438 resources.get_image('objects', self.image_name)), | |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
439 environment.YesCondition(), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
440 ) |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
441 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
442 @classmethod |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
443 def requires(cls): |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
444 return [("name", "string"), ("position", "coordinates"), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
445 ("destination", "level name"), ("dest_pos", "coordinate"), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
446 ("angle", "degrees")] |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
447 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
448 |
437
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
449 class RestartGameDoor(Door): |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
450 def _post_door_event(self, protagonist): |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
451 protagonist.world.reset() |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
452 super(RestartGameDoor, self)._post_door_event(protagonist) |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
453 |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
454 |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
455 class ContinueGameDoor(Door): |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
456 def _post_door_event(self, protagonist): |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
457 world = protagonist.world |
510
2cdfbc483d57
Don't put the starting level in the world, it just creates too much pain
Stefano Rivera <stefano@rivera.za.net>
parents:
488
diff
changeset
|
458 if world.level[0]: |
2cdfbc483d57
Don't put the starting level in the world, it just creates too much pain
Stefano Rivera <stefano@rivera.za.net>
parents:
488
diff
changeset
|
459 DoorEvent.post(world.level[0], world.level[1]) |
2cdfbc483d57
Don't put the starting level in the world, it just creates too much pain
Stefano Rivera <stefano@rivera.za.net>
parents:
488
diff
changeset
|
460 else: |
2cdfbc483d57
Don't put the starting level in the world, it just creates too much pain
Stefano Rivera <stefano@rivera.za.net>
parents:
488
diff
changeset
|
461 # New game? |
2cdfbc483d57
Don't put the starting level in the world, it just creates too much pain
Stefano Rivera <stefano@rivera.za.net>
parents:
488
diff
changeset
|
462 super(ContinueGameDoor, self)._post_door_event(protagonist) |
437
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
463 |
d087dfb10896
Replace menu and death screen with the starting level
Stefano Rivera <stefano@rivera.za.net>
parents:
429
diff
changeset
|
464 |
628 | 465 class RocketConsole(Door): |
466 | |
467 image_name = "rocket_console.png" | |
468 | |
469 def _post_door_event(self, protagonist): | |
470 QuitEvent.post() | |
471 | |
472 | |
519 | 473 def make_overlay_image(image_name, angle): |
474 transforms = () | |
475 if angle != 0: | |
476 transforms = (rotator(-angle),) | |
477 return resources.get_image('objects', image_name, transforms=transforms) | |
478 | |
479 | |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
480 class PuzzleDoor(BaseDoor): |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
481 def __init__(self, space, position, destination, dest_pos, angle, |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
482 key_state): |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
483 self._key_state = key_state |
519 | 484 overlay = ImageOverlay(make_overlay_image('lock.png', angle)) |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
485 super(PuzzleDoor, self).__init__( |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
486 space, position, destination, dest_pos, angle, |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
487 render.ImageStateRenderer({ |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
488 True: resources.get_image('objects', 'door.png'), |
390
52c94435e38b
Goodbye foul locked_door!
Jeremy Thurgood <firxen@gmail.com>
parents:
385
diff
changeset
|
489 False: resources.get_image( |
52c94435e38b
Goodbye foul locked_door!
Jeremy Thurgood <firxen@gmail.com>
parents:
385
diff
changeset
|
490 'objects', 'door.png', transforms=(overlay,)), |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
491 }), |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
492 environment.FunctionCondition(lambda p: self.is_open), |
176 | 493 ) |
494 | |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
495 @property |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
496 def is_open(self): |
569
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
497 if self._stored_state['is_open']: |
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
498 return True |
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
499 return self.puzzler.glue.get_state_of(self._key_state) |
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
500 |
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
501 def door_opened(self): |
f735665c359e
Only save state when PuzzleDoor is activated, not on update.
Jeremy Thurgood <firxen@gmail.com>
parents:
567
diff
changeset
|
502 self._stored_state['is_open'] = True |
591 | 503 super(PuzzleDoor, self).door_opened() |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
504 |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
505 def set_stored_state_dict(self, stored_state): |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
506 self._stored_state = stored_state |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
507 self._stored_state.setdefault('is_open', False) |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
508 return True |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
509 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
510 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
511 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
512 return [("name", "string"), ("position", "coordinates"), |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
513 ("destination", "level name"), ("dest_pos", "coordinate"), |
263 | 514 ("angle", "degrees"), |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
515 ("key_state", "puzzler")] |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
516 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
517 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
518 class KeyedDoor(BaseDoor): |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
519 def __init__(self, space, position, destination, dest_pos, angle, |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
520 key_item=None): |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
521 self._key_item = key_item |
364 | 522 overlay = ImageOverlay( |
519 | 523 make_overlay_image('%s.png' % (key_item,), angle)) |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
524 super(KeyedDoor, self).__init__( |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
525 space, position, destination, dest_pos, angle, |
364 | 526 render.ImageRenderer(resources.get_image( |
527 'objects', 'door.png', transforms=(overlay,))), | |
359
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
528 environment.ItemRequiredCondition(key_item), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
529 ) |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
530 |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
531 @classmethod |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
532 def requires(cls): |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
533 return [("name", "string"), ("position", "coordinates"), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
534 ("destination", "level name"), ("dest_pos", "coordinate"), |
d42752ab3231
Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents:
357
diff
changeset
|
535 ("angle", "degrees"), ("key_item", "item name")] |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
536 |
224
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
537 |
558
4abf8cf717e9
Rename "bulkhead" to "hatch".
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
538 class Hatch(GameObject): |
224
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
539 zorder = ZORDER_FLOOR |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
540 |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
541 def __init__(self, space, end1, end2, key_state=None): |
609 | 542 a = pymunk.Vec2d(end1) |
543 b = pymunk.Vec2d(end2) | |
544 offset = b - a | |
545 offset.length /= 2 | |
546 mid = (a + offset).int_tuple | |
547 body = make_body(None, None, mid) | |
548 self.shape = pymunk.Segment( | |
549 body, body.world_to_local(tuple(end1)), | |
550 body.world_to_local(tuple(end2)), 7) | |
224
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
551 self.shape.collision_type = COLLISION_TYPE_DOOR |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
552 if key_state is None: |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
553 puzzler = puzzle.YesPuzzler() |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
554 else: |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
555 puzzler = puzzle.StateProxyPuzzler(key_state) |
558
4abf8cf717e9
Rename "bulkhead" to "hatch".
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
556 super(Hatch, self).__init__( |
224
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
557 SingleShapePhysicser(space, self.shape), |
558
4abf8cf717e9
Rename "bulkhead" to "hatch".
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
558 render.HatchRenderer(), |
224
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
559 puzzler, |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
560 ) |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
561 |
256
2a0bad886956
Collision handlers get the protagonist.
Jeremy Thurgood <firxen@gmail.com>
parents:
235
diff
changeset
|
562 def collide_with_protagonist(self, protagonist): |
224
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
563 if self.puzzler.get_state(): |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
564 # Reject the collision, we can walk through. |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
565 return False |
b6db213e53a2
Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents:
222
diff
changeset
|
566 return True |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
567 |
319
01e98732de46
Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents:
318
diff
changeset
|
568 collide_with_furniture = collide_with_protagonist |
01e98732de46
Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents:
318
diff
changeset
|
569 |
235
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
570 @classmethod |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
571 def requires(cls): |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
572 return [("name", "string"), ("end1", "coordinates"), |
831e4f6b3d18
Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents:
229
diff
changeset
|
573 ("end2", "coordinates"), ("key_state", "puzzler")] |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
574 |
609 | 575 # The level knows that hatches are magical |
576 @classmethod | |
577 def movable(cls): | |
578 return True | |
579 | |
580 | |
581 class KeyedHatch(GameObject): | |
582 zorder = ZORDER_FLOOR | |
583 | |
584 def __init__(self, space, end1, end2, key_item): | |
585 a = pymunk.Vec2d(end1) | |
586 b = pymunk.Vec2d(end2) | |
587 offset = b - a | |
588 offset.length /= 2 | |
589 mid = (a + offset).int_tuple | |
590 body = make_body(None, None, mid) | |
591 self.shape = pymunk.Segment( | |
592 body, body.world_to_local(tuple(end1)), | |
593 body.world_to_local(tuple(end2)), 7) | |
594 self.shape.collision_type = COLLISION_TYPE_DOOR | |
610 | 595 other_shape = pymunk.Circle(body, 30) |
596 other_shape.collision_type = COLLISION_TYPE_DOOR | |
597 other_shape.sensor = True | |
609 | 598 self._key_item = key_item |
599 super(KeyedHatch, self).__init__( | |
610 | 600 MultiShapePhysicser(space, self.shape, other_shape), |
609 | 601 render.KeyedHatchRenderer( |
602 resources.get_image( | |
603 'objects', '%s.png' % (key_item,), | |
604 transforms=(scaler((32, 32)),))), | |
605 puzzle.ParentAttrPuzzler('is_open'), | |
606 ) | |
607 self.add_timer('door_open', 0.1) | |
608 | |
609 @property | |
610 def is_open(self): | |
611 return self.check_timer('door_open') | |
612 | |
613 def collide_with_protagonist(self, protagonist): | |
614 if protagonist.has_item(self._key_item): | |
615 self.start_timer('door_open') | |
616 return False | |
617 return True | |
618 | |
619 @classmethod | |
620 def requires(cls): | |
621 return [("name", "string"), ("end1", "coordinates"), | |
622 ("end2", "coordinates"), ("key_item", "item name")] | |
623 | |
624 # The level knows that hatches are magical | |
570 | 625 @classmethod |
626 def movable(cls): | |
627 return True | |
628 | |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
629 |
282
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
630 class ToggleSwitch(GameObject): |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
631 zorder = ZORDER_LOW |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
632 |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
633 def __init__(self, space, position): |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
634 body = make_body(None, None, position) |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
635 self.shape = pymunk.Circle(body, 20) |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
636 self.shape.sensor = True |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
637 super(ToggleSwitch, self).__init__( |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
638 SingleShapePhysicser(space, self.shape), |
296
eb08426a58fe
Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents:
295
diff
changeset
|
639 render.ImageStateRenderer({ |
eb08426a58fe
Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents:
295
diff
changeset
|
640 True: resources.get_image('objects', 'lever.png'), |
eb08426a58fe
Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents:
295
diff
changeset
|
641 False: resources.get_image( |
eb08426a58fe
Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents:
295
diff
changeset
|
642 'objects', 'lever.png', transforms=(FLIP_H,)), |
eb08426a58fe
Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents:
295
diff
changeset
|
643 }), |
282
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
644 puzzle.ParentAttrPuzzler('toggle_on'), |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
645 interactible=environment.Interactible( |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
646 environment.Action(self._toggle)), |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
647 ) |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
648 |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
649 @property |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
650 def toggle_on(self): |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
651 return self._stored_state['toggle_on'] |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
652 |
282
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
653 def _toggle(self, protagonist): |
346
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
654 self._stored_state['toggle_on'] = not self.toggle_on |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
655 |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
656 def set_stored_state_dict(self, stored_state): |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
657 self._stored_state = stored_state |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
658 # We start in the "off" position. |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
659 self._stored_state.setdefault('toggle_on', False) |
282113d86d75
Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents:
335
diff
changeset
|
660 return True |
282
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
661 |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
662 @classmethod |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
663 def requires(cls): |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
664 return [("name", "string"), ("position", "coordinates")] |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
665 |
9d186b897d82
Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents:
281
diff
changeset
|
666 |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
667 class Bullet(GameObject): |
363
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
362
diff
changeset
|
668 def __init__(self, space, position, impulse, damage, bullet_type, |
612 | 669 source_collision_type, bullet_sound=None): |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
670 body = make_body(1, pymunk.inf, position) |
363
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
362
diff
changeset
|
671 body.angle = impulse.angle |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
672 self.last_position = position |
286
248b8fdb160c
Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents:
282
diff
changeset
|
673 self.shape = pymunk.Circle(body, 2) |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
674 self.shape.sensor = True |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
675 self.shape.collision_type = COLLISION_TYPE_PROJECTILE |
305 | 676 self.damage = damage |
363
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
362
diff
changeset
|
677 self.type = bullet_type |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
678 self.source_collision_type = source_collision_type |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
679 super(Bullet, self).__init__( |
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
680 SingleShapePhysicser(space, self.shape), |
363
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
362
diff
changeset
|
681 render.ImageRenderer(resources.get_image( |
3dd08e18580f
Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents:
362
diff
changeset
|
682 'objects', '%s.png' % self.type)), |
261
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
683 ) |
db7c8e74efb4
(really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents:
256
diff
changeset
|
684 self.physicser.apply_impulse(impulse) |
612 | 685 if bullet_sound is not None: |
686 sound.play_sound(bullet_sound, 0.3) | |
286
248b8fdb160c
Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents:
282
diff
changeset
|
687 |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
688 def update(self, dt): |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
689 super(Bullet, self).update(dt) |
297
b00ed05f7364
Create a tuple of bullet position, so we don't just hold a reference to a mutable object
Stefano Rivera <stefano@rivera.za.net>
parents:
296
diff
changeset
|
690 position = (self.physicser.position.x, self.physicser.position.y) |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
691 r = self.get_space().segment_query(self.last_position, position) |
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
692 self.last_position = position |
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
693 for collision in r: |
302
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
694 shape = collision.shape |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
695 if (shape.collision_type == self.source_collision_type |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
696 or shape == self.physicser.get_shape() |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
697 or shape.sensor): |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
698 continue |
302
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
699 if hasattr(shape, 'physicser'): |
a0a471ad2ee8
Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents:
297
diff
changeset
|
700 shape.physicser.game_object.hit(self) |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
701 self.physicser.remove_from_space() |
385
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
702 return Result(remove=[self]) |
293
47226c661ae2
Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents:
286
diff
changeset
|
703 |
286
248b8fdb160c
Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents:
282
diff
changeset
|
704 |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
705 class ClawAttack(GameObject): |
356 | 706 def __init__(self, space, pos, vector, damage): |
707 body = make_body(1, pymunk.inf, | |
708 (pos[0] + (vector.length * math.cos(vector.angle)), | |
362 | 709 pos[1] + (vector.length * math.sin(vector.angle)))) |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
710 body.angle = vector.angle |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
711 self.shape = pymunk.Circle(body, 30) |
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
712 self.shape.sensor = True |
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
713 self.shape.collision_type = COLLISION_TYPE_WEREWOLF_ATTACK |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
714 self.damage = damage |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
715 super(ClawAttack, self).__init__( |
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
716 SingleShapePhysicser(space, self.shape), |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
717 render.ImageRenderer(resources.get_image( |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
718 'objects', 'werewolf_SW_claw_attack.png', |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
719 transforms=(FLIP_H,))), |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
720 ) |
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
721 |
333
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
722 def update(self, dt): |
3dd32686dbc3
Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
332
diff
changeset
|
723 super(ClawAttack, self).update(dt) |
335
78b805549b4e
More interesting claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents:
333
diff
changeset
|
724 if self.lifetime > 0.1: |
312
72aca01c87ed
Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents:
307
diff
changeset
|
725 self.physicser.remove_from_space() |
385
51deb78cae52
Use a result object to get new drawables back to the area
Stefano Rivera <stefano@rivera.za.net>
parents:
384
diff
changeset
|
726 return Result(remove=[self]) |
351 | 727 |
728 | |
729 class HostileTerrain(GameObject): | |
730 zorder = ZORDER_FLOOR | |
731 damage = None | |
401 | 732 tiles = [] |
362 | 733 tile_alpha = 255 |
401 | 734 tile_frame_ticks = 3 |
351 | 735 # How often to hit the player |
736 rate = 5 | |
737 | |
738 def __init__(self, space, position, outline): | |
739 body = make_body(10, pymunk.inf, position) | |
740 # Adjust shape relative to position | |
741 shape_outline = [(p[0] - position[0], p[1] - position[1]) for | |
742 p in outline] | |
743 self.shape = pymunk.Poly(body, shape_outline) | |
744 self._ticks = 0 | |
745 self.shape.collision_type = COLLISION_TYPE_SWITCH | |
746 self.shape.sensor = True | |
548
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
747 renderer = self._fix_image(outline) |
624
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
748 self._collider = puzzle.CollidePuzzler() |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
749 self._collider.set_game_object(self) |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
750 self._protagonist = None |
548
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
751 super(HostileTerrain, self).__init__( |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
752 SingleShapePhysicser(space, self.shape), |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
753 renderer) |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
754 |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
755 def _fix_image(self, outline): |
401 | 756 if len(self.tiles) > 1: |
757 tile_images = [resources.get_image('tiles', x) | |
758 for x in self.tiles] | |
759 renderer = render.TimedTiledRenderer(outline, tile_images, | |
760 self.tile_frame_ticks, | |
761 self.tile_alpha) | |
762 else: | |
763 tile_image = resources.get_image('tiles', self.tiles[0]) | |
764 renderer = render.TiledRenderer(outline, tile_image, | |
765 self.tile_alpha) | |
548
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
766 return renderer |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
767 |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
768 def update_image(self, new_outline): |
b0c5f032eb9d
Tweak terrain render creation logic
Neil Muller <drnlmuller@gmail.com>
parents:
521
diff
changeset
|
769 self.renderer = self._fix_image(new_outline) |
351 | 770 |
624
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
771 def update(self, seconds): |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
772 if self._collider.get_state(): |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
773 if self._ticks == 0: |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
774 self.apply_effect(self._protagonist) |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
775 self._ticks += 1 |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
776 if self._ticks > self.rate: |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
777 self._ticks = 0 |
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
778 |
351 | 779 def collide_with_protagonist(self, protagonist): |
624
59d375111cc5
collider based moonlight and acid
Neil Muller <drnlmuller@gmail.com>
parents:
614
diff
changeset
|
780 self._protagonist = protagonist |
351 | 781 |
357
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
782 def apply_effect(self, protagonist): |
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
783 protagonist.lose_health(self.damage) |
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
784 |
351 | 785 @classmethod |
786 def requires(cls): | |
787 return [("name", "string"), ("position", "coordinates"), | |
354
55752fc7b753
Add convex requirement to hint
Neil Muller <drnlmuller@gmail.com>
parents:
351
diff
changeset
|
788 ("outline", "polygon (convex)")] |
351 | 789 |
790 | |
791 class AcidFloor(HostileTerrain): | |
792 damage = 1 | |
402
c08d409a1c87
better bubbles (work in progress)
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
401
diff
changeset
|
793 tiles = ['acid.png', 'acid2.png', 'acid3.png'] |
377
4eb7f5dffa59
new acid and moonlight art
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
374
diff
changeset
|
794 tile_alpha = 200 |
402
c08d409a1c87
better bubbles (work in progress)
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
401
diff
changeset
|
795 tile_frame_ticks = 10 |
357
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
796 |
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
797 |
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
798 class ForceWolfFloor(HostileTerrain): |
401 | 799 tiles = ['moonlight.png'] |
357
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
800 rate = 0 |
362 | 801 tile_alpha = 150 |
802 zorder = ZORDER_HIGH | |
357
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
803 |
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
804 def apply_effect(self, protagonist): |
d2c7e17299a7
Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents:
356
diff
changeset
|
805 protagonist.force_wolf_form() |
416 | 806 |
418 | 807 |
416 | 808 class GravityWell(GameObject): |
809 zorder = ZORDER_FLOOR | |
810 # How often to hit the player | |
811 rate = 5 | |
812 | |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
813 def __init__(self, space, position, radius, force): |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
814 body = make_body(None, None, position) |
416 | 815 # Adjust shape relative to position |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
816 self._radius = radius |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
817 self.shape = pymunk.Circle(body, radius) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
818 self.centre = pymunk.Circle(body, 10) |
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
819 self.centre.friction = pymunk.inf |
416 | 820 self._ticks = 0 |
821 self.force = force | |
822 self.shape.collision_type = COLLISION_TYPE_SWITCH | |
823 self.shape.sensor = True | |
824 super(GravityWell, self).__init__( | |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
825 MultiShapePhysicser(space, self.shape, self.centre), |
416 | 826 render.ImageRenderer(resources.get_image( |
827 'objects', 'gravity_well.png')), | |
828 ) | |
829 | |
830 def collide_with_protagonist(self, protagonist): | |
831 # We're called every frame we're colliding, so | |
832 # There are timing issues with stepping on and | |
833 # off terrian, but as long as the rate is reasonably | |
834 # low, they shouldn't impact gameplay | |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
835 self.apply_effect(protagonist) |
416 | 836 |
837 def collide_with_furniture(self, furniture): | |
838 # We're called every frame we're colliding, so | |
839 # There are timing issues with stepping on and | |
840 # off terrian, but as long as the rate is reasonably | |
841 # low, they shouldn't impact gameplay | |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
842 self.apply_effect(furniture) |
416 | 843 |
417 | 844 def apply_effect(self, object_to_move): |
427
3ee839f227ad
Special relativistic gravities.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
418
diff
changeset
|
845 movement = self.physicser.position - object_to_move.physicser.position |
575 | 846 local_force = self.force * math.sqrt( |
847 object_to_move.get_shape().body.mass) | |
429
46ecb2c4cb61
Special relativistic gravities again.
davidsharpe@185.4.16.172.in-addr.arpa
parents:
427
diff
changeset
|
848 movement.length = local_force |
575 | 849 object_to_move.environmental_movement(movement) |
416 | 850 |
851 @classmethod | |
852 def requires(cls): | |
853 return [("name", "string"), ("position", "coordinates"), | |
567
33f28f1cb0eb
Fix gravity well requires.
Simon Cross <hodgestar@gmail.com>
parents:
563
diff
changeset
|
854 ("radius", "int"), ("force", "int")] |
444 | 855 |
856 | |
857 class SheepPen(GameObject): | |
858 zorder = ZORDER_FLOOR | |
859 | |
860 def __init__(self, space, position, outline, sheep_count): | |
861 body = make_body(None, None, position) | |
862 # Adjust shape relative to position | |
863 shape_outline = [(p[0] - position[0], p[1] - position[1]) for | |
864 p in outline] | |
865 self.shape = pymunk.Poly(body, shape_outline) | |
866 self.shape.collision_type = COLLISION_TYPE_SHEEP_PEN | |
867 self.shape.sensor = True | |
868 super(SheepPen, self).__init__( | |
869 SingleShapePhysicser(space, self.shape), | |
870 render.Renderer(), | |
871 puzzle.MultiCollidePuzzler(sheep_count, COLLISION_TYPE_SHEEP), | |
872 ) | |
873 | |
874 @classmethod | |
875 def requires(cls): | |
876 return [("name", "string"), ("position", "coordinates"), | |
877 ("outline", "polygon (convex)"), ("sheep_count", "int")] |