ein docstring in moon eingefügt
apollo.py erstellt
This commit is contained in:
1 parent
0c59c96407
commit
a9ba1a66ce
2 files changed
+51
-1
No files matched your search
@@ -0,0 +1,48 @@
|
|||||||
|
"""Apollo kreist um den Mond."""
|
||||||
|
|
||||||
|
from compute import matvec, rot_2D
|
||||||
|
from moon import Moon
|
||||||
|
|
||||||
|
APOLLO_DIST = 60 # Abstand Mond -> Apollo
|
||||||
|
APOLLO_RADIUS = 5
|
||||||
|
RED = (255, 0, 0)
|
||||||
|
FAKTOR = -2 # doppelte Drehung, entgegengesetzte Richtung
|
||||||
|
|
||||||
|
|
||||||
|
class Apollo(Moon):
|
||||||
|
"""Apollo kreist doppelt so schnell und gegenläufig um den Mond."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
title: str = "Apollo",
|
||||||
|
fps: int = 60,
|
||||||
|
size: tuple[int, int] = (640, 400),
|
||||||
|
) -> None:
|
||||||
|
super().__init__(title, fps, size)
|
||||||
|
self.apollo_pos = self.apollo_startposition()
|
||||||
|
|
||||||
|
def apollo_startposition(self) -> list[float]:
|
||||||
|
"""Startposition von Apollo als Vektor relativ zum Mond."""
|
||||||
|
return [APOLLO_DIST, 0.0]
|
||||||
|
|
||||||
|
def drehe_apollo(self, vektor: list[float]) -> list[float]:
|
||||||
|
"""Dreht Apollo mit doppelter, gegenläufiger Winkelgeschwindigkeit."""
|
||||||
|
return matvec(rot_2D(FAKTOR * self.angle), vektor)
|
||||||
|
|
||||||
|
def update_game(self) -> bool:
|
||||||
|
super().update_game()
|
||||||
|
self.apollo_pos = self.drehe_apollo(self.apollo_pos)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def draw_space(self) -> None:
|
||||||
|
super().draw_space()
|
||||||
|
apollo_vektor = [
|
||||||
|
self.pos[0] + self.apollo_pos[0],
|
||||||
|
self.pos[1] + self.apollo_pos[1],
|
||||||
|
]
|
||||||
|
self.draw_body(self.absolut(apollo_vektor), APOLLO_RADIUS, RED)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
apollo = Apollo()
|
||||||
|
apollo.run()
|
||||||
@@ -56,7 +56,8 @@ class Moon(Game):
|
|||||||
self.draw_space()
|
self.draw_space()
|
||||||
self.display()
|
self.display()
|
||||||
|
|
||||||
def draw_space(self):
|
def draw_space(self) -> None:
|
||||||
|
"""Zeichnet Erde und Mond ohne die Anzeige zu aktualisieren."""
|
||||||
self.clear()
|
self.clear()
|
||||||
self.draw_earth()
|
self.draw_earth()
|
||||||
self.draw_body(self.absolut(self.pos), MOON_RADIUS, WHITE)
|
self.draw_body(self.absolut(self.pos), MOON_RADIUS, WHITE)
|
||||||
@@ -72,6 +73,7 @@ class Moon(Game):
|
|||||||
"""Zeichnet einen Himmelskörper an einer Position."""
|
"""Zeichnet einen Himmelskörper an einer Position."""
|
||||||
pygame.draw.circle(self.screen, farbe, pos, radius)
|
pygame.draw.circle(self.screen, farbe, pos, radius)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
moon = Moon()
|
moon = Moon()
|
||||||
moon.run()
|
moon.run()
|
||||||
Reference in new issue
Block a user