-
Notifications
You must be signed in to change notification settings - Fork 0
/
Laser.py
34 lines (26 loc) · 1.04 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
import pygame
from RenderObject import RenderObject
from Shield import Shield
import Enemy
class Laser(RenderObject):
speed = 10
size = (4, 10)
def __init__(self, game, pos):
self.game = game
game.render_objects.append(self)
self.sprite = pygame.transform.scale(pygame.image.load("assets/missle_green.png"), self.size)
self.rect = self.sprite.get_rect()
self.rect = self.rect.move(pos)
self.rect.x -= self.size[0] / 2
def tick(self, surface):
self.rect.move_ip(0, -self.speed)
if self.rect.y + self.size[1] < 0:
self.game.render_objects.remove(self)
self.check_collision()
surface.blit(self.sprite, self.rect)
def check_collision(self):
for render_object in self.game.render_objects:
if type(render_object) is Enemy.Enemy or type(render_object) is Shield:
if self.rect.colliderect(render_object.rect):
self.game.render_objects.remove(self)
render_object.damage(self.rect)