about summary refs log blame commit diff
path: root/src/gui/minimap_sprite.py
blob: fc71f9fbe229f4b8b3a7a123ea41e4e1c6d07263 (plain) (tree)


























                                                                                                                         
import math

import pygame
from pygame.locals import *

from simulation import Simulation

class Sprite_Minimap(pygame.sprite.Sprite):
    def __init__(self, simulation: type[Simulation], radius: int):
        super().__init__()
        self.simulation = simulation
        self.radius = radius

    def update(self, display_width, display_height):
        self.image = pygame.Surface([self.radius * 2, self.radius * 2], pygame.SRCALPHA)

        #body
        pygame.draw.circle(self.image, (0, 255, 0), (self.radius, self.radius), self.radius, width=2)
        
        #rocket position (TODO, show actual position in relation to surface. allow zoom?)
        normalized_x = math.sin(math.radians(self.simulation.angle_of_position_with_respect_to_origin())) * (self.radius)
        normalized_y = math.cos(math.radians(self.simulation.angle_of_position_with_respect_to_origin())) * (self.radius)
        normalized_rocket_pos = [self.radius + normalized_x, self.radius - normalized_y]
        pygame.draw.circle(self.image, (255, 0, 0), normalized_rocket_pos, 4)

        self.rect = self.image.get_rect()
        self.rect.topright = [display_width, 0]