Apollo Hausi
This commit is contained in:
1 parent
a3ec69b681
commit
863bb21df7
4 files changed
+97
-11
No files matched your search
+45
-11
@@ -1,12 +1,46 @@
|
|||||||
Apollo (P)
|
from Moon import Moon
|
||||||
Nun wollen wir unsere Animation um die Raumkapsel Apollo
|
from Praktikumsaufgaben.matrixmania.compute import rot_2D, matmul, transpose
|
||||||
erweitern, die gerade um den Mond kreist. Sie bewegt sich mit der
|
import pygame
|
||||||
doppelten Winkelgeschwindigkeit wie der Mond und in
|
class Apollo(Moon):
|
||||||
entgegengesetzter Drehrichtung. Die Raumkapsel soll als roter
|
def __init__(self) -> None:
|
||||||
Kreis dargestellt werden.
|
super().__init__() #ruft den konstruktor auf vom moon
|
||||||
Implementieren Sie eine Klasse Apollo als Unterklasse der Klasse
|
|
||||||
Moon aus der vorherigen Aufgabe, die diese Animation realisiert. Wenn Sie feststellen, dass Ihre bisherige Klasse
|
|
||||||
Moon nicht geeignet erweitert werden kann, dann bauen Sie Moon bitte entsprechend um, so dass sie das
|
|
||||||
Open/Closed-Principle erfüllt. Natürlich muss die reine Mond-Simulation weiterhin funktionieren. Wählen Sie die
|
|
||||||
Abstände und Größen wieder so, dass die Animation ansprechend aussieht.
|
|
||||||
|
|
||||||
|
self.position_apollo = (30, 0) #koordinaten sind somit relativ zum moon und nicht zum mittelpunkt
|
||||||
|
self.theta_apollo = -2 * self.theta
|
||||||
|
self.rot_apollo = rot_2D(self.theta_apollo) #doppelt so schnell und in die ntgegengesetzte richtung
|
||||||
|
def update_game(self) -> bool:
|
||||||
|
super().update_game()
|
||||||
|
point = transpose([list(self.position_apollo)])
|
||||||
|
result = matmul(self.rot_apollo, point) #apollo wird mit dr rotationsmatrix gedreht
|
||||||
|
self.position_apollo = (result[0][0], result[1][0]) #koordinaten werden gespeichert
|
||||||
|
return True
|
||||||
|
def draw_game(self):
|
||||||
|
super().draw_game()
|
||||||
|
|
||||||
|
center_x = self.size[0] // 2 #mittelpunkt bestimmen
|
||||||
|
center_y = self.size[1] // 2
|
||||||
|
|
||||||
|
apollo_x = ( #Relative Apollo Position
|
||||||
|
center_x
|
||||||
|
+ self.position_moon[0]
|
||||||
|
+ self.position_apollo[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
apollo_y = (
|
||||||
|
center_y
|
||||||
|
+ self.position_moon[1]
|
||||||
|
+ self.position_apollo[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
pygame.draw.circle(
|
||||||
|
self.screen,
|
||||||
|
(255, 0, 0),
|
||||||
|
(int(apollo_x), int(apollo_y)),
|
||||||
|
5
|
||||||
|
)
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
apollo = Apollo()
|
||||||
|
apollo.run()
|
||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,52 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
"""Basisklasse für Pygame-Spiele."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
title: str = "Game",
|
||||||
|
fps: int = 60,
|
||||||
|
size: tuple[int, int] = (640, 400),
|
||||||
|
) -> None:
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
self.title = title
|
||||||
|
self.fps = fps
|
||||||
|
self.size = size
|
||||||
|
|
||||||
|
self.screen = pygame.display.set_mode(size)
|
||||||
|
pygame.display.set_caption(title)
|
||||||
|
|
||||||
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
def update_game(self) -> bool:
|
||||||
|
"""Aktualisiert den Spielzustand."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
def draw_game(self) -> None:
|
||||||
|
"""Zeichnet das Spiel."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
"""Startet die Spielschleife."""
|
||||||
|
|
||||||
|
running = True
|
||||||
|
|
||||||
|
while running:
|
||||||
|
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
if running:
|
||||||
|
running = self.update_game()
|
||||||
|
|
||||||
|
if running:
|
||||||
|
self.draw_game()
|
||||||
|
|
||||||
|
self.clock.tick(self.fps)
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
Reference in new issue
Block a user