Mercurial > nagslang
comparison nagslang/game_object.py @ 155:b455873020be
Crates look like crates.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 02 Sep 2013 23:49:27 +0200 |
parents | 0c49627920eb |
children | f80323140317 |
comparison
equal
deleted
inserted
replaced
154:041f3b7a884c | 155:b455873020be |
---|---|
5 import pymunk.pygame_util | 5 import pymunk.pygame_util |
6 | 6 |
7 from nagslang.constants import ( | 7 from nagslang.constants import ( |
8 SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW) | 8 SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW) |
9 from nagslang.options import options | 9 from nagslang.options import options |
10 from nagslang.resources import resources | |
10 | 11 |
11 | 12 |
12 class PuzzleGlue(object): | 13 class PuzzleGlue(object): |
13 """Glue that holds bits of a puzzle together. | 14 """Glue that holds bits of a puzzle together. |
14 """ | 15 """ |
145 pygame.draw.lines(surface, color, True, points, 2) | 146 pygame.draw.lines(surface, color, True, points, 2) |
146 else: | 147 else: |
147 pymunk.pygame_util.draw(surface, shape) | 148 pymunk.pygame_util.draw(surface, shape) |
148 | 149 |
149 def render(self, surface): | 150 def render(self, surface): |
150 pos = self.game_object.get_render_position(surface) | |
151 angle = self.game_object.get_render_angle() | |
152 if options.debug: | 151 if options.debug: |
153 self._render_shape(surface, pos, angle) | 152 self._render_shape(surface) |
154 | 153 |
155 def animate(self): | 154 def animate(self): |
156 # Used by time animatations to advance the clock | 155 # Used by time animatations to advance the clock |
157 pass | 156 pass |
158 | 157 |
166 def __init__(self, image): | 165 def __init__(self, image): |
167 self._image = image | 166 self._image = image |
168 | 167 |
169 def render(self, surface): | 168 def render(self, surface): |
170 pos = self.game_object.get_render_position(surface) | 169 pos = self.game_object.get_render_position(surface) |
171 surface.blit(self._image, image_pos(self._image, pos)) | 170 angle = self.game_object.get_render_angle() * 180 / math.pi |
171 image = pygame.transform.rotate(self._image, angle) | |
172 surface.blit(image, image_pos(image, pos)) | |
172 super(ImageRenderer, self).render(surface) | 173 super(ImageRenderer, self).render(surface) |
173 | 174 |
174 | 175 |
175 class FacingImageRenderer(Renderer): | 176 class FacingImageRenderer(Renderer): |
176 def __init__(self, left_image, right_image): | 177 def __init__(self, left_image, right_image): |
353 self.shape = pymunk.Poly( | 354 self.shape = pymunk.Poly( |
354 body, [(-20, -20), (20, -20), (20, 20), (-20, 20)]) | 355 body, [(-20, -20), (20, -20), (20, 20), (-20, 20)]) |
355 self.shape.collision_type = COLLISION_TYPE_BOX | 356 self.shape.collision_type = COLLISION_TYPE_BOX |
356 super(Box, self).__init__( | 357 super(Box, self).__init__( |
357 SingleShapePhysicser(space, self.shape), | 358 SingleShapePhysicser(space, self.shape), |
358 ShapeRenderer(), | 359 ImageRenderer(resources.get_image('objects', 'crate.png')), |
359 ) | 360 ) |