Mercurial > skaapsteker
annotate skaapsteker/sprites/enemies.py @ 632:0675f390653c
Initial port to Python 3 and Pygame 2.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Fri, 20 Jan 2023 20:01:06 +0100 |
parents | b7f912705adb |
children |
rev | line source |
---|---|
632
0675f390653c
Initial port to Python 3 and Pygame 2.
Simon Cross <hodgestar@gmail.com>
parents:
549
diff
changeset
|
1 from .base import Monster, PatrollingMonster |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
2 from pygame import transform |
25 | 3 |
4 | |
240 | 5 class RedOni(Monster): |
236
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
6 image_dir = 'sprites/oni red' |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
7 |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
8 attack_frame = 1 |
9528c6fc7f75
Hook up attack anaimation (needs facing support still)
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
9 attack_damage = 10 |
333
e499a10eb41f
Time based animation for npcs and monsters. Make oni attack faster
Neil Muller <drnlmuller@gmail.com>
parents:
240
diff
changeset
|
10 frame_pause = 0.05 # Fast attacks |
47 | 11 |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
12 facings = { |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
13 'running' : (('left', None), |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
14 ('right', lambda x: transform.flip(x, True, False))), |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
15 'attacking' : (('left', None), |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
16 ('right', lambda x: transform.flip(x, True, False))), |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
17 } |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
18 |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
425
diff
changeset
|
19 def setup(self, direction, **opts): |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
425
diff
changeset
|
20 super(RedOni, self).setup(**opts) |
127
e1dd3b785269
Initial game state stuff.
Jeremy Thurgood <firxen@gmail.com>
parents:
59
diff
changeset
|
21 self.facing = direction |
239
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
22 |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
23 def start_attack(self, player): |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
24 if self._animation != 'attacking': |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
25 # Turn to face the player we're attacking |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
26 if player.collide_rect.centerx > self.collide_rect.centerx: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
27 self.facing = 'right' |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
28 else: |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
29 self.facing = 'left' |
6a2f366d5e62
Add facing support for attack animations
Neil Muller <drnlmuller@gmail.com>
parents:
236
diff
changeset
|
30 Monster.start_attack(self, player) |
336
c8fd82ff0c71
Hook up fire buttons to attack functions. Use correct check for tails. Add skeleton for projectiles.
Simon Cross <hodgestar@gmail.com>
parents:
333
diff
changeset
|
31 |
c8fd82ff0c71
Hook up fire buttons to attack functions. Use correct check for tails. Add skeleton for projectiles.
Simon Cross <hodgestar@gmail.com>
parents:
333
diff
changeset
|
32 |
c8fd82ff0c71
Hook up fire buttons to attack functions. Use correct check for tails. Add skeleton for projectiles.
Simon Cross <hodgestar@gmail.com>
parents:
333
diff
changeset
|
33 class FireballOni(RedOni): |
c8fd82ff0c71
Hook up fire buttons to attack functions. Use correct check for tails. Add skeleton for projectiles.
Simon Cross <hodgestar@gmail.com>
parents:
333
diff
changeset
|
34 pass # TODO |
373
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
336
diff
changeset
|
35 |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
336
diff
changeset
|
36 |
a2efe5470b79
start of patrolling monsters
Neil Muller <drnlmuller@gmail.com>
parents:
336
diff
changeset
|
37 class PatrollingOni(RedOni, PatrollingMonster): |
425
fc3b5460d454
WTF. Redid change which got eaten.
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
409
diff
changeset
|
38 image_dir = 'sprites/oni blue' |
409 | 39 |
40 class FlyingOni(PatrollingOni): | |
425
fc3b5460d454
WTF. Redid change which got eaten.
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
409
diff
changeset
|
41 image_dir = 'sprites/oni gold' |
409 | 42 |
43 gravitates = False | |
44 | |
45 patrol_velocity = (0, 200) | |
46 | |
549
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
425
diff
changeset
|
47 def setup(self, **opts): |
b7f912705adb
Fishmonger now mongers fish.
Jeremy Thurgood <firxen@gmail.com>
parents:
425
diff
changeset
|
48 super(PatrollingOni, self).setup(**opts) |
409 | 49 self.heading = 'up' |
50 | |
51 def update(self): | |
52 PatrollingOni.update(self) | |
53 if self._animation == 'running': | |
54 if self.heading == 'up': | |
55 self.velocity = (0, -self.patrol_velocity[1]) | |
56 else: | |
57 self.velocity = (0, self.patrol_velocity[1]) | |
58 | |
59 def check_floors(self, floors): | |
60 pass | |
61 | |
62 def collided(self, other): | |
63 if not other.block or not other.floor: | |
64 return | |
65 if other.collide_rect.bottom < self.collide_rect.bottom: | |
66 # We're colliding with something above us | |
67 if self.heading == 'up': | |
68 self.change_facing() | |
69 else: | |
70 if self.heading == 'down': | |
71 self.change_facing() | |
72 | |
73 def change_facing(self): | |
74 if self.heading == 'up': | |
75 self.heading = 'down' | |
76 else: | |
77 self.heading = 'up' |