Mercurial > skaapsteker
annotate skaapsteker/sprites/base.py @ 624:83569a6b3ad8
Fix StartingDoorway and velocity clamping.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 07 May 2011 14:40:04 +0200 |
parents | 65881746dc20 |
children |
rev | line source |
---|---|
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
1 """Basic sprite classes.""" |
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
2 |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
3 import re |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
4 import time |
35 | 5 |
248 | 6 from pygame import Rect |
249 | 7 import pygame.transform |
248 | 8 |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
9 from .. import data |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
10 from .. import dialogue |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
11 from .. import sound |
248 | 12 from ..physics import Sprite |
13 from ..constants import Layers | |
551 | 14 from ..engine import OpenDialog, AddSpriteEvent, OpenNotification |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
15 from ..utils import cadd, csub, cmul, cdiv |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
16 |
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
17 |
35 | 18 TILE_SIZE = (64, 64) |
19 | |
97
a1d95c6152a0
Shiny new collision detection. Read code for usage information.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
20 # Collision Layers (values are ids not numbers) |
a1d95c6152a0
Shiny new collision detection. Read code for usage information.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
21 PC_LAYER = 0 |
a1d95c6152a0
Shiny new collision detection. Read code for usage information.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
22 MONSTER_LAYER = 1 |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
23 NPC_LAYER = 2 |
362 | 24 PROJECTILE_LAYER = 3 |
35 | 25 |
551 | 26 def notify(text): |
27 OpenNotification.post(text=text) | |
28 | |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
29 |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
30 def tile_midbottom(pos): |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
31 return cadd(cmul(pos, TILE_SIZE), cdiv(TILE_SIZE, (2, 1))) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
32 |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
33 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
34 class GameSprite(Sprite): |
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
35 image_dir = 'sprites/' |
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
36 image_file = None |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
37 sprite_layer = None |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
38 debug_color = (240, 0, 0) |
97
a1d95c6152a0
Shiny new collision detection. Read code for usage information.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
39 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
40 def __init__(self, pos, **opts): |
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
41 Sprite.__init__(self) |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
42 if self.sprite_layer is not None: |
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
43 # pygame's Sprite class clobbers self._layer in __init__(), so we need to thwart it. |
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
44 self._layer = self.sprite_layer |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
45 self.setup_image_data(pos, **opts) |
367
04b7d8724add
crashing vase bugfix
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
362
diff
changeset
|
46 self.setup(**opts) |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
47 |
342 | 48 def setup(self): |
49 pass | |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
50 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
51 def get_tile_pos(self): |
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
52 return cdiv(self.rect.center, TILE_SIZE) |
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
53 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
54 def setup_image_data(self, pos, **opts): |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
55 self.image = data.load_image(self.image_dir + self.image_file) |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
56 self.rect = self.image.get_rect(midbottom=tile_midbottom(pos)) |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
57 self.collide_rect = self.rect.move(0, 0) |
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
58 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
59 def get_debug_color(self): |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
60 return self.debug_color |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
61 |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
62 def draw_debug(self, surface): |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
63 pygame.draw.rect(surface, self.get_debug_color(), self.collide_rect, 1) |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
64 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
65 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
66 class AnimatedGameSprite(GameSprite): |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
67 # first item is the starting animation |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
68 animation_regexes = ( |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
69 # TODO: swap back once we know how to swap |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
70 ("running", r"^.*_\d+.png$"), |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
71 ("standing", r"^.*_standing.png$"), |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
72 ("attacking", r"^.*_attacking.png$"), |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
73 ) |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
74 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
75 wants_updates = True |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
76 frame_pause = 0.1 # default time between animation frames |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
77 facings = None |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
78 |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
79 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
80 def setup_image_data(self, pos, **opts): |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
81 self._animations = dict((k, []) for k, r in self.animation_regexes) |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
82 self._frame = 0 |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
83 self._last_time = 0 |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
84 self._animation = self.animation_regexes[0][0] |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
85 if self.facings and self._animation in self.facings: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
86 self.facing = self.facings[self._animation][0][0] |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
87 else: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
88 self.facing = None |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
89 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
90 for image in data.get_files(self.image_dir): |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
91 for name, pattern in self.animation_regexes: |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
92 if re.match(pattern, image): |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
93 img = data.load_image("%s/%s" % (self.image_dir, image)) |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
94 if self.facings and name in self.facings: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
95 if not self._animations[name]: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
96 self._animations[name] = dict((k, []) for k, t in self.facings[name]) |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
97 for facing, transform in self.facings[name]: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
98 if transform: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
99 mod_img = transform(img) |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
100 else: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
101 mod_img = img |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
102 collide_rect = mod_img.get_bounding_rect(1).inflate(-2,-2) |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
103 self._animations[name][facing].append((mod_img, collide_rect)) |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
104 else: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
105 collide_rect = img.get_bounding_rect(1).inflate(-2,-2) |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
106 self._animations[name].append((img, collide_rect)) |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
107 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
108 self.collide_rect = Rect((0, 0), (2, 2)) |
355
5bdb4677510a
Have fireballs appear in the right place.
Simon Cross <hodgestar@gmail.com>
parents:
352
diff
changeset
|
109 if isinstance(pos, pygame.Rect): |
5bdb4677510a
Have fireballs appear in the right place.
Simon Cross <hodgestar@gmail.com>
parents:
352
diff
changeset
|
110 self.collide_rect.midbottom = pos.midbottom |
5bdb4677510a
Have fireballs appear in the right place.
Simon Cross <hodgestar@gmail.com>
parents:
352
diff
changeset
|
111 else: |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
112 self.collide_rect.midbottom = tile_midbottom(pos) |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
113 self._update_image() |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
114 |
342 | 115 |
242
c30fcf903d29
Add update force parameter, so we can transition out of attacking animations even if it introduce a new collision
Neil Muller <drnlmuller@gmail.com>
parents:
241
diff
changeset
|
116 def _update_image(self, force=False): |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
117 if self.facing: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
118 images = self._animations[self._animation][self.facing] |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
119 else: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
120 images = self._animations[self._animation] |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
121 if self._frame >= len(images): |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
122 self._frame = 0 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
123 cand_image, cand_collide_rect = images[self._frame] |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
124 cand_collide_rect = cand_collide_rect.move(0, 0) # copy collide rect before we move it |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
125 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
126 cur_pos = self.collide_rect.midbottom |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
127 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
128 cand_rect = cand_image.get_rect() |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
129 cand_rect_offset = csub(cand_rect.midbottom, cand_collide_rect.midbottom) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
130 cand_rect.midbottom = cadd(cur_pos, cand_rect_offset) |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
131 cand_collide_rect.midbottom = cur_pos |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
132 |
242
c30fcf903d29
Add update force parameter, so we can transition out of attacking animations even if it introduce a new collision
Neil Muller <drnlmuller@gmail.com>
parents:
241
diff
changeset
|
133 if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not force: |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
134 return |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
135 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
136 self.image = cand_image |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
137 self.collide_rect = cand_collide_rect |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
138 self.rect = cand_rect |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
139 self.rect_offset = cand_rect_offset |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
140 self.init_pos() |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
141 |
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
142 def update(self): |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
143 if self._last_time is not None: |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
144 if time.time() - self._last_time > self.frame_pause: |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
145 self._frame += 1 |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
146 self._last_time = time.time() |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
147 force = False |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
148 if self._animation == 'attacking': |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
149 force = True |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
150 self._update_image(force) |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
151 else: |
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
152 self._last_time = time.time() |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
153 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
154 |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
155 class Monster(AnimatedGameSprite): |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
156 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
157 sprite_layer = Layers.PLAYER |
97
a1d95c6152a0
Shiny new collision detection. Read code for usage information.
Simon Cross <hodgestar@gmail.com>
parents:
88
diff
changeset
|
158 collision_layer = MONSTER_LAYER |
362 | 159 collides_with = set([PC_LAYER, PROJECTILE_LAYER]) |
47 | 160 |
117
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
161 debug_color = (240, 120, 120) |
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
162 |
152
60138b935bc0
Make enemies block by default, so we can jump off them
Neil Muller <drnlmuller@gmail.com>
parents:
144
diff
changeset
|
163 block = True |
60138b935bc0
Make enemies block by default, so we can jump off them
Neil Muller <drnlmuller@gmail.com>
parents:
144
diff
changeset
|
164 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
165 attack_frame = None # Mark a speficic frame in the animation as when the attack lands |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
166 attack_damage = 1 |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
167 |
25
fe87d828d093
Very basic enemy support.
Jeremy Thurgood <firxen@gmail.com>
parents:
22
diff
changeset
|
168 def __init__(self, pos, **opts): |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
169 AnimatedGameSprite.__init__(self, pos, **opts) |
186
72e92893ccb8
Use layers for floor check
Neil Muller <drnlmuller@gmail.com>
parents:
174
diff
changeset
|
170 self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2)) |
206
e2acf4663065
Move fox properties to the world
Neil Muller <drnlmuller@gmail.com>
parents:
203
diff
changeset
|
171 self.health = 10 |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
172 self._done_attack = False |
203
0a793c4ac341
Add default health values
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
173 self.setup(**opts) |
25
fe87d828d093
Very basic enemy support.
Jeremy Thurgood <firxen@gmail.com>
parents:
22
diff
changeset
|
174 |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
538
diff
changeset
|
175 def setup(self, fishmonger_count=False): |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
538
diff
changeset
|
176 self.fishmonger_count = fishmonger_count |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
538
diff
changeset
|
177 |
208
c72d9bf911fb
Add start of player damage
Neil Muller <drnlmuller@gmail.com>
parents:
206
diff
changeset
|
178 def collided_player(self, player): |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
179 self.start_attack(player) |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
180 |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
181 def update(self): |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
182 AnimatedGameSprite.update(self) |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
183 if self._animation == 'attacking': |
352 | 184 if self._frame == 0 and self._done_attack: |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
185 # We've just looped through the animation sequence |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
186 self._animation = self._old_state |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
187 self.facing = self._old_facing |
242
c30fcf903d29
Add update force parameter, so we can transition out of attacking animations even if it introduce a new collision
Neil Muller <drnlmuller@gmail.com>
parents:
241
diff
changeset
|
188 self._update_image(True) |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
189 elif self._frame == self.attack_frame and not self._done_attack: |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
190 # Attack the player |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
191 self.do_attack() |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
192 |
376
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
193 def _launch_projectile(self, cls): |
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
194 from .player import Player # avoid circular imports |
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
195 if self.facing == 'left': |
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
196 pos = pygame.Rect(self.rect.midleft, (0, 0)) |
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
197 else: |
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
198 pos = pygame.Rect(self.rect.midright, (0, 0)) |
441 | 199 projectile = cls(pos, direction=self.facing, hits=Player, source=self) |
538
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
200 projectile.launch() |
376
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
201 AddSpriteEvent.post(projectile) |
4d6198b68cb9
Add projectile launching method to monsters.
Simon Cross <hodgestar@gmail.com>
parents:
374
diff
changeset
|
202 |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
203 def do_attack(self): |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
204 """Overriden by monster classes""" |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
205 if self.check_collides(self._target): |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
206 self._target.damage(self.attack_damage) |
352 | 207 self._done_attack = True |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
208 |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
209 def start_attack(self, player): |
410
115e738e209c
Become visible when attacking. Enemies shouldn't attack invisible foxes.
Simon Cross <hodgestar@gmail.com>
parents:
409
diff
changeset
|
210 if player.invisible: |
115e738e209c
Become visible when attacking. Enemies shouldn't attack invisible foxes.
Simon Cross <hodgestar@gmail.com>
parents:
409
diff
changeset
|
211 return |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
212 if self._animation == 'attacking': |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
213 return # We're already attacking |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
214 elif self.attack_frame is not None: |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
215 self._done_attack = False |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
216 self._target = player |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
217 self._old_state = self._animation |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
218 self._old_facing = self.facing |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
219 self._animation = 'attacking' |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
220 self._frame = 0 # Start the attack from the beginning |
242
c30fcf903d29
Add update force parameter, so we can transition out of attacking animations even if it introduce a new collision
Neil Muller <drnlmuller@gmail.com>
parents:
241
diff
changeset
|
221 self._update_image(True) |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
302
diff
changeset
|
222 self._last_time = self._start_attack_time = time.time() |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
223 else: |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
228
diff
changeset
|
224 player.damage(1) # collision damage |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
225 |
210 | 226 def damage(self, damage): |
227 self.health -= damage | |
374 | 228 if self.health <= 0: |
528
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
229 AddSpriteEvent.post(Skeleton(self.rect.midbottom)) |
210 | 230 self.kill() |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
538
diff
changeset
|
231 if self.fishmonger_count: |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
538
diff
changeset
|
232 self.world.missions.fishmonger_demons_killed += 1 |
210 | 233 |
373
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
234 class PatrollingMonster(Monster): |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
235 """Monster that collides with horizontal geography""" |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
236 |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
237 debug_color = (120, 240, 120) |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
238 |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
239 patrol_speed = (200, 0) |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
240 |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
241 def update(self): |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
242 Monster.update(self) |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
243 if self._animation == 'running': |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
244 if self.facing == 'left': |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
245 self.velocity = (-self.patrol_speed[0], 0) |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
246 elif self.facing == 'right': |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
247 self.velocity = self.patrol_speed |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
248 |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
249 def collided(self, other): |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
250 Monster.collided(self, other) |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
251 # Check if the object we've collided with is the same height our higher than us |
399 | 252 if (other.block or other.floor) and other.collide_rect.bottom <= self.collide_rect.bottom: |
373
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
253 # Change direction |
409 | 254 self.change_facing() |
255 | |
256 def change_facing(self): | |
257 if self.facing == 'left': | |
258 self.facing = 'right' | |
259 self._update_image(True) | |
260 else: | |
261 self.facing = 'left' | |
262 self._update_image(True) | |
373
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
370
diff
changeset
|
263 |
400
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
264 def check_floors(self, floors): |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
265 """If we're only on 1 floor tile, and our centre is beyond half way, |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
266 turn back""" |
592
1386cae4cc15
Remove don't crash if we're colliding with a player after being bounced off the floor
Neil Muller <drnlmuller@gmail.com>
parents:
584
diff
changeset
|
267 if len(floors) != 1: |
400
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
268 return |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
269 |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
270 floor = floors[0] |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
271 |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
272 if self.facing == 'left': |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
273 if self.collide_rect.centerx < floor.collide_rect.centerx: |
409 | 274 self.change_facing() |
400
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
275 else: |
1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
Neil Muller <drnlmuller@gmail.com>
parents:
399
diff
changeset
|
276 if self.collide_rect.centerx > floor.collide_rect.centerx: |
409 | 277 self.change_facing() |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
278 |
213
c5c4306593d8
Attempt to animate NPCs a bit.
Simon Cross <hodgestar@gmail.com>
parents:
210
diff
changeset
|
279 class NPC(AnimatedGameSprite): |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
280 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
281 sprite_layer = Layers.PLAYER |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
282 collision_layer = NPC_LAYER |
362 | 283 collides_with = set([]) |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
284 |
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
285 debug_color = (240, 240, 240) |
271
56a529a69e97
Only backout / move-off "solid" collisions
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
286 bounce_factor = (0, 0) # NPC's don't bounce by default |
537
a7b7694644a5
Exclude NPC's from gravity
Neil Muller <drnlmuller@gmail.com>
parents:
534
diff
changeset
|
287 gravitates = False |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
288 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
289 block = False |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
290 actionable = True |
189
9d08f99b5ddf
Add npcs to gamestate. Update gamestate. Pass world around a bit. Some other stuff.
Simon Cross <hodgestar@gmail.com>
parents:
186
diff
changeset
|
291 |
484
b15b0bd933a5
Fix facing on NPCs and clean up debug prints.
Jeremy Thurgood <firxen@gmail.com>
parents:
475
diff
changeset
|
292 def setup(self, name, world, dsm, state, facing=None): |
302
78220c989e6a
Add supporting for flicking between speaking NPCs.
Simon Cross <hodgestar@gmail.com>
parents:
296
diff
changeset
|
293 self.name = name |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
538
diff
changeset
|
294 self.world = world |
217
fcc5eca8eaca
Add explicit starting state to avoid it magically appearing later.
Simon Cross <hodgestar@gmail.com>
parents:
214
diff
changeset
|
295 self.dsm = dialogue.DSM(name, world, dsm, state) |
461
c6d1165bb16f
Can talk your way past the guard
Neil Muller <drnlmuller@gmail.com>
parents:
460
diff
changeset
|
296 self._me = getattr(world.npcs, self.name) |
475
18427edff33a
Add facing support to npcs
Neil Muller <drnlmuller@gmail.com>
parents:
461
diff
changeset
|
297 self.facing = facing |
508 | 298 self._update_image(True) # Force things to the right image |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
299 |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
300 def player_action(self, player): |
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
301 OpenDialog.post(self) |
209 | 302 |
501
9a16483e49cb
Remove 1st set of blocking samuri
Neil Muller <drnlmuller@gmail.com>
parents:
487
diff
changeset
|
303 def remove(self): |
9a16483e49cb
Remove 1st set of blocking samuri
Neil Muller <drnlmuller@gmail.com>
parents:
487
diff
changeset
|
304 self._me.level = '_limbo' |
9a16483e49cb
Remove 1st set of blocking samuri
Neil Muller <drnlmuller@gmail.com>
parents:
487
diff
changeset
|
305 self.kill() |
9a16483e49cb
Remove 1st set of blocking samuri
Neil Muller <drnlmuller@gmail.com>
parents:
487
diff
changeset
|
306 |
209 | 307 |
460 | 308 class BlockingNPC(NPC): |
309 | |
310 collides_with = set([PC_LAYER]) | |
311 mobile = False | |
312 block = True | |
313 | |
487
17e01e201f9b
Add default facing to blocking NPCs
Neil Muller <drnlmuller@gmail.com>
parents:
484
diff
changeset
|
314 def setup(self, name, world, dsm, state, block, facing=None): |
475
18427edff33a
Add facing support to npcs
Neil Muller <drnlmuller@gmail.com>
parents:
461
diff
changeset
|
315 NPC.setup(self, name, world, dsm, state, facing) |
460 | 316 self.block = block |
317 self._animation = 'standing' | |
318 | |
319 | |
336
c8fd82ff0c71
Hook up fire buttons to attack functions. Use correct check for tails. Add skeleton for projectiles.
Simon Cross <hodgestar@gmail.com>
parents:
335
diff
changeset
|
320 class Projectile(AnimatedGameSprite): |
362 | 321 |
322 collision_layer = PROJECTILE_LAYER | |
323 collides_with = set() | |
538
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
324 launch_sound = None, None |
362 | 325 |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
326 gravitates = False |
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
327 |
362 | 328 DAMAGE = 10 |
329 | |
366 | 330 PROJECTILE_SIZE = (0, 0) # pixels |
331 VELOCITY = (10, 10) # pixels/s | |
332 | |
441 | 333 def setup(self, direction, hits, source, **opts): |
366 | 334 super(Projectile, self).setup(**opts) |
335 self.facing = direction | |
441 | 336 self.source = source # source of the projectile (may be None) |
380
a0afc7c1a4dc
Force projectile image to have right facing
Neil Muller <drnlmuller@gmail.com>
parents:
376
diff
changeset
|
337 self._update_image(True) # ensure we get the direction right |
538
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
338 if self.launch_sound[0]: |
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
339 sound.load_sound(self.launch_sound[0], self.launch_sound[0], self.launch_sound[1]) |
366 | 340 |
362 | 341 if isinstance(hits, tuple): |
342 self.hits = hits + (Geography,) | |
343 else: | |
344 self.hits = (hits, Geography) | |
345 | |
366 | 346 if self.facing == "left": |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
347 shift = cdiv(self.PROJECTILE_SIZE, (-2, 1)) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
348 dv = cmul(self.VELOCITY, (-1, 1)) |
366 | 349 else: |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
350 shift = cdiv(self.PROJECTILE_SIZE, (2, 1)) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
351 dv = cmul(self.VELOCITY, (1, 1)) |
366 | 352 |
353 self.rect.move_ip(shift) | |
354 self.collide_rect.move_ip(shift) | |
355 self.deltav(dv) | |
356 | |
538
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
357 def launch(self): |
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
358 if self.launch_sound[0]: |
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
359 sound.play_sound(self.launch_sound[0]) |
c1b0ad1c0932
Hook up projectile sounds.
Simon Cross <hodgestar@gmail.com>
parents:
537
diff
changeset
|
360 |
362 | 361 def explode(self): |
362 self.kill() | |
363 | |
364 def collided(self, other): | |
365 if not isinstance(other, self.hits): | |
366 return | |
367 if hasattr(other, 'damage'): | |
368 other.damage(self.DAMAGE) | |
584
b8bed508036f
Don't steal life from skulls
Stefano Rivera <stefano@rivera.za.net>
parents:
562
diff
changeset
|
369 if hasattr(self.source, 'steal_life'): |
b8bed508036f
Don't steal life from skulls
Stefano Rivera <stefano@rivera.za.net>
parents:
562
diff
changeset
|
370 self.source.steal_life(self.DAMAGE) |
362 | 371 self.explode() |
372 | |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
373 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
374 class Item(GameSprite): |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
375 mobile = False |
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
376 gravitates = False |
335 | 377 actionable = True |
434
827c5d045cf5
Don't allow the cannon to be picked up
Neil Muller <drnlmuller@gmail.com>
parents:
412
diff
changeset
|
378 liftable = True |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
379 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
380 sprite_layer = Layers.PLAYER |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
381 collision_layer = NPC_LAYER |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
382 |
335 | 383 debug_color = (240, 0, 240) |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
384 |
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
385 |
193
897eec397cbb
Fix state checks for hattori, ichiro, kaneda and kumiko. In the process provide easier access to other npcs.
Simon Cross <hodgestar@gmail.com>
parents:
191
diff
changeset
|
386 def setup(self, name, world): |
209 | 387 self.name = name |
388 self.world = world | |
335 | 389 self._me = getattr(self.world.items, self.name) |
191 | 390 |
391 | |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
392 def player_action(self, player): |
434
827c5d045cf5
Don't allow the cannon to be picked up
Neil Muller <drnlmuller@gmail.com>
parents:
412
diff
changeset
|
393 if self.liftable: |
827c5d045cf5
Don't allow the cannon to be picked up
Neil Muller <drnlmuller@gmail.com>
parents:
412
diff
changeset
|
394 player.take_item(self) |
209 | 395 |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
396 |
335 | 397 def remove(self): |
398 self._me.level = '_limbo' | |
399 self.kill() | |
400 | |
202
a11325bc5ff0
Sprite refactoring stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
193
diff
changeset
|
401 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
402 class Geography(GameSprite): |
18
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
403 mobile = False |
81974842b38e
Add skeleton for physics and sprites.
Simon Cross <hodgestar@gmail.com>
parents:
diff
changeset
|
404 gravitates = False |
362 | 405 collides_with = set([PC_LAYER, MONSTER_LAYER, NPC_LAYER, PROJECTILE_LAYER]) |
144
6b488e1351a5
Buggy ground implementation. Make the world less bouncy
Neil Muller <drnlmuller@gmail.com>
parents:
127
diff
changeset
|
406 is_ground = True |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
407 actionable = False |
144
6b488e1351a5
Buggy ground implementation. Make the world less bouncy
Neil Muller <drnlmuller@gmail.com>
parents:
127
diff
changeset
|
408 bounce_factor = (0.0, 0.0) |
28
94d5ebaa912f
Example for global sprite importing.
Simon Cross <hodgestar@gmail.com>
parents:
25
diff
changeset
|
409 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
410 def setup(self, image): |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
411 pass |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
412 |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
413 def setup_image_data(self, pos, image, **opts): |
35 | 414 self.tile_pos = pos |
415 self.image = image | |
122
51bcc909873d
Saner, buggier collision rectangles
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
416 self.collide_rect = self.image.get_bounding_rect(1) |
186
72e92893ccb8
Use layers for floor check
Neil Muller <drnlmuller@gmail.com>
parents:
174
diff
changeset
|
417 self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2)) |
122
51bcc909873d
Saner, buggier collision rectangles
Neil Muller <drnlmuller@gmail.com>
parents:
117
diff
changeset
|
418 self.rect = self.image.get_rect() |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
419 self.rect_offset = csub(self.collide_rect.topleft, self.rect.topleft) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
420 self.rect.topleft = cmul(pos, TILE_SIZE) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
421 self.collide_rect.topleft = cadd(self.rect.topleft, self.rect_offset) |
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
422 self.floor_rect.topleft = cadd(self.rect.topleft, self.rect_offset) |
35 | 423 |
117
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
424 def get_debug_color(self): |
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
425 if self.floor or self.block: |
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
426 return (240, 240, 0) |
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
427 return (0, 240, 0) |
b361d9e17c26
Angry fruit salad debug boxes.
Jeremy Thurgood <firxen@gmail.com>
parents:
97
diff
changeset
|
428 |
35 | 429 |
249 | 430 |
431 class Doorway(GameSprite): | |
432 mobile = False | |
433 gravitates = False | |
434 | |
271
56a529a69e97
Only backout / move-off "solid" collisions
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
435 blocks = False |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
436 actionable = True |
271
56a529a69e97
Only backout / move-off "solid" collisions
Neil Muller <drnlmuller@gmail.com>
parents:
264
diff
changeset
|
437 |
249 | 438 image_file = 'torii.png' |
439 | |
624
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
440 def __init__(self, pos, **opts): |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
441 super(Doorway, self).__init__(pos, **opts) |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
442 self.tile_pos = pos |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
443 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
444 def setup_image_data(self, pos, **opts): |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
445 super(Doorway, self).setup_image_data(pos, **opts) |
249 | 446 self.image = pygame.transform.scale(self.image, self.image.get_rect().center) |
447 self.rect = self.image.get_rect(midbottom=self.rect.midbottom) | |
448 self.collide_rect = self.rect | |
449 | |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
450 def setup(self, facing, leadsto): |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
451 self.facing = facing |
249 | 452 self.leadsto = leadsto |
453 | |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
454 def player_action(self, player): |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
455 from .. import engine, levelscene |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
456 engine.ChangeScene.post((levelscene.LevelScene, self.leadsto)) |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
457 |
624
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
458 def get_tile_pos(self): |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
459 return self.tile_pos |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
460 |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
461 |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
462 |
562
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
463 class CelestialDoorway(Doorway): |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
464 def player_action(self, player): |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
465 from .. import engine |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
466 if len(self.world.fox.tails) < 8: |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
467 engine.OpenNotification.post(text="You need eight tails to enter the Celestial Plane.") |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
468 return |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
469 super(CelestialDoorway, self).player_action(player) |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
470 |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
471 |
91ad18a5acf1
Celestial Doorway now counts tails.
Jeremy Thurgood <firxen@gmail.com>
parents:
551
diff
changeset
|
472 |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
473 class StartingDoorway(Doorway): |
273
95e2ef31e714
Hit "down" to interact with things.
Jeremy Thurgood <firxen@gmail.com>
parents:
271
diff
changeset
|
474 actionable = False |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
475 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
476 def setup_image_data(self, pos, **opts): |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
477 self.image = pygame.Surface((0, 0)) |
621
851c8726696c
More cleanup. Mostly using utils.c* instead of doing things the long way.
Jeremy Thurgood <firxen@gmail.com>
parents:
592
diff
changeset
|
478 self.rect = self.image.get_rect(midbottom=tile_midbottom(pos)) |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
479 self.collide_rect = self.rect.move(0, 0) |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
480 |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
481 |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
482 def setup(self, facing): |
624
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
483 super(StartingDoorway, self).setup(facing, None) |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
484 |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
485 def player_action(self, player): |
83569a6b3ad8
Fix StartingDoorway and velocity clamping.
Jeremy Thurgood <firxen@gmail.com>
parents:
623
diff
changeset
|
486 pass |
264
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
487 |
afd9256ad682
Move between doorways. (Still with hacky collision limiting.)
Jeremy Thurgood <firxen@gmail.com>
parents:
261
diff
changeset
|
488 |
528
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
489 class Skeleton(GameSprite): |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
490 mobile = False |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
491 gravitates = False |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
492 actionable = False |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
493 liftable = False |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
494 image_dir = 'sprites/skulls/' |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
495 sprite_layer = Layers.BEHIND |
528
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
496 debug_color = (255, 255, 0) |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
497 |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
498 |
528
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
499 def __init__(self, pos, player=False, **opts): |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
500 self._pos = pos |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
501 if player: |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
502 self.image_file = 'kitsune.png' |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
503 else: |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
504 self.image_file = 'monster.png' |
622
da331c80ec08
Clean up sprite inheritance hierarchy a bit.
Jeremy Thurgood <firxen@gmail.com>
parents:
621
diff
changeset
|
505 super(Skeleton, self).__init__(pos, **opts) |
528
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
506 |
623
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
507 def setup_image_data(self, pos, **opts): |
65881746dc20
More Sprite hierarchy work.
Jeremy Thurgood <firxen@gmail.com>
parents:
622
diff
changeset
|
508 super(Skeleton, self).setup_image_data(pos, **opts) |
528
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
509 # Pixel based rect, not tile: |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
510 self.rect = self.image.get_rect(midbottom=self._pos) |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
511 self.collide_rect = self.rect.move(0, 0) |
52b38b803782
Skeleton for dead monsters
Stefano Rivera <stefano@rivera.za.net>
parents:
508
diff
changeset
|
512 |
249 | 513 |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
514 def find_sprite(descr, mod_name=None): |
28
94d5ebaa912f
Example for global sprite importing.
Simon Cross <hodgestar@gmail.com>
parents:
25
diff
changeset
|
515 """Create a sprite object from a dictionary describing it.""" |
261
7668243695f4
Trial patch for dealing with unicode dict key issue on Windows.
Simon Cross <hodgestar@gmail.com>
parents:
254
diff
changeset
|
516 descr = dict((str(k), v) for k, v in descr.items()) # convert unicode keys |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
517 cls_name = descr.pop("type") |
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
518 if mod_name is None: |
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
122
diff
changeset
|
519 mod_name, cls_name = cls_name.rsplit(".", 1) |
28
94d5ebaa912f
Example for global sprite importing.
Simon Cross <hodgestar@gmail.com>
parents:
25
diff
changeset
|
520 mod_name = ".".join(["skaapsteker.sprites", mod_name]) |
94d5ebaa912f
Example for global sprite importing.
Simon Cross <hodgestar@gmail.com>
parents:
25
diff
changeset
|
521 mod = __import__(mod_name, fromlist=[cls_name]) |
94d5ebaa912f
Example for global sprite importing.
Simon Cross <hodgestar@gmail.com>
parents:
25
diff
changeset
|
522 cls = getattr(mod, cls_name) |
94d5ebaa912f
Example for global sprite importing.
Simon Cross <hodgestar@gmail.com>
parents:
25
diff
changeset
|
523 return cls(**descr) |
35 | 524 |