Files
2026-10-22 15:02:03 +02:00

54 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()