From 563c9a1ef6429464f9eff5f756b2aa1897b1bfbe Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 28 Apr 2015 12:20:15 +0100 Subject: [PATCH] Added file for target --- target.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 target.py diff --git a/target.py b/target.py new file mode 100644 index 0000000..3607e46 --- /dev/null +++ b/target.py @@ -0,0 +1,21 @@ +import pygame + +class Target(pygame.sprite.Sprite): + def __init__(self, color=(30,0,150), width=16, height=16): + super().__init__() + self.width = width + self.height = height + self.image = pygame.Surface((self.width, self.height)) + self.image.fill(color) + self.rect = self.image.get_rect() + self.speed = 4 + + def set_position(self,x,y): + self.rect.x, self.rect.y = (x+(self.width/2)),(x+(self.width/2)) # centres co-ordinates + + def move(self, x,y): + if ((self.rect.y + self.width) > window_rect.y) or((self.rect.y - self.width < 0)): + movement = self.speed + else: + movement = -self.speed + self.rect.y += movement