Apollo unterklasse von Moon und dateien aus anderem Projekt hier zusammengefügt (game.py, apollo.py und moon.py)
This commit is contained in:
1 parent
959cfb4f1e
commit
a8901dae2f
5 files changed
+218
-1
No files matched your search
@@ -0,0 +1,47 @@
|
||||
"""Die Raumkapsel Apollo kreist um den Mond."""
|
||||
|
||||
import pygame
|
||||
|
||||
from compute import rot_2d
|
||||
from moon import MOON_RADIUS, Moon, Point
|
||||
|
||||
APOLLO_RADIUS = 4
|
||||
APOLLO_DISTANCE = MOON_RADIUS + 15 # Abstand Mond-Apollo (Mittelpunkte)
|
||||
RED = (255, 0, 0)
|
||||
|
||||
|
||||
class Apollo(Moon):
|
||||
"""Erweitert die Mond-Simulation um die Raumkapsel Apollo."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str = "Apollo",
|
||||
fps: int = 60,
|
||||
size: tuple[int, int] = (640, 400),
|
||||
) -> None:
|
||||
"""Legt Startposition und Rotationsmatrix von Apollo fest."""
|
||||
super().__init__(title, fps, size)
|
||||
self.position_apollo: Point = (APOLLO_DISTANCE, 0.0) # relativ zum Mond
|
||||
# doppelte Winkelgeschwindigkeit, entgegengesetzte Drehrichtung
|
||||
self.rot_apollo = rot_2d(-2 * self.theta, unit="rad")
|
||||
|
||||
def update_game(self) -> bool:
|
||||
"""Bewegt erst den Mond, dann Apollo."""
|
||||
running = super().update_game()
|
||||
self.position_apollo = self.rotate(self.position_apollo, self.rot_apollo)
|
||||
return running
|
||||
|
||||
def draw_bodies(self) -> None:
|
||||
"""Zeichnet Erde und Mond und zusätzlich Apollo."""
|
||||
super().draw_bodies()
|
||||
moon_x, moon_y = self.moon_screen_position()
|
||||
apollo_pos = (
|
||||
moon_x + self.position_apollo[0],
|
||||
moon_y + self.position_apollo[1],
|
||||
)
|
||||
pygame.draw.circle(self.screen, RED, apollo_pos, APOLLO_RADIUS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
apollo = Apollo()
|
||||
apollo.run()
|
||||
Reference in new issue
Block a user