import pygame from _game import Game from compute import Pi, cos, sin class Apollo(Game): """A small red circle orbiting the moon in the opposite direction.""" def __init__(self, earth_x, earth_y): super().__init__() self.center_x = earth_x self.center_y = earth_y # Moon orbit parameters self.moon_theta = 0.05 self.moon_orbit_radius = 80 self.moon_radius = 5 # Apollo orbit parameters (opposite direction) self.apollo_theta = -0.04 self.apollo_orbit_radius = 30 self.apollo_radius = 3 # Colors self.earth_color = (0, 0, 255) self.moon_color = (255, 255, 255) self.apollo_color = (255, 0, 0) self.screen = None def update_game(self): # Update moon angle self.moon_theta += 0.02 if self.moon_theta > 2 * Pi: self.moon_theta -= 2 * Pi # Calculate moon position moon_x = int(self.center_x + self.moon_orbit_radius * cos(self.moon_theta)) moon_y = int(self.center_y + self.moon_orbit_radius * sin(self.moon_theta)) # Update Apollo angle (opposite direction) self.apollo_theta -= 0.02 if abs(self.apollo_theta) > 2 * Pi: self.apollo_theta += 2 * Pi # Calculate Apollo position relative to moon apollo_x = int(moon_x + self.apollo_orbit_radius * cos(self.apollo_theta)) apollo_y = int(moon_y + self.apollo_orbit_radius * sin(self.apollo_theta)) # Draw everything screen = self.set_screen() screen.fill((0, 0, 0)) # Earth pygame.draw.circle(screen, self.earth_color, (self.center_x, self.center_y), 20) # Moon pygame.draw.circle(screen, self.moon_color, (moon_x, moon_y), self.moon_radius) # Apollo pygame.draw.circle(screen, self.apollo_color, (apollo_x, apollo_y), self.apollo_radius) pygame.display.flip() return True def draw_game(self): pass def main(): apollo = Apollo(250, 250) apollo.run() if __name__ == "__main__": main()