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