58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
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() |