-
Notifications
You must be signed in to change notification settings - Fork 0
/
alienattack.py
66 lines (49 loc) · 1.89 KB
/
alienattack.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
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
57
58
59
60
61
62
63
64
65
66
import pygame, sys , math
from pygame.locals import *
from Tank import *
#Alien = alienAttack(gameWidth*3/4, groundHeight-50)
#Alien.moveAlien(gameWidth,gameHeight)
class alienAttack(pygame.sprite.Sprite):
def __init__(self,X,Y):
self.health = 100
self.posX = X
self.posY = Y
self.alienw = 267
self.alienh = 306
self.alienImages = pygame.image.load('enemies/ship.png')
self.attackImage = pygame.image.load('enemies/ship.png')
self.damage = 5
def getDmg(self):
return self.damage
def getX(self):
return self.posX
def getY(self):
return self.posY
def IsInBounds(self,maxX,maxY,moveX,moveY):
if self.posX + moveX >= 0 and self.posX + self.alienw + moveX <= maxX:
self.posX = self.posX + moveX + 15
if self.posY + moveY >= 0 and self.posY + self.alienh + moveY <= maxY:
self.posY = self.posY + moveY + 15
def getImage(self):
return self.alienImages
class alienList():
def __init__(self,X,Y):
self.alienList = []
self.clock = 0
self.posX = X
self.posY = Y
self.moveX = -2
self.moveY = 0
self.limit = 2
def moveAlien(self,maxX,maxY):
self.clock = self.clock + 1
if self.clock > 80 and len(self.alienList) < self.limit :
self.clock = 0
self.alienList.append(alienAttack(self.posX,self.posY))
for tempAlien in self.alienList:
tempAlien.IsInBounds(maxX,maxY,self.moveX,self.moveY)
def getCount(self):
return len(self.alienList)-1
def drawAlien(self,screen):
for i in range(0,len(self.alienList)-1):
screen.blit(self.alienList[i].getImage(),(self.alienList[i].getX(),self.alienList[i].getY()))