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

30 lines
873 B
Python
Raw Normal View History

2015-04-28 12:20:15 +01:00
import pygame
2015-05-11 22:15:40 +01:00
from random import randint
2015-04-28 12:20:15 +01:00
2015-05-07 19:50:57 +01:00
2015-04-28 12:20:15 +01:00
class Target(pygame.sprite.Sprite):
2015-05-11 22:15:40 +01:00
def __init__(self, x, y, textures, color=(30,0,150), width=16, height=16):
2015-04-28 12:20:15 +01:00
super().__init__()
self.width = width
self.height = height
2015-05-11 22:15:40 +01:00
self.image = pygame.transform.scale(textures.get_target_texture(), (self.width, self.height))
2015-04-28 12:20:15 +01:00
self.rect = self.image.get_rect()
2015-05-08 11:24:33 +01:00
self.speed = 7
self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates
2015-05-07 19:50:57 +01:00
self.type = "NORMAL"
def move(self):
self.rect.x += self.speed
def drop(self):
2015-05-08 11:24:33 +01:00
self.rect.y += 17
self.speed *= -1
2015-05-07 19:50:57 +01:00
2015-05-09 23:55:43 +01:00
def set_position(self, x, y, center=False):
if center:
self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2))
else:
self.rect.x, self.rect.y = x, y
2015-05-07 19:50:57 +01:00