Files
2026-10-19 20:29:13 +02:00

58 lines
1.2 KiB
Python

import pygame
WIDTH = 800
HEIGHT= 600
SIZE = (WIDTH, HEIGHT)
RED = (255, 0, 0)
CIRCLE_RADIUS = 10
BLACK = (0, 0, 0)
FPS = 60
def main():
screen = init_game()
game_loop(screen)
exit_game()
def init_game():
global position
global clock
clock = pygame.time.Clock()
position = (WIDTH // 2, HEIGHT // 2)
pygame.init()
return pygame.display.set_mode(SIZE)
def game_loop(screen):
while True:
if not event_handling():
break
if not update_game():
break
event = event_handling()
draw_game(screen)
clock.tick(FPS)
def event_handling():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
return True
def update_game():
global new_pos
mouse_pos = pygame.mouse.get_pos()
delta_x = mouse_pos[0] - position[0]
delta_y = mouse_pos[1] - position[1]
acceleration = delta_x / WIDTH, delta_y / HEIGHT
new_pos = (mouse_pos[0] + acceleration[0], mouse_pos[1] + acceleration[1])
clock.tick(FPS)
return True
def draw_game(screen):
screen.fill(BLACK)
pygame.draw.circle(screen, RED, new_pos, CIRCLE_RADIUS)
pygame.display.flip()
def exit_game():
pygame.quit()
main()