apollo Hausaufgabe
This commit is contained in:
1 parent
ba85e87473
commit
731b7c2a1d
3 files changed
+159
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import pygame
|
||||
|
||||
from compute import matmul, rot_2D, transpose
|
||||
from game import Game
|
||||
|
||||
EARTH_RADIUS = 30
|
||||
MOON_RADIUS = 10
|
||||
BLACK = (0, 0, 0)
|
||||
WHITE = (255, 255, 255)
|
||||
BLUE = (0, 0, 255)
|
||||
|
||||
|
||||
class Moon(Game):
|
||||
"""Der Mond kreist um die Erde."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str = "Moon",
|
||||
fps: int = 60,
|
||||
size: tuple[int, int] = (640, 400),
|
||||
) -> None:
|
||||
"""Legt Startposition, Drehwinkel und Rotationsmatrix fest."""
|
||||
super().__init__(title, fps, size)
|
||||
self.centre = (size[0] // 2, size[1] // 2)
|
||||
|
||||
self.position_moon = [0.0, -150.0]
|
||||
|
||||
theta = 0.01
|
||||
self.rot_moon = rot_2D(theta)
|
||||
|
||||
def update_game(self) -> bool:
|
||||
"""Dreht den Mond ein Stück weiter."""
|
||||
self.update_moon_position()
|
||||
return True
|
||||
|
||||
def update_moon_position(self) -> None:
|
||||
point = transpose([self.position_moon]) # [x, y] wird zur Spalte [[x], [y]]
|
||||
result = matmul(self.rot_moon, point) # Ergebnis: [[x'], [y']]
|
||||
self.position_moon = [result[0][0], result[1][0]]
|
||||
|
||||
def draw_game(self) -> None:
|
||||
self.screen.fill(BLACK)
|
||||
self.draw_earth()
|
||||
self.draw_moon()
|
||||
pygame.display.flip()
|
||||
|
||||
def draw_earth(self) -> None:
|
||||
pygame.draw.circle(self.screen, BLUE, self.centre, EARTH_RADIUS)
|
||||
|
||||
def draw_moon(self) -> None:
|
||||
moon_x = int(self.centre[0] + self.position_moon[0])
|
||||
moon_y = int(self.centre[1] + self.position_moon[1])
|
||||
pygame.draw.circle(self.screen, WHITE, (moon_x, moon_y), MOON_RADIUS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
game = Moon()
|
||||
game.run()
|
||||
Reference in new issue
Block a user