From 1dd1205cb494f8e2acb0f6d2055d3de9de7cd2ab Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 6 May 2015 09:52:28 +0100 Subject: [PATCH] added target movement, and added dropping. --- target.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/target.py b/target.py index 3607e46..b159529 100644 --- a/target.py +++ b/target.py @@ -1,21 +1,19 @@ import pygame class Target(pygame.sprite.Sprite): - def __init__(self, color=(30,0,150), width=16, height=16): + def __init__(self, x, y, 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 + self.speed = 10 + self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates + + def move(self): + self.rect.x += self.speed + + def drop(self): + self.rect.y += 20 + self.speed *= -1