initial commit
This commit is contained in:
commit
39f56a3b10
83 files changed
+3583
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import pygame
|
||||
|
||||
WIDTH = 800
|
||||
HEIGHT= 600
|
||||
SIZE = (WIDTH, HEIGHT)
|
||||
RED = (255, 0, 0)
|
||||
CIRCLE_RADIUS = 10
|
||||
BLACK = (0, 0, 0)
|
||||
FPS = 120
|
||||
|
||||
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 position
|
||||
keys_pressed = pygame.key.get_pressed()
|
||||
if keys_pressed[pygame.K_UP]:
|
||||
position = (position[0], position[1] - 1)
|
||||
if keys_pressed[pygame.K_DOWN]:
|
||||
position = (position[0], position[1] + 1)
|
||||
if keys_pressed[pygame.K_LEFT]:
|
||||
position = (position[0] - 1, position[1])
|
||||
if keys_pressed[pygame.K_RIGHT]:
|
||||
position = (position[0] + 1, position[1])
|
||||
return True
|
||||
|
||||
def draw_game(screen):
|
||||
screen.fill(BLACK)
|
||||
pygame.draw.circle(screen, RED, position, CIRCLE_RADIUS)
|
||||
pygame.display.flip()
|
||||
|
||||
def exit_game():
|
||||
pygame.quit()
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user