A simple game made as a hobby. Use the mouse to control the starship and collect the gems. The faster you collect them the better. Needs pygame (2.1.2) to run.
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.
 

38 lines
1.2 KiB

import pygame as pg
from sprite import Sprite
SHAPE = [(6,3), (1,5), (2,3), (1,1)]
class Ship(Sprite):
SIZE = 40
COLOR =(255,0,0)
def __init__(self, pos, scr_rect):
super().__init__((self.SIZE,)*2)
self.map_pos = pg.math.Vector2(pos)
u = self.SIZE//6
self.shape = [pg.math.Vector2(p[0]*u,p[1]*u) for p in SHAPE]
self.rect.x = scr_rect.centerx - self.rect.width / 2
self.rect.y = scr_rect.centery - self.rect.height / 2
self.velocity = 0
self.deceleration = 0
self.direction = pg.math.Vector2((1,0))
self.change = pg.math.Vector2((0,0))
def update(self, rot_vector):
center = self.SIZE/2
def rotate(p):
x0 = p[0]-center
y0 = p[1]-center
x1 = x0 * rot_vector.x - y0 * rot_vector.y
y1 = x0 * rot_vector.y + y0 * rot_vector.x
return (x1 + center, y1 + center)
new_shape = list(map(rotate, self.shape))
self.image.fill(self.image.get_colorkey())
pg.draw.polygon(self.image, self.COLOR, new_shape)
@property
def map_rect(self):
return pg.Rect(
(self.map_pos.x-self.SIZE/2+1, self.map_pos.y-self.SIZE/2+1),
(self.SIZE-2, self.SIZE-2))