Apollo läuft!

This commit is contained in:
kreischeran103444 committed 2026-10-22 15:02:03 +02:00
1 parent ddaceeaffe
commit 93ee30229d
2 files changed
+54 -14

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
from __future__ import annotations
import pygame
from compute import rot_2D, matmul
from moon import Moon
# Apollo visual parameters
APOLLO_RADIUS = 2
APOLLO_COLOR = (255, 0, 0)
class Apollo(Moon):
def __init__(self, title: str = "Apollo", fps: int = 60, size: tuple[int, int] = (640, 400)) -> None:
super().__init__(title=title, fps=fps, size=size)
# Apollo starts on the positive x‑axis relative to the moon
self.offsetap: tuple[float, float] = (40.0, 0.0)
# Apollo moves twice as fast and opposite direction
self.delta_thetaap: float = -0.05
self.thetaap: float = 0.0
self.rot_apollo: list[list[float]] = rot_2D(self.theta)
def update_game(self) -> bool:
# Update moon first
super().update_game()
# Advance Apollo
self.thetaap += self.delta_thetaap
self.rot_apollo = rot_2D(self.thetaap)
point = [[self.offsetap[0]], [self.offsetap[1]]]
rel_pos = matmul(self.rot_apollo, point)
# Apollo's world position is moon's position plus relative vector
moon_pos = self.position_moon
self.position_apollo = (
moon_pos[0] + rel_pos[0][0],
moon_pos[1] + rel_pos[1][0],
)
return True
def draw_game(self) -> None:
# Draw base moon graphics
super().draw_game()
# Draw Apollo on the screen
pygame.draw.circle(
self.screen,
APOLLO_COLOR,
(int(self.position_apollo[0]), int(self.position_apollo[1])),
APOLLO_RADIUS,
)
if __name__ == "__main__":
apollo = Apollo()
apollo.run()