-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlien.py
More file actions
27 lines (22 loc) · 804 Bytes
/
Copy pathAlien.py
File metadata and controls
27 lines (22 loc) · 804 Bytes
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
import pygame.sprite
import pygame
import random
import Hardcodes
class Alien(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
pygame.sprite.Sprite.__init__(self)
# Import the alien image
self.image = pygame.image.load("alien.png")
self.image = pygame.transform.scale(self.image, (2 * 24, 2 * 18))
self.rect = self.image.get_rect()
# And set its position to the ceiling with a random x position
self.rect.x = random.randint(0, Hardcodes.windowSize[0]-3 * 24)
self.rect.y = -4 * 18
def update(self, dt):
self.move((0, Hardcodes.alienSpeed), dt)
if self.rect.y > 1700:
self.kill()
def move(self, pos, dt):
self.rect.x += pos[0] * dt
self.rect.y += pos[1] * dt