-
Notifications
You must be signed in to change notification settings - Fork 0
/
worm.py
30 lines (23 loc) · 1.07 KB
/
worm.py
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
import pygame
import enemy
from animation import Animation, ColorFadeAnimation
from constants import *
"""class Worm subclasses entity. Position starts randomly across the top of the screen, moves to the left until it hits the edge of the game scren, falls down a little, then moves to the right. Back and forth."""
class Worm(enemy.Enemy):
def __init__(self, position, subtype):
imageName = "worm " + subtype + ".png"
deathImageName = "worm " + subtype + " death.png"
anims = {
'idle': Animation(imageName),
'death': Animation(deathImageName, 32, 2, False),
'takehit': ColorFadeAnimation(imageName, 3, 3, (255, 0, 0, 0)),
}
super(Worm, self).__init__("worm", position, anims, 'idle')
self.health = 2
self.movex = 5
self.movey = 0
def update(self):
super(Worm, self).update()
if self.rect.left < 0 or self.rect.right > PLAY_WIDTH:
self.movex = -self.movex
self.rect.move_ip((self.movex, 30))