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