2015-04-16 10:00:39 +01:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
|
|
class Shooter(pygame.sprite.Sprite):
|
2015-05-10 13:13:28 +01:00
|
|
|
def __init__(self, window, colour=(255,255,255), width=45, height=20):
|
2015-04-16 10:00:39 +01:00
|
|
|
super().__init__()
|
2015-04-29 09:48:37 +01:00
|
|
|
self.width = width
|
|
|
|
self.height = height
|
2015-05-10 13:13:28 +01:00
|
|
|
self.colour = colour
|
2015-04-16 10:00:39 +01:00
|
|
|
self.image = pygame.Surface((width, height))
|
2015-05-08 11:24:33 +01:00
|
|
|
self.image.fill(self.colour)
|
2015-04-16 10:00:39 +01:00
|
|
|
self.rect = self.image.get_rect()
|
2015-05-06 09:52:00 +01:00
|
|
|
self.speed = 3
|
2015-04-29 09:48:37 +01:00
|
|
|
self.window_rect = window.get_rect()
|
2015-05-09 23:55:14 +01:00
|
|
|
|
2015-05-06 09:52:00 +01:00
|
|
|
self.score = 0
|
2015-05-09 23:55:14 +01:00
|
|
|
self.OP = False
|
2015-05-07 19:43:09 +01:00
|
|
|
self.level = 0
|
|
|
|
self.lives = 3
|
2015-05-10 13:13:28 +01:00
|
|
|
self.powerup = ""
|
|
|
|
self.colours = [(255,0,0), (255,255,0), (0,255,0)]
|
2015-05-09 23:55:14 +01:00
|
|
|
|
2015-04-16 10:00:39 +01:00
|
|
|
def set_position(self,x,y):
|
|
|
|
self.rect.x, self.rect.y = x,y
|
|
|
|
|
2015-04-29 09:48:37 +01:00
|
|
|
def move(self, value):
|
|
|
|
self.rect.x += value
|
2015-05-08 11:24:33 +01:00
|
|
|
self.rect.clamp_ip(self.window_rect)
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.image.fill(self.colour)
|
2015-05-10 13:13:28 +01:00
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
|
|
|
|
def change_colour(self, colour):
|
|
|
|
x,y = self.rect.x, self.rect.y
|
|
|
|
self.image.fill(colour)
|
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
self.set_position(x,y)
|