-
Notifications
You must be signed in to change notification settings - Fork 1
/
gm_player.py
76 lines (63 loc) · 2.23 KB
/
gm_player.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import pygame
import os
from config import soundFolder
from asset_loader import YELLOW_SPACE_SHIP, YELLOW_LASER
from gm_abs_ship import Ship
class Player(Ship):
def __init__(self, x, y, health=100):
super().__init__(x, y, health)
self.ship_img = YELLOW_SPACE_SHIP
self.laser_img = YELLOW_LASER
self.mask = self.createMask()
self.max_health = health
self.width = self.ship_img.get_width()
self.height = self.ship_img.get_height()
def move_lasers(self, objs):
self.cooldown()
for laser in self.lasers:
laser.moveDown(False)
if laser.off_screen():
self.lasers.remove(laser)
else:
for obj in objs:
if laser.collision(obj):
if obj.y > 0:
laserEffect = pygame.mixer.Sound(os.path.join(soundFolder,"__retro-bomb-explosion_modif.wav"))
laserEffect.play()
objs.remove(obj)
self.lasers.remove(laser)
def draw(self, window):
super().draw(window)
self.healthBar(window)
def healthBar(self, window):
pygame.draw.rect(
window,
(255, 0, 0),
(self.x, self.y + self.ship_img.get_height() + 10, self.width, 10),
)
pygame.draw.rect(
window,
(0, 255, 0),
(
self.x,
self.y + self.ship_img.get_height() + 10,
(self.width * (self.health / self.max_health)),
10,
),
)
def moveLeft(self):
self.x -= self.velocity
def moveRight(self):
self.x += self.velocity
def moveUp(self):
self.y -= self.velocity
def moveDown(self):
self.y += self.velocity
def checkDownLimit(self, height, fromBottom):
return self.y + self.velocity + self.height + fromBottom < height
def checkUpLimit(self, height, fromTop):
return self.y - self.velocity - fromTop > height
def checkRightLimit(self, width):
return self.x + self.velocity + self.width < width
def checkLeftLimit(self, width):
return self.x - self.velocity > width