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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fe87d828d093 Very basic enemy support.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
3
fe87d828d093 Very basic enemy support.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
4
240
9adf5076f3a2 Rename dummy monster
Neil Muller <drnlmuller@gmail.com>
parents: 239
diff changeset
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
215e2e74c244 Better dummy monster.
Jeremy Thurgood <firxen@gmail.com>
parents: 25
diff changeset
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
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
39
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
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
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
42
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
43 gravitates = False
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
44
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
45 patrol_velocity = (0, 200)
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
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
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
49 self.heading = 'up'
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
50
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
51 def update(self):
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
52 PatrollingOni.update(self)
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
53 if self._animation == 'running':
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
54 if self.heading == 'up':
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
55 self.velocity = (0, -self.patrol_velocity[1])
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
56 else:
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
57 self.velocity = (0, self.patrol_velocity[1])
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
58
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
59 def check_floors(self, floors):
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
60 pass
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
61
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
62 def collided(self, other):
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
63 if not other.block or not other.floor:
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
64 return
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
65 if other.collide_rect.bottom < self.collide_rect.bottom:
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
66 # We're colliding with something above us
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
67 if self.heading == 'up':
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
68 self.change_facing()
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
69 else:
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
70 if self.heading == 'down':
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
71 self.change_facing()
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
72
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
73 def change_facing(self):
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
74 if self.heading == 'up':
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
75 self.heading = 'down'
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
76 else:
ed26bbfec03a Add up-down 'Fying' Oni
Neil Muller <drnlmuller@gmail.com>
parents: 373
diff changeset
77 self.heading = 'up'