from __future__ import annotations import math from typing import Tuple, List import pygame # type: ignore from game import Game import compute from config import get_settings class Moon(Game): """Unterklasse von Game: Animation Mond-um-Erde mit .env-Konfiguration.""" def __init__(self) -> None: self.settings = get_settings() super().__init__( width=self.settings.width, height=self.settings.height, fps=self.settings.fps, title="Moon Orbit (env-configured)", ) self._theta: float = 0.0 self._center: Tuple[float, float] = (self.width / 2, self.height / 2) # Hooks def get_earth_center(self) -> Tuple[float, float]: return self._center def get_moon_angle(self) -> float: return self._theta def get_moon_orbit_radius(self) -> int: return self.settings.moon_orbit_radius def get_moon_position(self) -> Tuple[int, int]: theta = self.get_moon_angle() r = float(self.get_moon_orbit_radius()) rot: List[List[float]] = [ [math.cos(theta), -math.sin(theta)], [math.sin(theta), math.cos(theta)], ] vec: List[List[float]] = [[r], [0.0]] res = compute.matmul(rot, vec) cx, cy = self.get_earth_center() return int(cx + res[0][0]), int(cy + res[1][0]) def update(self, dt: float) -> None: omega = math.radians(self.settings.moon_angular_speed_deg) self._theta = (self._theta + omega * dt) % (2.0 * math.pi) def draw(self, surface: pygame.Surface) -> None: s = self.settings surface.fill(s.bg_color) ex, ey = self.get_earth_center() pygame.draw.circle(surface, s.earth_color, (int(ex), int(ey)), s.earth_radius) pygame.draw.circle(surface, (60, 60, 80), (int(ex), int(ey)), s.moon_orbit_radius, width=1) mx, my = self.get_moon_position() pygame.draw.circle(surface, s.moon_color, (mx, my), s.moon_radius) if __name__ == "__main__": Moon().run()