Last active
November 8, 2018 16:32
-
-
Save aoloe/86aaf7c1ec859287c24b90e4729c1ca7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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