Skip to content

Instantly share code, notes, and snippets.

@WierQ
Created April 19, 2021 06:18
Show Gist options
  • Save WierQ/c9f2ecd73127a1e99f3539d95b2ca07a to your computer and use it in GitHub Desktop.
Save WierQ/c9f2ecd73127a1e99f3539d95b2ca07a to your computer and use it in GitHub Desktop.
Now I have added colors!
import pygame, sys
pygame.init()
screen = pygame.display.set_mode((1366, 768))
box = pygame.Rect(2.5, 2.5, 5, 5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
sys.exit(0)
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
screen.fill((0, 0, 0))
if pygame.key.get_pressed() [pygame.K_d]:
box.x += 1
if pygame.key.get_pressed() [pygame.K_a]:
box.x -= 1
if pygame.key.get_pressed() [pygame.K_w]:
box.y -= 1
if pygame.key.get_pressed() [pygame.K_s]:
box.y += 1
if pygame.key.get_pressed() [pygame.K_b]:
pygame.draw.rect(screen,(3, 252, 248), box)
if pygame.key.get_pressed() [pygame.K_g]:
pygame.draw.rect(screen,(53, 252, 3), box)
if pygame.key.get_pressed() [pygame.K_r]:
pygame.draw.rect(screen,(252, 3, 3), box)
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment