apollo uploud
This commit is contained in:
parent
00c2390bbf
commit
4bc6b8d9b8
5
.env
5
.env
@ -0,0 +1,5 @@
|
|||||||
|
WINDOW_WIDTH=800
|
||||||
|
WINDOW_HEIGHT=600
|
||||||
|
FPS=60
|
||||||
|
ORBIT_RADIUS=160
|
||||||
|
ANGULAR_SPEED=0.8
|
||||||
23
apollo.py
23
apollo.py
@ -1,40 +1,23 @@
|
|||||||
# apollo.py
|
|
||||||
from moon import Moon
|
from moon import Moon
|
||||||
from compute import rotation_matrix, apply_mat_to_vec, add
|
from compute import rotation_matrix, apply_mat_to_vec, add
|
||||||
import pygame
|
import pygame
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class Apollo(Moon):
|
class Apollo(Moon):
|
||||||
"""
|
|
||||||
Erweiterung der Moon-Klasse:
|
|
||||||
Zeigt zusätzlich ein Raumschiff (Apollo), das die Erde umkreist.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Ruft alles aus Moon.__init__ auf → Fenster, Farben, Erde, Mond
|
super().__init__() #Fenster
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
# Neue Eigenschaften nur für Apollo
|
|
||||||
self.ship_radius = 6
|
self.ship_radius = 6
|
||||||
self.ship_distance = self.orbit_radius + 40 # etwas weiter außen
|
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:
|
def draw(self, screen: pygame.Surface) -> None:
|
||||||
# 1️⃣ Alles aus Moon zeichnen (Erde + Mond)
|
|
||||||
super().draw(screen)
|
super().draw(screen)
|
||||||
|
|
||||||
# 2️⃣ Dann die Rakete dazuzeichnen
|
|
||||||
v0 = (float(self.ship_distance), 0.0)
|
v0 = (float(self.ship_distance), 0.0)
|
||||||
|
R = rotation_matrix(self.angle * 1.3) #geschwindigkeit
|
||||||
# leicht andere Drehgeschwindigkeit
|
|
||||||
R = rotation_matrix(self.angle * 1.3)
|
|
||||||
v_rot = apply_mat_to_vec(R, v0)
|
v_rot = apply_mat_to_vec(R, v0)
|
||||||
pos = add(self.center, v_rot)
|
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)
|
pygame.draw.circle(screen, self.ship_color, (int(pos[0]), int(pos[1])), self.ship_radius)
|
||||||
|
|
||||||
|
|
||||||
# wenn du apollo.py startest
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
Apollo().run()
|
Apollo().run()
|
||||||
|
|||||||
65
moon.py
65
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 math
|
||||||
import pygame
|
import pygame
|
||||||
from compute import rotation_matrix, apply_mat_to_vec, add
|
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):
|
class Moon(Game):
|
||||||
"""
|
def __init__(self):
|
||||||
Animation: Blauer Kreis (Erde) im Ursprung, weißer Kreis (Mond) kreist darum.
|
#.env
|
||||||
Mathe (Rotation etc.) liegt komplett in compute.py.
|
width = int(os.getenv("WINDOW_WIDTH", "800"))
|
||||||
"""
|
height = int(os.getenv("WINDOW_HEIGHT", "600"))
|
||||||
def __init__(self, width: int = 800, height: int = 600, fps: int = 60):
|
fps = int(os.getenv("FPS", "60"))
|
||||||
|
|
||||||
super().__init__(width, height, fps, title="Moon – Orbit Demo")
|
super().__init__(width, height, fps, title="Moon – Orbit Demo")
|
||||||
|
self.center = (width // 2, height // 2) #mittelpunlt
|
||||||
# „Ursprung“ = Bildschirmmitte (damit Erde bei (0,0) in unserer Welt liegt)
|
self.earth_radius = 32 #Darstellung
|
||||||
self.center = (width // 2, height // 2)
|
self.moon_radius = 12
|
||||||
|
self.orbit_radius = int(os.getenv("ORBIT_RADIUS", "160")) # neu
|
||||||
# Darstellung
|
self.angular_speed = float(os.getenv("ANGULAR_SPEED", "0.8")) # neu
|
||||||
self.earth_radius = 32
|
self.angle = 0.0
|
||||||
self.moon_radius = 12
|
self.bg_color = (10, 10, 25)
|
||||||
self.orbit_radius = 160 # Abstand Erde–Mond in Pixeln (optisch ansprechend)
|
self.earth_color = (60, 120, 255)
|
||||||
|
self.moon_color = (245, 245, 245)
|
||||||
# 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ß
|
|
||||||
|
|
||||||
def update(self, dt: float) -> None:
|
def update(self, dt: float) -> None:
|
||||||
"""Zeitentwicklung: Winkel erhöhen (dt in Sekunden)."""
|
|
||||||
self.angle = (self.angle + self.angular_speed * dt) % (2 * math.pi)
|
self.angle = (self.angle + self.angular_speed * dt) % (2 * math.pi)
|
||||||
|
|
||||||
def draw(self, screen: pygame.Surface) -> None:
|
def draw(self, screen: pygame.Surface) -> None:
|
||||||
"""Szene rendern."""
|
|
||||||
screen.fill(self.bg_color)
|
screen.fill(self.bg_color)
|
||||||
|
pygame.draw.circle(screen, self.earth_color, self.center, self.earth_radius) #Erde
|
||||||
# Erde im „Ursprung“ (hier: Bildschirmmitte)
|
v0 = (float(self.orbit_radius), 0.0) #start
|
||||||
pygame.draw.circle(screen, self.earth_color, self.center, self.earth_radius)
|
R = rotation_matrix(self.angle) #rotierter vektor
|
||||||
|
|
||||||
# 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)
|
|
||||||
v_rot = apply_mat_to_vec(R, v0)
|
v_rot = apply_mat_to_vec(R, v0)
|
||||||
|
|
||||||
# In Bildschirmkoordinaten verschieben: (0,0) Welt -> center Screen
|
|
||||||
pos = add(self.center, v_rot)
|
pos = add(self.center, v_rot)
|
||||||
|
pygame.draw.circle(screen, self.moon_color, (int(pos[0]), int(pos[1])), self.moon_radius) #mOnd zeichenn
|
||||||
# Mond zeichnen
|
|
||||||
pygame.draw.circle(screen, self.moon_color, (int(pos[0]), int(pos[1])), self.moon_radius)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
Moon().run()
|
Moon().run()
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
pygame
|
||||||
|
|
||||||
|
python-dotenv
|
||||||
Loading…
x
Reference in New Issue
Block a user