Skip to content

Instantly share code, notes, and snippets.

@ectrimble20
Created August 8, 2018 05:50
Show Gist options
  • Save ectrimble20/3777c7034c2c8115ae6be8c438cb2b37 to your computer and use it in GitHub Desktop.
Save ectrimble20/3777c7034c2c8115ae6be8c438cb2b37 to your computer and use it in GitHub Desktop.
Pygame Loop fix
import pygame
from pygame.locals import *
import sys
pygame.init()
pygame.display.set_caption('Test')
mouse = pygame.mouse
fps_clock = pygame.time.Clock()
width = 640
height = 480
window = pygame.display.set_mode((width, height))
BLACK = pygame.Color(0, 0, 0)
WHITE = pygame.Color(255, 255, 255)
window.fill(WHITE)
pygame.display.update()
x1 = 20
y1 = 20
running = True
while running:
keys = pygame.key.get_pressed() # checking pressed keys
window.fill(WHITE)
for event in pygame.event.get():
if event.type == QUIT:
running = False
if keys[pygame.K_w]:
y1 -= 1
if keys[pygame.K_s]:
y1 += 1
if keys[pygame.K_a]:
x1 -= 1
if keys[pygame.K_d]:
x1 += 1
pygame.draw.circle(window, BLACK, [x1, y1], 5)
pygame.display.update()
fps_clock.tick(60)
pygame.quit()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment