apollo Hausaufgabe
This commit is contained in:
1 parent
ba85e87473
commit
731b7c2a1d
3 files changed
+159
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import pygame
|
||||
|
||||
from compute import matmul, rot_2D, transpose
|
||||
from Moon import Moon
|
||||
|
||||
RED = (255, 0, 0)
|
||||
BLACK = (0, 0, 0)
|
||||
APOLLO_RADIUS = 3
|
||||
|
||||
|
||||
class Apollo(Moon):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str = "Apollo",
|
||||
fps: int = 60,
|
||||
size: tuple[int, int] = (640, 400),
|
||||
) -> None:
|
||||
|
||||
super().__init__(title, fps, size)
|
||||
|
||||
self.position_apollo = [0.0, -40.0] #Startposition von Apollo relativ zum Mond
|
||||
theta_apollo = -0.02 #doppelte Geschwindigkeit, umgekehrte Drehrichtung
|
||||
self.rot_apollo = rot_2D(theta_apollo)
|
||||
|
||||
def update_game(self) -> bool:
|
||||
super().update_game()
|
||||
|
||||
point = transpose([self.position_apollo]) #dreht sich um eigene Position
|
||||
result = matmul(self.rot_apollo, point)
|
||||
self.position_apollo = [result[0][0], result[1][0]] #Matrix: erste Zeile: erstes Element, zweite Zeile: zweites Element
|
||||
|
||||
return True
|
||||
|
||||
def draw_game(self) -> None:
|
||||
self.screen.fill(BLACK)
|
||||
self.draw_earth()
|
||||
self.draw_moon()
|
||||
self.draw_apollo()
|
||||
pygame.display.flip()
|
||||
|
||||
def draw_apollo(self) -> None:
|
||||
apollo_x = int(self.centre[0] + self.position_moon[0] + self.position_apollo[0]) #Absolute Position = Bildschirmmitte + Mond-Position + Apollo-Relativposition
|
||||
apollo_y = int(self.centre[1] + self.position_moon[1] + self.position_apollo[1])
|
||||
pygame.draw.circle(self.screen, RED, (apollo_x, apollo_y), APOLLO_RADIUS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
game = Apollo()
|
||||
game.run()
|
||||
Reference in new issue
Block a user