Moon-Simulation aktualisiert und apollo-simulation hinzugefügt
This commit is contained in:
1 parent
17bf515f39
commit
bdbf024154
2 files changed
+79
-23
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import pygame
|
||||
|
||||
from compute import matmul, rot_2D, transpose
|
||||
from moon import Moon
|
||||
|
||||
RED = (255, 0, 0)
|
||||
APOLLO_RADIUS = 4
|
||||
|
||||
|
||||
class Apollo(Moon):
|
||||
"""Die Raumkapsel Apollo kreist um den Mond."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str = "Apollo Mission",
|
||||
fps: int = 60,
|
||||
size: tuple[int, int] = (640, 400),
|
||||
) -> None:
|
||||
"""Initialisiert Mond und zusätzlich die Apollo-Parameter."""
|
||||
super().__init__(title, fps, size)
|
||||
|
||||
# Doppelte Winkelgeschwindigkeit und entgegengesetzte Richtung (negatives Vorzeichen)
|
||||
theta_apollo = -2 * self.theta_moon
|
||||
self.rot_apollo = rot_2D(theta_apollo)
|
||||
|
||||
# Startposition relativ zum Mond (z. B. 35 Pixel Abstand)
|
||||
self.position_apollo_rel = (35.0, 0.0)
|
||||
|
||||
def update_game(self) -> bool:
|
||||
"""Aktualisiert sowohl den Mond als auch Apollo."""
|
||||
super().update_game()
|
||||
|
||||
# Apollos relative Position zum Mond weiterdrehen
|
||||
point = transpose([list(self.position_apollo_rel)])
|
||||
result = matmul(self.rot_apollo, point)
|
||||
self.position_apollo_rel = (result[0][0], result[1][0])
|
||||
|
||||
return True
|
||||
|
||||
def draw_objects(self, center_x: int, center_y: int) -> None:
|
||||
"""Zeichnet Apollo relativ zur aktuellen Mondposition."""
|
||||
# Mond-Absolutposition im Fenster
|
||||
moon_x = center_x + self.position_moon[0]
|
||||
moon_y = center_y + self.position_moon[1]
|
||||
|
||||
# Apollo-Absolutposition (Mondposition + relative Apollo-Position)
|
||||
apollo_x = int(moon_x + self.position_apollo_rel[0])
|
||||
apollo_y = int(moon_y + self.position_apollo_rel[1])
|
||||
|
||||
# Apollo als roten Kreis zeichnen
|
||||
pygame.draw.circle(self.screen, RED, (apollo_x, apollo_y), APOLLO_RADIUS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Apollo()
|
||||
app.run()
|
||||
Reference in new issue
Block a user