1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
attack-on-blocks/target.py

22 lines
736 B
Python
Raw Normal View History

2015-04-28 12:20:15 +01:00
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