-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaser.py
executable file
·45 lines (33 loc) · 938 Bytes
/
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
37
38
39
40
41
42
43
44
45
import pygame
from pygame.locals import *
from sys import exit
import os.path as osp
class Laser(pygame.sprite.Sprite):
def __init__(self, screen, laser_image, x, y):
pygame.sprite.Sprite.__init__(self)
self.screen = screen
self.image = laser_image
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
# Returns the current x position of the laser
def XPosition(self):
return self.rect.x
def getImage(self):
return self.rect
# Returns the current y position of the laser
def YPosition(self):
return self.rect.y
# Moves the laser
def update(self):
self.rect.y -= 1
class LaserFactory(object):
def __init__(self, screen, image):
self.moving_lasers = pygame.sprite.Group()
self.screen = screen
self.image = image
def NewLaser(self, x, y):
new_laser = Laser(self.screen, self.image, x, y)
self.moving_lasers.add(new_laser)
def getLasers(self):
return self.moving_lasers