Apollo, Game hinzugefügt und Moon überarbeitet

This commit is contained in:
MaaaartinTH committed 2026-10-22 11:34:20 +02:00
1 parent 090453d4aa
commit 9d1ebda660
3 files changed
+157

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
import pygame
from compute import matmul, rot_2D
from game import Game
EARTH_RADIUS = 30
MOON_RADIUS = 10
MOON_DISTANCE = 100.0
MOON_ANGLE = 0.01
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
GRAY = (200, 200, 200)
class Moon(Game):
"""Der Mond kreist um die Erde."""
def __init__(self, title="Moon", fps=60, size=(640, 400)):
super().__init__(title, fps, size)
self.center_x = size[0] // 2
self.center_y = size[1] // 2
self.init_positions()
def init_positions(self):
self.position_moon = (MOON_DISTANCE, 0.0)
self.rot_moon = rot_2D(MOON_ANGLE)
def rotate_point(self, position, rotation):
result = matmul(rotation, [[position[0]], [position[1]]])
return (result[0][0], result[1][0])
def update_game(self):
self.update_positions()
return True
def update_positions(self):
self.position_moon = self.rotate_point(self.position_moon, self.rot_moon)
def to_screen(self, position):
return (int(self.center_x + position[0]), int(self.center_y + position[1]))
def draw_game(self):
self.screen.fill(BLACK)
self.draw_scene()
pygame.display.flip()
def draw_scene(self):
self.draw_earth()
self.draw_moon()
def draw_earth(self):
pygame.draw.circle(
self.screen, BLUE, (self.center_x, self.center_y), EARTH_RADIUS
)
def draw_moon(self):
pygame.draw.circle(
self.screen, GRAY, self.to_screen(self.position_moon), MOON_RADIUS
)
if __name__ == "__main__":
Moon().run()