Facebook
From donantonnio1, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 386
  1. import pygame, sys
  2.  
  3. pygame.init()
  4. screen = pygame.display.set_mode((1024,600))
  5. box = pygame.Rect(10, 10, 50, 50)
  6. print(type(box))
  7. while True:
  8.  
  9.     # Handle events
  10.     for event in pygame.event.get():
  11.         if event.type == pygame.QUIT:
  12.             sys.exit(0)
  13.        
  14.     # Checking input
  15.     if pygame.key.get_pressed()[pygame.K_d]:
  16.         box.x += 1
  17.     if pygame.key.get_pressed()[pygame.K_a]:
  18.         box.x -= 1
  19.     if pygame.key.get_pressed()[pygame.K_s]:
  20.         box.y += 1
  21.     if pygame.key.get_pressed()[pygame.K_w]:
  22.         box.y -= 1
  23.  
  24.     # Drawing
  25.     screen.fill((0, 0, 0))
  26.     pygame.draw.rect(screen, (100 ,200, 120), box)
  27.     pygame.display.flip()