diff --git a/.env b/.env index e69de29..700bd73 100644 --- a/.env +++ b/.env @@ -0,0 +1,5 @@ +WINDOW_WIDTH=800 +WINDOW_HEIGHT=600 +FPS=60 +ORBIT_RADIUS=160 +ANGULAR_SPEED=0.8 diff --git a/apollo.py b/apollo.py index 642cf93..2bc2e39 100644 --- a/apollo.py +++ b/apollo.py @@ -1,40 +1,23 @@ -# apollo.py from moon import Moon from compute import rotation_matrix, apply_mat_to_vec, add import pygame import math class Apollo(Moon): - """ - Erweiterung der Moon-Klasse: - Zeigt zusätzlich ein Raumschiff (Apollo), das die Erde umkreist. - """ - def __init__(self): - # Ruft alles aus Moon.__init__ auf → Fenster, Farben, Erde, Mond - super().__init__() - - # Neue Eigenschaften nur für Apollo + super().__init__() #Fenster self.ship_radius = 6 self.ship_distance = self.orbit_radius + 40 # etwas weiter außen - self.ship_color = (255, 180, 0) # orange-gelb (Rakete) + self.ship_color = (255, 180, 0) def draw(self, screen: pygame.Surface) -> None: - # 1️⃣ Alles aus Moon zeichnen (Erde + Mond) super().draw(screen) - - # 2️⃣ Dann die Rakete dazuzeichnen v0 = (float(self.ship_distance), 0.0) - - # leicht andere Drehgeschwindigkeit - R = rotation_matrix(self.angle * 1.3) + R = rotation_matrix(self.angle * 1.3) #geschwindigkeit v_rot = apply_mat_to_vec(R, v0) pos = add(self.center, v_rot) - - # Raumschiff zeichnen (kleiner Kreis) pygame.draw.circle(screen, self.ship_color, (int(pos[0]), int(pos[1])), self.ship_radius) -# wenn du apollo.py startest if __name__ == "__main__": Apollo().run() diff --git a/moon.py b/moon.py index 12f6424..d1d0600 100644 --- a/moon.py +++ b/moon.py @@ -1,57 +1,42 @@ -# moon.py +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 # <- euer Framework aus Semester 1 +from game import Game class Moon(Game): - """ - Animation: Blauer Kreis (Erde) im Ursprung, weißer Kreis (Mond) kreist darum. - Mathe (Rotation etc.) liegt komplett in compute.py. - """ - def __init__(self, width: int = 800, height: int = 600, fps: int = 60): + 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") - - # „Ursprung“ = Bildschirmmitte (damit Erde bei (0,0) in unserer Welt liegt) - self.center = (width // 2, height // 2) - - # Darstellung - self.earth_radius = 32 - self.moon_radius = 12 - self.orbit_radius = 160 # Abstand Erde–Mond in Pixeln (optisch ansprechend) - - # Bewegung - self.angular_speed = 0.8 # rad/s (Geschwindigkeit der Umlaufbahn) - self.angle = 0.0 # aktueller Winkel in rad - - # Farben - self.bg_color = (10, 10, 25) - self.earth_color = (60, 120, 255) # blau - self.moon_color = (245, 245, 245) # weiß + 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: - """Zeitentwicklung: Winkel erhöhen (dt in Sekunden).""" self.angle = (self.angle + self.angular_speed * dt) % (2 * math.pi) def draw(self, screen: pygame.Surface) -> None: - """Szene rendern.""" screen.fill(self.bg_color) - - # Erde im „Ursprung“ (hier: Bildschirmmitte) - pygame.draw.circle(screen, self.earth_color, self.center, self.earth_radius) - - # Startvektor des Mondes (auf x-Achse, Länge = orbit_radius) - v0 = (float(self.orbit_radius), 0.0) - - # Rotierter Vektor: v = R(angle) * v0 - R = rotation_matrix(self.angle) + 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) - - # In Bildschirmkoordinaten verschieben: (0,0) Welt -> center Screen pos = add(self.center, v_rot) - - # Mond zeichnen - pygame.draw.circle(screen, self.moon_color, (int(pos[0]), int(pos[1])), self.moon_radius) + pygame.draw.circle(screen, self.moon_color, (int(pos[0]), int(pos[1])), self.moon_radius) #mOnd zeichenn if __name__ == "__main__": Moon().run() diff --git a/requirements.txt b/requirements.txt index e69de29..2d0d32a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,3 @@ +pygame + +python-dotenv