-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.py
More file actions
40 lines (33 loc) · 1.01 KB
/
Enemy.py
File metadata and controls
40 lines (33 loc) · 1.01 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
import pygame
pygame.init()
class Enemy():
def __init__(self,x,y):
self.x = x
self.y = y
self.width = 100
self.height = 100
self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
self.speed = 11
self.img = pygame.image.load("assets/enemy.png").convert()
def moveDown(self):
if self.y < 5:
self.y += 1
def moveSideways(self):
if self.x + self.width > 800:
self.speed = -11
elif self.x < 0:
self.speed = +11
self.x += self.speed
def obstCollisions(self, cList):
collisionList = self.rect.collidelistall(cList)
if collisionList !=[]:
return cList[collisionList[0]]
else:
return False
def getX(self):
return self.x
def update(self,window):
self.moveDown()
self.moveSideways()
self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
window.blit(self.img, self.rect)