Files
prog3a/apollo.py
T
2026-10-15 17:09:26 +02:00

43 lines
1.6 KiB
Python

import pygame
from compute import matmul, rot_2D, transpose
from moon import Moon
# Colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)
class Apollo(Moon):
"""Die Raumkapsel Apollo kreist um den Mond"""
def __init__(self, title: str = "Apollo", fps: int = 60, size: tuple[int, int] = (640, 400)):
super().__init__(title, fps, size)
# Apollo orbit radius around the moon (relative to moon position)
self.apollo_radius = 30.0
# Initial position relative to moon
self.apollo_offset = (0.0, self.apollo_radius)
# Apollo angular speed: double moon speed, opposite direction
self.theta = -2 * self.rot_moon[0][0] # since rot_2D(theta) second element is cos=rot[0][0]
self.rot_apollo = rot_2D(self.theta)
def update_game(self) -> bool:
# First let the moon move
super().update_game()
# Rotate Apollo around the moon
point = transpose([list(self.apollo_offset)])
result = matmul(self.rot_apollo, point)
self.apollo_offset = (result[0][0], result[1][0])
return True
def draw_game(self) -> None:
# Draw background and Earth and Moon via super()
super().draw_game()
# Compute Apollo absolute position
moon_abs = (self.center[0] + self.position_moon[0], self.center[1] + self.position_moon[1])
apollo_pos = (int(moon_abs[0] + self.apollo_offset[0]), int(moon_abs[1] + self.apollo_offset[1]))
screen = pygame.display.get_surface()
pygame.draw.circle(screen, RED, apollo_pos, 5)
pygame.display.flip()
if __name__ == "__main__":
Apollo().run()