annotate nagslang/game_object.py @ 377:4eb7f5dffa59

new acid and moonlight art
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Fri, 06 Sep 2013 23:03:28 +0200
parents 150332d6c1fb
children 8069c9be1c3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
6c554ce627e3 Add angle to doors
Neil Muller <drnlmuller@gmail.com>
parents: 261
diff changeset
4 import math
6c554ce627e3 Add angle to doors
Neil Muller <drnlmuller@gmail.com>
parents: 261
diff changeset
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
42e8993c31fd Break out Renderers
Stefano Rivera <stefano@rivera.za.net>
parents: 203
diff changeset
8 from nagslang import render
364
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
9 from nagslang.mutators import FLIP_H, ImageOverlay
107
b90d01e4d9d4 Layered drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 106
diff changeset
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,
26d1978fa1da BOX is no longer accurate
Stefano Rivera <stefano@rivera.za.net>
parents: 313
diff changeset
12 COLLISION_TYPE_SWITCH, COLLISION_TYPE_WEREWOLF_ATTACK,
362
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
13 SWITCH_PUSHERS, ZORDER_FLOOR, ZORDER_LOW, ZORDER_HIGH)
155
b455873020be Crates look like crates.
Jeremy Thurgood <firxen@gmail.com>
parents: 145
diff changeset
14 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
15 from nagslang.events import DoorEvent
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
16
82
11b0017b5e4b Fix whitespace.
davidsharpe@185.4.16.172.in-addr.arpa
parents: 81
diff changeset
17
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
18 def get_editable_game_objects():
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
19 classes = []
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
20 for cls_name, cls in globals().iteritems():
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
21 if isinstance(cls, type) and hasattr(cls, 'requires'):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
22 classes.append((cls_name, cls))
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
23 return classes
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
24
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
25
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
26 class Physicser(object):
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
27 def __init__(self, space):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
28 self._space = space
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
29
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
30 def get_space(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
31 return self._space
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
32
276
3153196517fc Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents: 264
diff changeset
33 def set_space(self, new_space):
3153196517fc Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents: 264
diff changeset
34 self._space = new_space
3153196517fc Move protagonist to the world
Neil Muller <drnlmuller@gmail.com>
parents: 264
diff changeset
35
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
36 def set_game_object(self, game_object):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
37 self.game_object = game_object
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
38
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
39 def get_shape(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
40 raise NotImplementedError()
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
41
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
42 def add_to_space(self):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
43 shape = self.get_shape()
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
44 self.get_space().add(shape)
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
45 if not shape.body.is_static:
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
46 self.get_space().add(shape.body)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
47
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
48 def remove_from_space(self):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
49 shape = self.get_shape()
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
50 self.get_space().remove(shape)
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
51 if not shape.body.is_static:
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
52 self.get_space().remove(shape.body)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
53
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
54 def get_render_position(self, surface):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
55 pos = self.get_shape().body.position
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
56 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
57
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
58 def get_angle(self):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
59 return self.get_shape().body.angle
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
60
217
d98daba73055 Composition-based renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 216
diff changeset
61 def get_velocity(self):
d98daba73055 Composition-based renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 216
diff changeset
62 return self.get_shape().body.velocity
d98daba73055 Composition-based renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 216
diff changeset
63
216
f23ab2dd6ce8 Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents: 215
diff changeset
64 def _get_position(self):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
65 return self.get_shape().body.position
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
66
216
f23ab2dd6ce8 Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents: 215
diff changeset
67 def _set_position(self, position):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
68 self.get_shape().body.position = position
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
69
216
f23ab2dd6ce8 Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents: 215
diff changeset
70 position = property(_get_position, _set_position)
f23ab2dd6ce8 Clunkier properties to make pyflakes happy.
Jeremy Thurgood <firxen@gmail.com>
parents: 215
diff changeset
71
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
72 def apply_impulse(self, j, r=(0, 0)):
215
325c317cbfa1 Better protagonist physicser.
Jeremy Thurgood <firxen@gmail.com>
parents: 211
diff changeset
73 return self.get_shape().body.apply_impulse(j, r)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
74
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
75
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
76 class SingleShapePhysicser(Physicser):
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
77 def __init__(self, space, shape):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
78 super(SingleShapePhysicser, self).__init__(space)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
79 self._shape = shape
186
d63c19003aec Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 185
diff changeset
80 shape.physicser = self
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
81
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
82 def get_shape(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
83 return self._shape
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
84
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
85
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
86 def damping_velocity_func(body, gravity, damping, dt):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
87 """Apply custom damping to this body's velocity.
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
88 """
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
89 damping = getattr(body, 'damping', damping)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
90 return pymunk.Body.update_velocity(body, gravity, damping, dt)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
91
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
92
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
93 def make_body(mass, moment, position, damping=None):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
94 body = pymunk.Body(mass, moment)
145
0c49627920eb Load game objects from level.
Jeremy Thurgood <firxen@gmail.com>
parents: 143
diff changeset
95 body.position = tuple(position)
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
96 if damping is not None:
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
97 body.damping = damping
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
98 body.velocity_func = damping_velocity_func
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
99 return body
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
100
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
101
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
102 class GameObject(object):
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
103 """A representation of a thing in the game world.
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
104
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
105 This has a rendery thing, physicsy things and maybe some other things.
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
106 """
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
107
162
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
108 zorder = ZORDER_LOW
218
9e2ef2f15035 Better rendering and movement detection.
Jeremy Thurgood <firxen@gmail.com>
parents: 217
diff changeset
109 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
110
281
9b56e954c674 Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 276
diff changeset
111 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
112 interactible=None):
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
113 self.lifetime = 0
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
114 self.physicser = physicser
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
115 physicser.set_game_object(self)
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
116 self.physicser.add_to_space()
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
117 self.renderer = renderer
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
118 renderer.set_game_object(self)
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
119 self.puzzler = puzzler
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
120 if puzzler is not None:
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
121 puzzler.set_game_object(self)
191
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
122 self.overlay = overlay
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
123 if overlay is not None:
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
124 self.overlay.set_game_object(self)
281
9b56e954c674 Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 276
diff changeset
125 self.interactible = interactible
9b56e954c674 Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 276
diff changeset
126 if interactible is not None:
9b56e954c674 Protagonist actions, now required for operating doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 276
diff changeset
127 self.interactible.set_game_object(self)
293
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
128 self.remove = False # If true, will be removed from drawables
371
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
129 self._timers = {}
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
130 self._active_timers = {}
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
131
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
132 def add_timer(self, name, secs):
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
133 self._timers[name] = secs
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
134
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
135 def start_timer(self, name, secs=None):
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
136 if secs is None:
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
137 secs = self._timers[name]
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
138 self._active_timers[name] = secs
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
139
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
140 def check_timer(self, name):
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
141 return name in self._active_timers
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
142
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
143 def set_stored_state_dict(self, stored_state):
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
144 """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
145
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
146 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
147 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
148 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
149 saved, otherwise it will be discarded.
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
150 """
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
151 pass
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
152
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
153 def get_space(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
154 return self.physicser.get_space()
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
155
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
156 def get_shape(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
157 return self.physicser.get_shape()
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
158
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
159 def get_render_position(self, surface):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
160 return self.physicser.get_render_position(surface)
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
161
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
162 def get_render_angle(self):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
163 return self.physicser.get_angle()
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
164
229
329b3044ddef Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 224
diff changeset
165 def get_facing_direction(self):
329b3044ddef Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 224
diff changeset
166 """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
167 """
329b3044ddef Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 224
diff changeset
168 return None
329b3044ddef Much better facing renderers.
Jeremy Thurgood <firxen@gmail.com>
parents: 224
diff changeset
169
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
170 def render(self, surface):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
171 return self.renderer.render(surface)
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
172
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
173 def update(self, dt):
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
174 self.lifetime += dt
371
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
175 for timer in self._active_timers.keys():
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
176 self._active_timers[timer] -= dt
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
177 if self._active_timers[timer] <= 0:
21c1c329f8e3 Automatic weapons.
Jeremy Thurgood <firxen@gmail.com>
parents: 370
diff changeset
178 self._active_timers.pop(timer)
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
179 self.renderer.update(dt)
143
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
180
302
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
181 def hit(self, weapon):
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
182 '''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
183 pass
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
184
256
2a0bad886956 Collision handlers get the protagonist.
Jeremy Thurgood <firxen@gmail.com>
parents: 235
diff changeset
185 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
186 """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
187
d63c19003aec Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 185
diff changeset
188 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
189 (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
190 """
192
3dc2b6290e66 Document collision handler a little better.
Jeremy Thurgood <firxen@gmail.com>
parents: 191
diff changeset
191 return True
186
d63c19003aec Some refactoring and fixing, start of better collision handling.
Jeremy Thurgood <firxen@gmail.com>
parents: 185
diff changeset
192
319
01e98732de46 Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents: 318
diff changeset
193 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
194 return True
01e98732de46 Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents: 318
diff changeset
195
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
196 def collide_with_claw_attack(self, claw_attack):
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
197 return True
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
198
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
199 @classmethod
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
200 def requires(cls):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
201 """Hints for the level editor"""
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
202 return [("name", "string")]
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
203
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
204
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
205 class FloorSwitch(GameObject):
162
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
206 zorder = ZORDER_FLOOR
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
207
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
208 def __init__(self, space, position):
145
0c49627920eb Load game objects from level.
Jeremy Thurgood <firxen@gmail.com>
parents: 143
diff changeset
209 body = make_body(None, None, position)
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
210 self.shape = pymunk.Circle(body, 30)
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
211 self.shape.collision_type = COLLISION_TYPE_SWITCH
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
212 self.shape.sensor = True
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
213 super(FloorSwitch, self).__init__(
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
214 SingleShapePhysicser(space, self.shape),
207
42e8993c31fd Break out Renderers
Stefano Rivera <stefano@rivera.za.net>
parents: 203
diff changeset
215 render.ImageStateRenderer({
162
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
216 True: resources.get_image('objects', 'sensor_on.png'),
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
217 False: resources.get_image('objects', 'sensor_off.png'),
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
218 }),
201
3495a2025bc6 Break puzzlers out of game_object.py
Stefano Rivera <stefano@rivera.za.net>
parents: 196
diff changeset
219 puzzle.CollidePuzzler(*SWITCH_PUSHERS),
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
220 )
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
221
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
222 @classmethod
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
223 def requires(cls):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
224 return [("name", "string"), ("position", "coordinates")]
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
225
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
226
191
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
227 class Note(GameObject):
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
228 zorder = ZORDER_FLOOR
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
229
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
230 def __init__(self, space, position, message):
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
231 body = make_body(None, None, position)
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
232 self.shape = pymunk.Circle(body, 30)
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
233 self.shape.sensor = True
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
234 super(Note, self).__init__(
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
235 SingleShapePhysicser(space, self.shape),
207
42e8993c31fd Break out Renderers
Stefano Rivera <stefano@rivera.za.net>
parents: 203
diff changeset
236 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
237 puzzle.CollidePuzzler(),
222
cc5f2a5ac501 Overlays belong in render
Stefano Rivera <stefano@rivera.za.net>
parents: 218
diff changeset
238 render.TextOverlay(message),
191
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
239 )
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
240
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
241 @classmethod
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
242 def requires(cls):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
243 return [("name", "string"), ("position", "coordinates"),
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
244 ("message", "text")]
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
245
191
e080fcd07fa9 Overlay notes
Stefano Rivera <stefano@rivera.za.net>
parents: 188
diff changeset
246
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
247 class FloorLight(GameObject):
162
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
248 zorder = ZORDER_FLOOR
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
249
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
250 def __init__(self, space, position, state_source):
145
0c49627920eb Load game objects from level.
Jeremy Thurgood <firxen@gmail.com>
parents: 143
diff changeset
251 body = make_body(None, None, position)
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
252 self.shape = pymunk.Circle(body, 10)
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
253 self.shape.collision_type = COLLISION_TYPE_SWITCH
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
254 self.shape.sensor = True
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
255 super(FloorLight, self).__init__(
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
256 SingleShapePhysicser(space, self.shape),
207
42e8993c31fd Break out Renderers
Stefano Rivera <stefano@rivera.za.net>
parents: 203
diff changeset
257 render.ImageStateRenderer({
162
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
258 True: resources.get_image('objects', 'light_on.png'),
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
259 False: resources.get_image('objects', 'light_off.png'),
507df17cfbaf Pictures for lights and switches.
Jeremy Thurgood <firxen@gmail.com>
parents: 160
diff changeset
260 }),
201
3495a2025bc6 Break puzzlers out of game_object.py
Stefano Rivera <stefano@rivera.za.net>
parents: 196
diff changeset
261 puzzle.StateProxyPuzzler(state_source),
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
262 )
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
263
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
264 @classmethod
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
265 def requires(cls):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
266 return [("name", "string"), ("position", "coordinates"),
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
267 ("state_source", "puzzler")]
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
268
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
269
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
270 class Box(GameObject):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
271 def __init__(self, space, position):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
272 body = make_body(10, 10000, position, damping=0.5)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
273 self.shape = pymunk.Poly(
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
274 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
275 self.shape.friction = 0.5
318
26d1978fa1da BOX is no longer accurate
Stefano Rivera <stefano@rivera.za.net>
parents: 313
diff changeset
276 self.shape.collision_type = COLLISION_TYPE_FURNITURE
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
277 super(Box, self).__init__(
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
278 SingleShapePhysicser(space, self.shape),
207
42e8993c31fd Break out Renderers
Stefano Rivera <stefano@rivera.za.net>
parents: 203
diff changeset
279 render.ImageRenderer(resources.get_image('objects', 'crate.png')),
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
280 )
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
281
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
282 @classmethod
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
283 def requires(cls):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
284 return [("name", "string"), ("position", "coordinates"),
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
285 ("state_source", "puzzler")]
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
286
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
287
359
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
288 class BaseDoor(GameObject):
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
289 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
290 is_open = True
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
291
263
6c554ce627e3 Add angle to doors
Neil Muller <drnlmuller@gmail.com>
parents: 261
diff changeset
292 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
293 renderer, condition):
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
294 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
295 self.shape = pymunk.Circle(body, 30)
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
296 self.shape.collision_type = COLLISION_TYPE_DOOR
264
Neil Muller <drnlmuller@gmail.com>
parents: 263
diff changeset
297 self.shape.body.angle = float(angle) / 180 * math.pi
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
298 self.shape.sensor = True
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
299 self.destination = destination
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
300 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
301 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
302 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
303 renderer,
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
304 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
305 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
306 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
307 )
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
308
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
309 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
310 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
311
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
312
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
313 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
314 def __init__(self, space, position, destination, dest_pos, angle):
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
315 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
316 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
317 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
318 environment.YesCondition(),
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
319 )
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
320
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
321 @classmethod
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
322 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
323 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
324 ("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
325 ("angle", "degrees")]
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
326
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
327
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
328 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
329 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
330 key_state):
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
331 self._key_state = key_state
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
332 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
333 space, position, destination, dest_pos, angle,
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
334 render.ImageStateRenderer({
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
335 True: resources.get_image('objects', 'door.png'),
359
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
336 False: resources.get_image('objects', 'locked_door.png'),
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
337 }),
359
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
338 environment.FunctionCondition(lambda p: self.is_open),
176
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
339 )
054944c6472b Initial door object
Neil Muller <drnlmuller@gmail.com>
parents: 162
diff changeset
340
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
341 @property
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
342 def is_open(self):
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
343 return self._stored_state['is_open']
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
344
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
345 def set_stored_state_dict(self, stored_state):
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
346 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
347 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
348 return True
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
349
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
350 def update(self, dt):
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
351 if not self.is_open:
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
352 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
353 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
354 super(PuzzleDoor, self).update(dt)
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
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 ("destination", "level name"), ("dest_pos", "coordinate"),
263
6c554ce627e3 Add angle to doors
Neil Muller <drnlmuller@gmail.com>
parents: 261
diff changeset
360 ("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
361 ("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
362
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
363
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
364 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
365 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
366 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
367 self._key_item = key_item
364
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
368 overlay = ImageOverlay(
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
369 resources.get_image('objects', '%s.png' % (key_item,)))
359
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
370 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
371 space, position, destination, dest_pos, angle,
364
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
372 render.ImageRenderer(resources.get_image(
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
373 '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
374 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
375 )
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
376
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
377 @classmethod
d42752ab3231 Refactor doors and add horrible temporoary image for someone to fix later.
Jeremy Thurgood <firxen@gmail.com>
parents: 357
diff changeset
378 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
379 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
380 ("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
381 ("angle", "degrees"), ("key_item", "item name")]
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
382
224
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
383
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
384 class Bulkhead(GameObject):
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
385 zorder = ZORDER_FLOOR
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
386
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
387 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
388 body = make_body(None, None, (0, 0))
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
389 self.shape = pymunk.Segment(body, tuple(end1), tuple(end2), 3)
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
390 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
391 if key_state is None:
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
392 puzzler = puzzle.YesPuzzler()
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
393 else:
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
394 puzzler = puzzle.StateProxyPuzzler(key_state)
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
395 super(Bulkhead, self).__init__(
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
396 SingleShapePhysicser(space, self.shape),
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
397 render.ShapeStateRenderer(),
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
398 puzzler,
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
399 )
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
400
256
2a0bad886956 Collision handlers get the protagonist.
Jeremy Thurgood <firxen@gmail.com>
parents: 235
diff changeset
401 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
402 if self.puzzler.get_state():
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
403 # 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
404 return False
b6db213e53a2 Bulkheads are bits of wall you can walk through.
Jeremy Thurgood <firxen@gmail.com>
parents: 222
diff changeset
405 return True
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
406
319
01e98732de46 Open bulkheads are no longer opaque to furniture
Stefano Rivera <stefano@rivera.za.net>
parents: 318
diff changeset
407 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
408
235
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
409 @classmethod
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
410 def requires(cls):
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
411 return [("name", "string"), ("end1", "coordinates"),
831e4f6b3d18 Add hints for the level editor
Neil Muller <drnlmuller@gmail.com>
parents: 229
diff changeset
412 ("end2", "coordinates"), ("key_state", "puzzler")]
261
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
413
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
414
282
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
415 class ToggleSwitch(GameObject):
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
416 zorder = ZORDER_LOW
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
417
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
418 def __init__(self, space, position):
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
419 body = make_body(None, None, position)
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
420 self.shape = pymunk.Circle(body, 20)
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
421 self.shape.sensor = True
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
422 super(ToggleSwitch, self).__init__(
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
423 SingleShapePhysicser(space, self.shape),
296
eb08426a58fe Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents: 295
diff changeset
424 render.ImageStateRenderer({
eb08426a58fe Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents: 295
diff changeset
425 True: resources.get_image('objects', 'lever.png'),
eb08426a58fe Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents: 295
diff changeset
426 False: resources.get_image(
eb08426a58fe Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents: 295
diff changeset
427 'objects', 'lever.png', transforms=(FLIP_H,)),
eb08426a58fe Levers look like levers.
Jeremy Thurgood <firxen@gmail.com>
parents: 295
diff changeset
428 }),
282
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
429 puzzle.ParentAttrPuzzler('toggle_on'),
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
430 interactible=environment.Interactible(
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
431 environment.Action(self._toggle)),
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
432 )
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
433
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
434 @property
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
435 def toggle_on(self):
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
436 return self._stored_state['toggle_on']
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
437
282
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
438 def _toggle(self, protagonist):
346
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
439 self._stored_state['toggle_on'] = not self.toggle_on
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
440
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
441 def set_stored_state_dict(self, stored_state):
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
442 self._stored_state = stored_state
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
443 # We start in the "off" position.
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
444 self._stored_state.setdefault('toggle_on', False)
282113d86d75 Save door and lever state.
Jeremy Thurgood <firxen@gmail.com>
parents: 335
diff changeset
445 return True
282
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
446
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
447 @classmethod
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
448 def requires(cls):
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
449 return [("name", "string"), ("position", "coordinates")]
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
450
9d186b897d82 Toggle switch, sans art.
Jeremy Thurgood <firxen@gmail.com>
parents: 281
diff changeset
451
261
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
452 class Bullet(GameObject):
363
3dd08e18580f Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents: 362
diff changeset
453 def __init__(self, space, position, impulse, damage, bullet_type,
305
ce11e1cae0ed Enemies now die
Stefano Rivera <stefano@rivera.za.net>
parents: 302
diff changeset
454 source_collision_type):
261
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
455 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
456 body.angle = impulse.angle
293
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
457 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
458 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
459 self.shape.sensor = True
261
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
460 self.shape.collision_type = COLLISION_TYPE_PROJECTILE
305
ce11e1cae0ed Enemies now die
Stefano Rivera <stefano@rivera.za.net>
parents: 302
diff changeset
461 self.damage = damage
363
3dd08e18580f Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents: 362
diff changeset
462 self.type = bullet_type
293
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
463 self.source_collision_type = source_collision_type
261
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
464 super(Bullet, self).__init__(
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
465 SingleShapePhysicser(space, self.shape),
363
3dd08e18580f Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents: 362
diff changeset
466 render.ImageRenderer(resources.get_image(
3dd08e18580f Acid attacks shoot things that look like acid
Stefano Rivera <stefano@rivera.za.net>
parents: 362
diff changeset
467 'objects', '%s.png' % self.type)),
261
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
468 )
db7c8e74efb4 (really rubbish) bullets
Stefano Rivera <stefano@rivera.za.net>
parents: 256
diff changeset
469 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
470
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
471 def update(self, dt):
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
472 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
473 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
474 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
475 self.last_position = position
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
476 for collision in r:
302
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
477 shape = collision.shape
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
478 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
479 or shape == self.physicser.get_shape()
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
480 or shape.sensor):
293
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
481 continue
302
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
482 if hasattr(shape, 'physicser'):
a0a471ad2ee8 Pass bullet hits through to the target
Stefano Rivera <stefano@rivera.za.net>
parents: 297
diff changeset
483 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
484 self.physicser.remove_from_space()
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
485 self.remove = True
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
486 break
47226c661ae2 Bullets that mostly die when they hit things
Stefano Rivera <stefano@rivera.za.net>
parents: 286
diff changeset
487
286
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
488
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
489 class CollectibleGameObject(GameObject):
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
490 zorder = ZORDER_LOW
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
491
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
492 def __init__(self, space, name, shape, renderer):
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
493 self._name = name
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
494 shape.sensor = True
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
495 super(CollectibleGameObject, self).__init__(
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
496 SingleShapePhysicser(space, shape),
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
497 renderer,
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
498 interactible=environment.Interactible(
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
499 environment.Action(
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
500 self._collect, environment.HumanFormCondition())),
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
501 )
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
502
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
503 def _collect(self, protagonist):
374
150332d6c1fb Move the inventory to world, to slightly reduce overall hackyness
Stefano Rivera <stefano@rivera.za.net>
parents: 371
diff changeset
504 protagonist.add_item(self._name)
286
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
505 # TODO: Make this less hacky.
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
506 self.physicser.remove_from_space()
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
507 self.renderer = render.NullRenderer()
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
508
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
509
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
510 class Gun(CollectibleGameObject):
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
511 def __init__(self, space, position):
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
512 body = make_body(None, None, position)
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
513 self.shape = pymunk.Circle(body, 20)
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
514 super(Gun, self).__init__(
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
515 space, 'gun', self.shape,
332
ffefb93127c5 laser gun
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 331
diff changeset
516 render.ImageRenderer(resources.get_image('objects', 'gun.png')),
286
248b8fdb160c Collect gun (which currently looks like a bullet) to shoot.
Jeremy Thurgood <firxen@gmail.com>
parents: 282
diff changeset
517 )
312
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
518
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
519
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
520 class ClawAttack(GameObject):
356
582a96e5fdac Tweaks to the claw attack.
David Sharpe
parents: 354
diff changeset
521 def __init__(self, space, pos, vector, damage):
582a96e5fdac Tweaks to the claw attack.
David Sharpe
parents: 354
diff changeset
522 body = make_body(1, pymunk.inf,
582a96e5fdac Tweaks to the claw attack.
David Sharpe
parents: 354
diff changeset
523 (pos[0] + (vector.length * math.cos(vector.angle)),
362
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
524 pos[1] + (vector.length * math.sin(vector.angle))))
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
525 body.angle = vector.angle
312
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
526 self.shape = pymunk.Circle(body, 30)
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
527 self.shape.sensor = True
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
528 self.shape.collision_type = COLLISION_TYPE_WEREWOLF_ATTACK
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
529 self.damage = damage
312
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
530 super(ClawAttack, self).__init__(
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
531 SingleShapePhysicser(space, self.shape),
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
532 render.ImageRenderer(resources.get_image(
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
533 'objects', 'werewolf_SW_claw_attack.png',
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
534 transforms=(FLIP_H,))),
312
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
535 )
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
536
333
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
537 def update(self, dt):
3dd32686dbc3 Better wolf claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 332
diff changeset
538 super(ClawAttack, self).update(dt)
335
78b805549b4e More interesting claw attack.
Jeremy Thurgood <firxen@gmail.com>
parents: 333
diff changeset
539 if self.lifetime > 0.1:
312
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
540 self.physicser.remove_from_space()
72aca01c87ed Basic claw attack, stealing liberally from other people's code! ;)
David Sharpe
parents: 307
diff changeset
541 self.remove = True
351
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
542
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
543
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
544 class HostileTerrain(GameObject):
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
545 zorder = ZORDER_FLOOR
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
546 damage = None
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
547 tile = None
362
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
548 tile_alpha = 255
351
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
549 # How often to hit the player
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
550 rate = 5
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
551
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
552 def __init__(self, space, position, outline):
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
553 body = make_body(10, pymunk.inf, position)
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
554 # Adjust shape relative to position
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
555 shape_outline = [(p[0] - position[0], p[1] - position[1]) for
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
556 p in outline]
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
557 self.shape = pymunk.Poly(body, shape_outline)
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
558 self._ticks = 0
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
559 self.shape.collision_type = COLLISION_TYPE_SWITCH
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
560 self.shape.sensor = True
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
561 super(HostileTerrain, self).__init__(
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
562 SingleShapePhysicser(space, self.shape),
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
563 render.TiledRenderer(outline,
362
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
564 resources.get_image('tiles', self.tile),
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
565 self.tile_alpha))
351
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
566
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
567 def collide_with_protagonist(self, protagonist):
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
568 # We're called every frame we're colliding, so
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
569 # There are timing issues with stepping on and
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
570 # off terrian, but as long as the rate is reasonably
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
571 # low, they shouldn't impact gameplay
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
572 if self._ticks == 0:
357
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
573 self.apply_effect(protagonist)
351
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
574 self._ticks += 1
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
575 if self._ticks > self.rate:
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
576 self._ticks = 0
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
577
357
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
578 def apply_effect(self, protagonist):
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
579 protagonist.lose_health(self.damage)
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
580
351
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
581 @classmethod
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
582 def requires(cls):
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
583 return [("name", "string"), ("position", "coordinates"),
354
55752fc7b753 Add convex requirement to hint
Neil Muller <drnlmuller@gmail.com>
parents: 351
diff changeset
584 ("outline", "polygon (convex)")]
351
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
585
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
586
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
587 class AcidFloor(HostileTerrain):
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
588 damage = 1
50fce787ae17 Hostile terrian objects
Neil Muller <drnlmuller@gmail.com>
parents: 346
diff changeset
589 tile = 'acid.png'
377
4eb7f5dffa59 new acid and moonlight art
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 374
diff changeset
590 tile_alpha = 200
357
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
591
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
592
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
593 class ForceWolfFloor(HostileTerrain):
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
594 tile = 'moonlight.png'
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
595 rate = 0
362
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
596 tile_alpha = 150
d0aeb893967d Transparent moonlight
Neil Muller <drnlmuller@gmail.com>
parents: 359
diff changeset
597 zorder = ZORDER_HIGH
357
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
598
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
599 def apply_effect(self, protagonist):
d2c7e17299a7 Moonlight tiles force wolf form.
Jeremy Thurgood <firxen@gmail.com>
parents: 356
diff changeset
600 protagonist.force_wolf_form()
364
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
601
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
602
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
603 class KeyCard(CollectibleGameObject):
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
604 def __init__(self, space, position, name):
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
605 body = make_body(None, None, position)
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
606 self.shape = pymunk.Circle(body, 20)
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
607 super(KeyCard, self).__init__(
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
608 space, name, self.shape,
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
609 render.ImageRenderer(
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
610 resources.get_image('objects', '%s.png' % (name,))),
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
611 )
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
612
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
613 @classmethod
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
614 def requires(cls):
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
615 return [("name", "string"), ("position", "coordinates"),
72a91d64c088 Keycard doors.
Jeremy Thurgood <firxen@gmail.com>
parents: 363
diff changeset
616 ("item_name", "string")]