-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathship.py
executable file
·57 lines (42 loc) · 1.21 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pygame
from pygame.locals import *
from sys import exit
import os.path as osp
class Ship(pygame.sprite.Sprite):
def __init__(self, screen, ship_image, x, y):
pygame.sprite.Sprite.__init__(self)
self.screen = screen
self.screen_width, self.screen_height = self.screen.get_size()
self.image = ship_image
self.rect = self.image.get_rect()
self.lives = 3
self.rect.x = x
self.rect.y = y
# Updates location of ship depending on x and
def update(self, x, y):
if y <= 320:
self.rect.y = 320
elif y + self.rect.height >= self.screen_height:
self.rect.y == self.screen_height - self.rect.height
else:
self.rect.y = y
if x + self.rect.width >= self.screen_width:
self.rect.x = self.screen_width - self.rect.width
elif x < 0:
self.rect.x = 0
else:
self.rect.x = x
# Returns current x position of the ship
def XPosition(self):
return self.rect.x
# Returns current y position of the ship
def YPosition(self):
return self.rect.y
def getImage(self):
return self.rect
# Returns current number of lives of the ship
def CurrentLives(self):
return self.lives
# Reduces number of lives of the ship when it hits a number or operator
def ReduceLives(self):
self.lives -= 1