Skip to content

Instantly share code, notes, and snippets.

@aoloe
Last active November 8, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoloe/86aaf7c1ec859287c24b90e4729c1ca7 to your computer and use it in GitHub Desktop.
Save aoloe/86aaf7c1ec859287c24b90e4729c1ca7 to your computer and use it in GitHub Desktop.
WIDTH = 640
HEIGHT = 480
BLACK = (0, 0, 0)
RED = (120, 0, 0)
box = Rect((100, 100), (100, 100), anchor=('left', 'top'))
player = Rect((300, 100), (100, 100), anchor=('left', 'top'))
def update(dt):
x = player.x
y = player.y
dx = 0
dy = 0
if keyboard.left:
dx = -100 * dt
elif keyboard.right:
dx = 100 * dt
elif keyboard.up:
dy = -100 * dt
elif keyboard.down:
dy = 100 * dt
if dx != 0 or dy != 0:
player.x += dx
player.y += dy
if player.colliderect(box):
player.x = x
player.y = y
def draw():
screen.fill((0, 128, 0))
screen.draw.filled_rect(box, BLACK)
screen.draw.filled_rect(player, RED)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment