yo
This commit is contained in:
commit
a8ee8bad99
7 files changed
+458
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import sys
|
||||
import pygame
|
||||
from moon import Moon
|
||||
|
||||
|
||||
class Apollo(Moon):
|
||||
def __init__(self, moon: Moon, distance: float = 40.0, radius: int = 5):
|
||||
# Geschwindigkeit: doppelt so schnell wie der Mond, aber entgegengesetzte Richtung (-2 * moon.speed)
|
||||
speed = -2.0 * moon.speed
|
||||
self.moon = moon
|
||||
# Initialisierung über super(): Farbe rot, kleinerer Radius
|
||||
super().__init__(
|
||||
center=(moon.x, moon.y),
|
||||
distance=distance,
|
||||
speed=speed,
|
||||
radius=radius,
|
||||
color=(255, 0, 0), # Roter Kreis
|
||||
)
|
||||
|
||||
|
||||
def update_position(self) -> None:
|
||||
"""
|
||||
Aktualisiert das dynamische Drehzentrum (Mondposition)
|
||||
und ruft anschließend die Positionsberechnung von Moon auf.
|
||||
"""
|
||||
# Drehzentrum ist der aktuelle Mittelpunkt des Mondes
|
||||
self.center = (self.moon.x, self.moon.y)
|
||||
|
||||
# Verwendet die bestehende Logik der Basisklasse Moon
|
||||
super().update_position()
|
||||
|
||||
|
||||
def main():
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode((800, 600))
|
||||
pygame.display.set_caption("Mond- und Apollo-Simulation")
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
earth_pos = (400, 300)
|
||||
moon = Moon(center=earth_pos, distance=180.0, speed=0.015, radius=16)
|
||||
apollo = Apollo(moon=moon, distance=45.0, radius=5)
|
||||
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
|
||||
# Erst Mond aktualisieren, dann Apollo (da Apollo auf die Mond-Position zugreift)
|
||||
moon.update_position()
|
||||
apollo.update_position()
|
||||
|
||||
# Render-Schritt
|
||||
screen.fill((10, 10, 25))
|
||||
|
||||
# Erde
|
||||
pygame.draw.circle(screen, (40, 120, 230), earth_pos, 40)
|
||||
|
||||
# Mond und Kapsel zeichnen
|
||||
moon.draw(screen)
|
||||
apollo.draw(screen)
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick(60)
|
||||
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user