parent
bd6a3f7492
commit
956b8cf83f
4 changed files with 75 additions and 37 deletions
@ -0,0 +1,31 @@ |
|||||||
|
import pygame as pg |
||||||
|
from sprite import Sprite |
||||||
|
|
||||||
|
SPEED = 4 |
||||||
|
COLOR = (255,0,0) |
||||||
|
SIZE = 12 |
||||||
|
LIFETIME = 60 |
||||||
|
|
||||||
|
class Torpedo(Sprite): |
||||||
|
COOLTIME = 15 |
||||||
|
|
||||||
|
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() |
Loading…
Reference in new issue