-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheagle.py
More file actions
56 lines (49 loc) · 1.56 KB
/
eagle.py
File metadata and controls
56 lines (49 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
""" Flying enemy, waves across screen """
from math import sin, radians
from tilengine import Spriteset, Sequence, Flags
from actor import Actor, Direction
import game
class Eagle(Actor):
""" Flying enemy """
size = (40, 40)
seq_fly = None
def __init__(self, item_ref, x, y):
# init class members once
if Eagle.spriteset is None:
Eagle.spriteset = Spriteset.fromfile("enemy_eagle")
Eagle.seq_fly = Sequence.create_sprite_sequence(Eagle.spriteset, "fly", 6)
Actor.__init__(self, item_ref, x, y)
self.frame = 0
self.base_y = y
self.xspeed = -3
self.direction = Direction.Left
self.sprite.set_animation(Eagle.seq_fly, 0)
self.collision_points = (4, 20, 36)
def update(self):
""" Update once per frame """
self.x += self.xspeed
self.y = self.base_y + int(sin(radians(self.frame*4))*15)
self.frame += 1
if self.frame is 10:
game.sounds.play("eagle", 3)
screen_x = self.x - game.world.x
if self.direction is Direction.Left:
if screen_x < 10:
self.direction = Direction.Right
self.xspeed = -self.xspeed
self.sprite.set_flags(Flags.FLIPX)
game.sounds.play("eagle", 3)
else:
for point in self.collision_points:
game.player.check_hit(self.x, self.y + point, self.direction)
else:
if screen_x > 590:
self.direction = Direction.Left
self.xspeed = -self.xspeed
self.sprite.set_flags(0)
game.sounds.play("eagle", 3)
else:
for point in self.collision_points:
game.player.check_hit(self.x + self.size[0], self.y + point, self.direction)
self.sprite.set_position(screen_x, self.y)
return True