You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
732 B
25 lines
732 B
import pygame as pg
|
|
from sprite import Sprite
|
|
|
|
GREEN = (0,255,0)
|
|
|
|
class Gem(Sprite):
|
|
RADIUS = 10
|
|
def __init__(self, pos):
|
|
size = (2*self.RADIUS,)*2
|
|
super().__init__(size)
|
|
rpos = (pos[0]- self.RADIUS, pos[1] - self.RADIUS)
|
|
self.map_rect = pg.Rect(rpos, size)
|
|
self.pos = pg.math.Vector2(pos)
|
|
pg.draw.circle(self.image, GREEN, (self.RADIUS,)*2, self.RADIUS)
|
|
|
|
|
|
def update(self, map_rect):
|
|
self.rect.x = self.pos.x - map_rect.x - self.RADIUS
|
|
self.rect.y = self.pos.y - map_rect.y - self.RADIUS
|
|
|
|
def collide_ship(self, ship):
|
|
rel_pos = self.pos - ship.map_rect.center
|
|
if rel_pos.length() < ship.SIZE/2 + self.RADIUS:
|
|
self.kill()
|
|
|
|
|