-
-
Save JeffersGlass/1a6a216b7bafc8bc3f42f4479f40d634 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
import pygame | |
import sys #will use the exit function | |
#Loads all the main pygame modules and initializes them | |
pygame.init() | |
screen_width=640 | |
screen_height=480 | |
guyImg = pygame.image.load('guy.png') | |
guyBigImgRight = pygame.transform.scale(guyImg, (200,200)) | |
guyBigImgLeft = pygame.transform.flip(guyBigImgRight, True, False) | |
imageToDraw = guyBigImgRight | |
guyX = 100 | |
guyY = 100 | |
guySpeed = 5 | |
guyVerticalSpeed = 0 | |
circleSpeed = 100 #pixels per second | |
objectList = list() | |
myClock = pygame.time.Clock() | |
#Create a new Surface with the dimensions listed above | |
screen=pygame.display.set_mode((screen_width, screen_height)) | |
#Loop forever: | |
while True: | |
dt = myClock.tick(30) | |
#The following makes the window close when clicking the "X" or exit button | |
#Without this, the window will nouot close, and will need to be killed | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: sys.exit() | |
screen.fill((0,0,0)) | |
screen.blit(imageToDraw, (guyX,guyY)) | |
keyPressedValues = pygame.key.get_pressed() | |
if keyPressedValues[pygame.K_RIGHT]: | |
guyX += guySpeed | |
imageToDraw = guyBigImgRight | |
if keyPressedValues[pygame.K_LEFT]: | |
guyX -= guySpeed | |
imageToDraw = guyBigImgLeft | |
if keyPressedValues[pygame.K_UP]: guyVerticalSpeed = -20 | |
guyVerticalSpeed += 2 | |
guyY += guyVerticalSpeed | |
if guyY > screen_height - 200: | |
guyY = screen_height - 200 | |
guyVerticalSpeed = 0 | |
#Apply all the changes we've made to the screen surface | |
#And draw them to the screen | |
pygame.display.flip() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment