import pygame from compute import matmul, rot_2D from game import Game EARTH_RADIUS = 30 MOON_RADIUS = 10 MOON_DISTANCE = 100.0 theta = 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) # Ruft Konstruktor von Game auf self.center_x = size[0] // 2 self.center_y = size[1] // 2 # Center position von Erde self.init_positions() def init_positions(self): self.position_moon = (MOON_DISTANCE, 0.0) self.rot_moon = rot_2D(theta) 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()