A clone of Asteroids.
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.

31 lines
1.0 KiB

import pygame as pg
from .sprite import Sprite
SPEED = 6
COLOR = (255,0,0)
SIZE = 12
LIFETIME = 90
class Torpedo(Sprite):
COOLTIME = 10
def __init__(self, scr_rect, map_pos, direction, velocity):
super().__init__((SIZE,)*2)
self.rect.x = scr_rect.centerx - self.rect.width / 2
self.rect.y = scr_rect.centery - self.rect.height / 2
self.image.fill(self.image.get_colorkey())
pg.draw.circle(self.image, COLOR, self.image.get_rect().center, self.image.get_rect().width/2)
self.map_pos = pg.math.Vector2(map_pos)
self.velocity = pg.math.Vector2(direction) * SPEED + velocity
self.lifetime = LIFETIME
def update(self, map_rect):
self.map_pos += self.velocity
self.map_pos.x %= map_rect.w
self.map_pos.y %= map_rect.h
self.rect.x = (self.map_pos.x - self.rect.w/2 - map_rect.x) % map_rect.w
self.rect.y = (self.map_pos.y - self.rect.w/2 - map_rect.y) % map_rect.h
self.lifetime -= 1
if self.lifetime == 0:
self.kill()