-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathship.py
37 lines (27 loc) · 1.06 KB
/
ship.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
import pygame
from pygame.sprite import Sprite
class Ship(Sprite):
def __init__(self, game):
super().__init__()
self.screen = game.screen
self.settings = game.settings
self.screen_rect = game.screen.get_rect()
# Load the image and gets its rect
self.image = pygame.image.load('images/spaceship/lv1SpaceShip.bmp')
self.rect = self.image.get_rect()
self.rect.midbottom = self.screen_rect.midbottom
self.x = float(self.rect.x)
# Movement flag
self.moving_right = False
self.moving_left = False
def update(self):
if self.moving_right and self.rect.right < self.screen_rect.right:
self.x += self.settings.ship_speed
elif self.moving_left and self.rect.left > self.screen_rect.left:
self.x -= self.settings.ship_speed
self.rect.x = self.x
def center_ship(self):
self.rect.midbottom = self.screen_rect.midbottom
self.x = float(self.rect.x)
def blit(self):
self.screen.blit(self.image, self.rect)