annotate nagslang/game_object.py @ 143:deac6a4008e7

Hook up protagnist animations
author Neil Muller <drnlmuller@gmail.com>
date Mon, 02 Sep 2013 22:35:41 +0200
parents f36a7075d9a0
children 0c49627920eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
1 import math
62
1d67a8c9861d WTF whitespace?!?!?!?!
Jeremy Thurgood <firxen@gmail.com>
parents: 60
diff changeset
2
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
3 import pygame
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
4 import pymunk
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
5 import pymunk.pygame_util
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
6
107
b90d01e4d9d4 Layered drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 106
diff changeset
7 from nagslang.constants import (
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
8 SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW)
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
9 from nagslang.options import options
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
10
82
11b0017b5e4b Fix whitespace.
davidsharpe@185.4.16.172.in-addr.arpa
parents: 81
diff changeset
11
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
12 class PuzzleGlue(object):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
13 """Glue that holds bits of a puzzle together.
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
14 """
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
15 def __init__(self):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
16 self._components = {}
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
17
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
18 def add_component(self, name, puzzler):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
19 self._components[name] = puzzler
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
20 puzzler.set_glue(self)
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
21
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
22 def get_state_of(self, name):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
23 return self._components[name].get_state()
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
24
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
25
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
26 class Puzzler(object):
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
27 """Behaviour specific to a puzzle component.
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
28 """
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
29 def set_glue(self, glue):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
30 self.glue = glue
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
31
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
32 def set_game_object(self, game_object):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
33 self.game_object = game_object
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
34
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
35 def get_state(self):
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
36 raise NotImplementedError()
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
37
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
38
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
39 class FloorSwitchPuzzler(Puzzler):
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
40 def get_state(self):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
41 space = self.game_object.get_space()
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
42 for shape in space.shape_query(self.game_object.get_shape()):
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
43 if shape.collision_type in SWITCH_PUSHERS:
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
44 return True
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
45 return False
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
46
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
47
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
48 class StateProxyPuzzler(Puzzler):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
49 def __init__(self, state_source):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
50 self._state_source = state_source
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
51
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
52 def get_state(self):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
53 return self.glue.get_state_of(self._state_source)
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
54
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
55
140
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
56 class StateLogicalAndPuzzler(Puzzler):
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
57 def __init__(self, *state_sources):
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
58 self._state_sources = state_sources
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
59
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
60 def get_state(self):
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
61 for state_source in self._state_sources:
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
62 if not self.glue.get_state_of(state_source):
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
63 return False
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
64 return True
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
65
f36a7075d9a0 Two switch puzzle!
Jeremy Thurgood <firxen@gmail.com>
parents: 133
diff changeset
66
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
67 class Physicser(object):
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
68 def __init__(self, space):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
69 self._space = space
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
70
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
71 def get_space(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
72 return self._space
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
73
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
74 def set_game_object(self, game_object):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
75 self.game_object = game_object
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
76
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
77 def get_shape(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
78 raise NotImplementedError()
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
79
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
80 def add_to_space(self):
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
81 raise NotImplementedError()
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
82
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
83 def remove_from_space(self):
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
84 raise NotImplementedError()
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
85
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
86 def get_render_position(self, surface):
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
87 raise NotImplementedError()
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
88
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
89 def get_angle(self):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
90 raise NotImplementedError()
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
91
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
92 def apply_impulse(self, j, r=(0, 0)):
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
93 raise NotImplementedError()
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
94
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
95
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
96 class SingleShapePhysicser(Physicser):
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
97 def __init__(self, space, shape):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
98 super(SingleShapePhysicser, self).__init__(space)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
99 self._shape = shape
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
100
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
101 def get_shape(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
102 return self._shape
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
103
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
104 def add_to_space(self):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
105 self.get_space().add(self._shape)
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
106 if not self._shape.body.is_static:
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
107 self.get_space().add(self._shape.body)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
108
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
109 def remove_from_space(self):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
110 self.get_space().remove(self._shape)
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
111 if not self._shape.body.is_static:
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
112 self.get_space().remove(self._shape.body)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
113
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
114 def get_render_position(self, surface):
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
115 pos = self._shape.body.position
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
116 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
117
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
118 def get_angle(self):
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
119 return self._shape.body.angle
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
120
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
121 def apply_impulse(self, j, r=(0, 0)):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
122 return self._shape.body.apply_impulse(j, r)
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
123
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
124
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
125 class Renderer(object):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
126 def set_game_object(self, game_object):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
127 self.game_object = game_object
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
128
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
129 def _render_shape(self, surface):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
130 shape = self.game_object.get_shape()
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
131 # Less general that pymunk.pygame_util.draw, but also a lot less noisy.
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
132 color = getattr(shape, 'color', pygame.color.THECOLORS['lightblue'])
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
133 # We only explicitly draw Circle and Poly shapes. Everything else we
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
134 # forward to pymunk.
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
135 if isinstance(shape, pymunk.Circle):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
136 centre = pymunk.pygame_util.to_pygame(shape.body.position, surface)
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
137 radius = int(shape.radius)
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
138 pygame.draw.circle(surface, color, centre, radius, 2)
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
139 elif isinstance(shape, pymunk.Poly):
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
140 # polygon bounding box
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
141 points = [pymunk.pygame_util.to_pygame(p, surface)
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
142 for p in shape.get_vertices()]
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
143 pygame.draw.lines(surface, color, True, points, 2)
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
144 else:
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
145 pymunk.pygame_util.draw(surface, shape)
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
146
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
147 def render(self, surface):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
148 pos = self.game_object.get_render_position(surface)
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
149 angle = self.game_object.get_render_angle()
104
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
150 if options.debug:
1be3eebb87c4 More consistent debug rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 93
diff changeset
151 self._render_shape(surface, pos, angle)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
152
143
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
153 def animate(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
154 # Used by time animatations to advance the clock
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
155 pass
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
156
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
157
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
158 def image_pos(image, pos):
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
159 return (pos[0] - image.get_width() / 2,
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
160 pos[1] - image.get_height() / 2)
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
161
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
162
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
163 class ImageRenderer(Renderer):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
164 def __init__(self, image):
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
165 self._image = image
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
166
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
167 def render(self, surface):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
168 pos = self.game_object.get_render_position(surface)
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
169 surface.blit(self._image, image_pos(self._image, pos))
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
170 super(ImageRenderer, self).render(surface)
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
171
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
172
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
173 class FacingImageRenderer(Renderer):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
174 def __init__(self, left_image, right_image):
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
175 self._images = {
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
176 'left': left_image,
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
177 'right': right_image,
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
178 }
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
179
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
180 def get_image(self, angle):
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
181 if abs(angle) < math.pi / 2:
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
182 return self._images['right']
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
183 return self._images['left']
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
184
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
185 def render(self, surface):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
186 pos = self.game_object.get_render_position(surface)
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
187 image = self.get_image(self.game_object.get_render_angle())
63
7f038ee778ad Put werewolf facing direction magic back.
Jeremy Thurgood <firxen@gmail.com>
parents: 62
diff changeset
188 surface.blit(image, image_pos(image, pos))
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
189 super(FacingImageRenderer, self).render(surface)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
190
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
191
143
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
192 class AnimatedFacingImageRenderer(FacingImageRenderer):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
193 def __init__(self, left_images, right_images):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
194 self._images = {
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
195 'left': left_images,
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
196 'right': right_images,
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
197 }
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
198 self._frame = 0
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
199 self._moving = False
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
200
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
201 def get_image(self, angle):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
202 if abs(angle) < math.pi / 2:
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
203 face = 'right'
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
204 else:
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
205 face = 'left'
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
206 if self._frame >= len(self._images[face]):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
207 self._frame = 0
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
208 return self._images[face][self._frame]
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
209
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
210 def render(self, surface):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
211 pos = self.game_object.get_render_position(surface)
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
212 image = self.get_image(self.game_object.get_render_angle())
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
213 surface.blit(image, image_pos(image, pos))
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
214 super(FacingImageRenderer, self).render(surface)
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
215
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
216 def animate(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
217 if self._moving:
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
218 self._frame += 1
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
219 else:
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
220 self._frame = 0
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
221
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
222 def start(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
223 self._moving = True
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
224
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
225 def stop(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
226 self._moving = False
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
227
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
228
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
229 class TimedAnimatedRenderer(ImageRenderer):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
230
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
231 def __init__(self, images):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
232 self._images = images
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
233 self._frame = 0
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
234 self._image = None
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
235
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
236 def _get_image(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
237 if self._frame > len(self._imaages):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
238 self._frame = 0
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
239 return self._images[self._frame]
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
240
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
241 def render(self, surface):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
242 self._image = self._get_image()
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
243 super(TimedAnimatedRenderer, self).render(surface)
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
244
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
245 def animate(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
246 self._frame += 1
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
247
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
248
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
249 class ShapeRenderer(Renderer):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
250 def render(self, surface):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
251 self._render_shape(surface)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
252 super(ShapeRenderer, self).render(surface)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
253
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
254
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
255 class ShapeStateRenderer(ShapeRenderer):
126
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
256 """Renders the shape in a different colour depending on the state.
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
257
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
258 Requires the game object it's attached to to have a puzzler.
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
259 """
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
260 def render(self, surface):
126
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
261 if self.game_object.puzzler.get_state():
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
262 color = pygame.color.THECOLORS['green']
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
263 else:
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
264 color = pygame.color.THECOLORS['red']
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
265
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
266 self.game_object.get_shape().color = color
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
267 super(ShapeStateRenderer, self).render(surface)
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
268
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
269
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
270 def damping_velocity_func(body, gravity, damping, dt):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
271 """Apply custom damping to this body's velocity.
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
272 """
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
273 damping = getattr(body, 'damping', damping)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
274 return pymunk.Body.update_velocity(body, gravity, damping, dt)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
275
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
276
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
277 def make_body(mass, moment, position, damping=None):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
278 body = pymunk.Body(mass, moment)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
279 body.position = position
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
280 if damping is not None:
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
281 body.damping = damping
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
282 body.velocity_func = damping_velocity_func
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
283 return body
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
284
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
285
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
286 class GameObject(object):
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
287 """A representation of a thing in the game world.
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
288
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
289 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
290 """
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
291
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
292 def __init__(self, physicser, renderer, puzzler=None):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
293 self.physicser = physicser
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
294 physicser.set_game_object(self)
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
295 self.physicser.add_to_space()
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
296 self.renderer = renderer
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
297 renderer.set_game_object(self)
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
298 self.puzzler = puzzler
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
299 if puzzler is not None:
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
300 puzzler.set_game_object(self)
107
b90d01e4d9d4 Layered drawing.
Jeremy Thurgood <firxen@gmail.com>
parents: 106
diff changeset
301 self.zorder = ZORDER_LOW
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
302
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
303 def get_space(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
304 return self.physicser.get_space()
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
305
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
306 def get_shape(self):
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
307 return self.physicser.get_shape()
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
308
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
309 def get_render_position(self, surface):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
310 return self.physicser.get_render_position(surface)
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
311
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
312 def get_render_angle(self):
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
313 return self.physicser.get_angle()
59
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
314
b412704a6737 Start of game object stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
315 def render(self, surface):
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
316 return self.renderer.render(surface)
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
317
143
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
318 def animate(self):
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
319 self.renderer.animate()
deac6a4008e7 Hook up protagnist animations
Neil Muller <drnlmuller@gmail.com>
parents: 140
diff changeset
320
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
321
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
322 class FloorSwitch(GameObject):
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
323 def __init__(self, space, position):
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
324 body = pymunk.Body()
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
325 body.position = position
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
326 self.shape = pymunk.Circle(body, 30)
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
327 self.shape.collision_type = COLLISION_TYPE_SWITCH
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
328 self.shape.sensor = True
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
329 super(FloorSwitch, self).__init__(
93
d6a49f0c1e6e Rectangular human protagonist shape, refactored physicsers.
Jeremy Thurgood <firxen@gmail.com>
parents: 91
diff changeset
330 SingleShapePhysicser(space, self.shape),
126
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
331 ShapeStateRenderer(),
123
23b533d6f27e Rearrange game objects a bit.
Jeremy Thurgood <firxen@gmail.com>
parents: 107
diff changeset
332 FloorSwitchPuzzler(),
81
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
333 )
a1b4d09e6f23 Floor switch with horrible hackery.
davidsharpe@lantea.local
parents: 63
diff changeset
334
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
335
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
336 class FloorLight(GameObject):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
337 def __init__(self, space, position, state_source):
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
338 body = pymunk.Body()
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
339 body.position = position
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
340 self.shape = pymunk.Circle(body, 10)
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
341 self.shape.collision_type = COLLISION_TYPE_SWITCH
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
342 self.shape.sensor = True
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
343 super(FloorLight, self).__init__(
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
344 SingleShapePhysicser(space, self.shape),
126
c3af35561494 Cleaner switch/light rendering.
Jeremy Thurgood <firxen@gmail.com>
parents: 123
diff changeset
345 ShapeStateRenderer(),
106
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
346 StateProxyPuzzler(state_source),
bce9cd8a4a8c FloorLight, linked to a FloorSwitch.
Jeremy Thurgood <firxen@gmail.com>
parents: 104
diff changeset
347 )
133
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
348
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
349
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
350 class Box(GameObject):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
351 def __init__(self, space, position):
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
352 body = make_body(10, 10000, position, damping=0.5)
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
353 self.shape = pymunk.Poly(
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
354 body, [(-20, -20), (20, -20), (20, 20), (-20, 20)])
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
355 self.shape.collision_type = COLLISION_TYPE_BOX
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
356 super(Box, self).__init__(
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
357 SingleShapePhysicser(space, self.shape),
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
358 ShapeRenderer(),
Jeremy Thurgood <firxen@gmail.com>
parents: 126
diff changeset
359 )