Created
November 16, 2015 01:14
-
-
Save AndyNovo/b56957abd17c845d46da to your computer and use it in GitHub Desktop.
This file contains hidden or 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 random | |
BLACK = (0,0,0) | |
pygame.init() | |
WIDTH = 450 | |
HEIGHT = 600 | |
screen = pygame.display.set_mode([WIDTH, HEIGHT]) | |
another_loop = True | |
clock = pygame.time.Clock() | |
#Assumes an image names bwclear1.gif is in the current directory | |
lsprite = pygame.image.load("bwclear1.gif") #load an image (blit it onto screen later) | |
rsprite = pygame.transform.flip(lsprite, True, False) #this is a right facing copy | |
sprite = lsprite #this variable will store the current directioned version | |
wx = 100 | |
wy = 100 | |
scale = 1.0 #I'm going to also allow scaling up and down | |
wiz_w, wiz_h = lsprite.get_size() #We can get the original dimensions this way | |
while another_loop: | |
# --- Basic Event Processing | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
another_loop = False | |
# Every loop we will wipe the screen and redraw images | |
screen.fill(BLACK) | |
if( pygame.key.get_pressed()[pygame.K_LEFT] != 0 ): | |
wx = (wx - 2) % WIDTH | |
sprite = lsprite | |
if( pygame.key.get_pressed()[pygame.K_RIGHT] != 0 ): | |
wx = (wx + 2) % WIDTH | |
sprite = rsprite | |
if( pygame.key.get_pressed()[pygame.K_UP] != 0 ): | |
scale += .1 | |
if( pygame.key.get_pressed()[pygame.K_DOWN] != 0 ): | |
scale -= .1 | |
if scale < .3: | |
scale = .3 | |
#Then at blit time I'll make a scaled copy of the left or right facing normal sprite | |
screen.blit(pygame.transform.scale(sprite, (int(wiz_w*scale), int(wiz_h*scale))), (wx, wy)) | |
#This sets the frames per second | |
clock.tick(60) | |
#This puts the new stuff you've drawn on screen | |
pygame.display.flip() | |
#When we've left the while loop exit pygame | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment