Add Apollo subclass extending Moon (Open/Closed Principle)
This commit is contained in:
parent
a2b388ed54
commit
00c2390bbf
40
apollo.py
Normal file
40
apollo.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# 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
|
||||||
|
self.ship_radius = 6
|
||||||
|
self.ship_distance = self.orbit_radius + 40 # etwas weiter außen
|
||||||
|
self.ship_color = (255, 180, 0) # orange-gelb (Rakete)
|
||||||
|
|
||||||
|
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)
|
||||||
|
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()
|
||||||
0
requirements.txt
Normal file
0
requirements.txt
Normal file
Loading…
x
Reference in New Issue
Block a user