-
Notifications
You must be signed in to change notification settings - Fork 0
/
spaceship.py
53 lines (32 loc) · 1.28 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pygame
class SpaceShip(pygame.sprite.Sprite):
""" Base Class for player ship and enemy ship """
def __init__(self, game, ship_img, scale=None) -> None:
super().__init__()
self.game = game
self.game_display = game.main_surface
self.settings = game.settings
self.surface_width = game.main_surface.get_width()
self.surface_height = game.main_surface.get_height()
self.display_rect = self.game_display.get_rect()
self.image = pygame.image.load(ship_img)
if scale is not None:
self.image = pygame.transform.scale(self.image, scale)
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.image)
self._moving_up = False
self._moving_down = False
self._moving_right = False
self._moving_left = False
self.shooter = None
def span_ship(self):
self.__draw()
def __draw(self):
# pygame.draw.rect(self.game_display, (0,0,255), self.ship_rect)
self.game_display.blit(self.image, self.rect)
def move_up(self, speed):
if self._moving_up:
self.rect.y -= int(speed)
def move_down(self, speed):
if self._moving_down:
self.rect.y += int(speed)