Created
February 18, 2015 20:36
-
-
Save ejmurray/261ccc7359fd2228f5d4 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
#!/usr/bin/python | |
# encoding: utf-8 | |
""" | |
here is the docstring | |
""" | |
__author__ = 'Ernest' | |
import pygame | |
import sys | |
from pygame.locals import * | |
pygame.init() | |
background = pygame.image.load("sky.jpg") | |
w = background.get_rect().w | |
h = background.get_rect().h | |
screen = pygame.display.set_mode((50, 50)) | |
clock = pygame.time.Clock() | |
block = pygame.Surface((50, 50)) | |
green = Color(0, 250, 0) | |
block.fill(green) | |
x = 200 | |
y = 200 | |
xspeed = 0 | |
yspeed = 0 | |
xmoveflag = False | |
ymoveflag = False | |
while True: | |
clock.tick(30) | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
exit() | |
if event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_RIGHT: | |
xmoveflag = True | |
xspeed = 5 | |
if event.key == pygame.K_LEFT: | |
xmoveflag = True | |
xspeed = -5 | |
if event.key == pygame.K_UP: | |
ymoveflag = True | |
yspeed = -5 | |
if event.key == pygame.K_DOWN: | |
ymoveflag = True | |
yspeed = 5 | |
if event.type == pygame.KEYUP: | |
xmoveflag = False | |
ymoveflag = False | |
if xmoveflag == True: | |
x = x + xspeed | |
if ymoveflag == True: | |
y = y + yspeed | |
screen.blit(background, (0, 0)) | |
screen.blit(block, (x, y)) | |
pygame.display.flip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment