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
@@ -15,53 +15,53 @@ class Moon(Game):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str = "Moon",
|
||||
title: str = "Moon & Apollo",
|
||||
fps: int = 60,
|
||||
size: tuple[int, int] = (640, 400),
|
||||
) -> None:
|
||||
"""Legt Startposition, Drehwinkel und Rotationsmatrix fest."""
|
||||
"""Legt Startposition, Drehwinkel und Rotationsmatrix für den Mond fest."""
|
||||
super().__init__(title, fps, size)
|
||||
|
||||
# Kleiner Drehwinkel im Bogenmaß und zugehörige Rotationsmatrix
|
||||
theta = 0.01
|
||||
self.rot_moon = rot_2D(theta)
|
||||
|
||||
# Startposition des Mondes als relativer Abstand zur Erde (z. B. 120 Pixel nach rechts)
|
||||
# Mond-Parameter
|
||||
self.theta_moon = 0.01
|
||||
self.rot_moon = rot_2D(self.theta_moon)
|
||||
self.position_moon = (120.0, 0.0)
|
||||
|
||||
def update_game(self) -> bool:
|
||||
"""Dreht den Mond ein Stück weiter."""
|
||||
# 1. Position in Spaltenvektor [[x], [y]] umwandeln
|
||||
point = transpose([list(self.position_moon)])
|
||||
|
||||
# 2. Mit der Rotationsmatrix multiplizieren
|
||||
result = matmul(self.rot_moon, point)
|
||||
|
||||
# 3. Ergebnis zurück in ein Tupel konvertieren und speichern
|
||||
self.position_moon = (result[0][0], result[1][0])
|
||||
|
||||
"""Aktualisiert die Positionen aller Himmelskörper."""
|
||||
self.update_moon()
|
||||
return True
|
||||
|
||||
def update_moon(self) -> None:
|
||||
"""Dreht den Mond ein Stück weiter um die Erde."""
|
||||
point = transpose([list(self.position_moon)])
|
||||
result = matmul(self.rot_moon, point)
|
||||
self.position_moon = (result[0][0], result[1][0])
|
||||
|
||||
def draw_game(self) -> None:
|
||||
"""Zeichnet Erde und Mond."""
|
||||
# Bildschirm mit Schwarz füllen
|
||||
"""Zeichnet den Hintergrund, die Erde und den Mond."""
|
||||
self.screen.fill(BLACK)
|
||||
|
||||
# Fenstermittelpunkt ermitteln, damit die Erde exakt in der Mitte sitzt
|
||||
center_x = self.size[0] // 2
|
||||
center_y = self.size[1] // 2
|
||||
|
||||
# Erde als blauen Kreis in der Mitte zeichnen
|
||||
# Erde zeichnen
|
||||
pygame.draw.circle(self.screen, BLUE, (center_x, center_y), EARTH_RADIUS)
|
||||
|
||||
# Mondposition relativ zum Mittelpunkt berechnen und zeichnen
|
||||
# Mond zeichnen
|
||||
moon_x = int(center_x + self.position_moon[0])
|
||||
moon_y = int(center_y + self.position_moon[1])
|
||||
pygame.draw.circle(self.screen, WHITE, (moon_x, moon_y), MOON_RADIUS)
|
||||
|
||||
# Anzeige aktualisieren
|
||||
# Hier können Unterklassen (wie Apollo) weiteres Zeichnen anhängen
|
||||
self.draw_objects(center_x, center_y)
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
def draw_objects(self, center_x: int, center_y: int) -> None:
|
||||
"""Erweiterungspunkt für Unterklassen, um zusätzliche Objekte zu zeichnen."""
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Moon()
|
||||
|
||||
Reference in new issue
Block a user