MoonGame/moon.py
2025-11-04 12:40:22 +01:00

43 lines
1.5 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 dotenv import load_dotenv
import os
load_dotenv() # lädt .env beim Start
import math
import pygame
from compute import rotation_matrix, apply_mat_to_vec, add
from game import Game
class Moon(Game):
def __init__(self):
#.env
width = int(os.getenv("WINDOW_WIDTH", "800"))
height = int(os.getenv("WINDOW_HEIGHT", "600"))
fps = int(os.getenv("FPS", "60"))
super().__init__(width, height, fps, title="Moon Orbit Demo")
self.center = (width // 2, height // 2) #mittelpunlt
self.earth_radius = 32 #Darstellung
self.moon_radius = 12
self.orbit_radius = int(os.getenv("ORBIT_RADIUS", "160")) # neu
self.angular_speed = float(os.getenv("ANGULAR_SPEED", "0.8")) # neu
self.angle = 0.0
self.bg_color = (10, 10, 25)
self.earth_color = (60, 120, 255)
self.moon_color = (245, 245, 245)
def update(self, dt: float) -> None:
self.angle = (self.angle + self.angular_speed * dt) % (2 * math.pi)
def draw(self, screen: pygame.Surface) -> None:
screen.fill(self.bg_color)
pygame.draw.circle(screen, self.earth_color, self.center, self.earth_radius) #Erde
v0 = (float(self.orbit_radius), 0.0) #start
R = rotation_matrix(self.angle) #rotierter vektor
v_rot = apply_mat_to_vec(R, v0)
pos = add(self.center, v_rot)
pygame.draw.circle(screen, self.moon_color, (int(pos[0]), int(pos[1])), self.moon_radius) #mOnd zeichenn
if __name__ == "__main__":
Moon().run()