-
Notifications
You must be signed in to change notification settings - Fork 0
/
Laser.py
36 lines (32 loc) · 1.29 KB
/
Laser.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
import pygame
class Laser(pygame.sprite.Sprite):
def __init__(self, type, x,y, speed):
super().__init__()
self.type = type
self.speed= speed
if type == "yellow":
self.image = pygame.image.load('assets/pixel_laser_yellow.png').convert_alpha()
self.rect = self.image.get_rect(bottomleft=(x,y))
elif type=="red":
self.image = pygame.image.load('assets/pixel_laser_red.png').convert_alpha()
self.rect = self.image.get_rect(center=(x,y))
elif type =="blue":
self.image = pygame.image.load('assets/pixel_laser_blue.png').convert_alpha()
self.rect = self.image.get_rect(center=(x,y))
elif type =="green":
self.image = pygame.image.load('assets/pixel_laser_green.png').convert_alpha()
self.rect = self.image.get_rect(center=(x,y))
self.mask = pygame.mask.from_surface(self.image)
def destroy_laser(self):
self.kill()
def animate_laser(self):
if self.type == "yellow":
self.rect.y -= self.speed
if self.rect.bottom <0:
self.kill()
else:
self.rect.y += self.speed
if self.rect.top > 650:
self.kill()
def update(self):
self.animate_laser()