-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspaceship.py
32 lines (24 loc) · 893 Bytes
/
spaceship.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
import pygame
from pygame.sprite import Sprite
class Spaceship(Sprite):
'''A class that manages the spaceships'''
def __init__(self, ss_game):
super().__init__()
self.screen = ss_game.screen
self.screen_rect = ss_game.screen.get_rect()
self.settings = ss_game.settings
# Load the image and set the position
self.image = pygame.image.load('spaceship.bmp')
self.rect = self.image.get_rect()
self.rect.x = self.screen_rect.width - (2 * self.rect.width)
self.rect.y = self.rect.height
self.y = float(self.rect.y)
def check_edges(self):
'''Check whether the first row of spaceship has reached the edge'''
if self.rect.top <= 0 or self.rect.bottom >= self.screen_rect.bottom:
return True
def update(self):
'''Update the postion of the spaceship'''
self.y += (self.settings.spaceship_speed *
self.settings.spaceship_direction)
self.rect.y = self.y