Files
matrixmania/apollo.py
T
2026-10-22 11:49:07 +02:00

50 lines
1.6 KiB
Python

import pygame
from compute import matmul, rot_2D, transpose
from Moon import Moon
RED = (255, 0, 0)
BLACK = (0, 0, 0)
APOLLO_RADIUS = 3
class Apollo(Moon):
def __init__(
self,
title: str = "Apollo",
fps: int = 60,
size: tuple[int, int] = (640, 400),
) -> None:
super().__init__(title, fps, size) #Startpos. des Mondes wird hier übergeben
self.position_apollo = [0.0, -40.0] #Startposition von Apollo relativ zum Mond
theta_apollo = -0.02 #doppelte Geschwindigkeit, umgekehrte Drehrichtung
self.rot_apollo = rot_2D(theta_apollo)
def update_game(self) -> bool:
super().update_game()
point = transpose([self.position_apollo]) #macht aus Koordinatenliste Spaltenvektor
result = matmul(self.rot_apollo, point) #neue relative Pos. berechnen
self.position_apollo = [result[0][0], result[1][0]] #Matrix: erste Zeile: erstes Element, zweite Zeile: erstes Element
return True
def draw_game(self) -> None:
self.screen.fill(BLACK)
self.draw_earth()
self.draw_moon()
self.draw_apollo()
pygame.display.flip()
def draw_apollo(self) -> None:
apollo_x = int(self.centre[0] + self.position_moon[0] + self.position_apollo[0]) #Absolute Position = Bildschirmmitte + Mond-Position + Apollo-Relativposition
apollo_y = int(self.centre[1] + self.position_moon[1] + self.position_apollo[1])
pygame.draw.circle(self.screen, RED, (apollo_x, apollo_y), APOLLO_RADIUS)
if __name__ == "__main__":
game = Apollo()
game.run()