This is working code That Derek Wilson and I have worked on.
It serves the purpose for this project.
#------------------------------------------------------------------------------
# Name: pyg_image.py
# Author: Kevin Harris (Modified by Derek Wilson and Jeremy Parker)
# Last Modified: 9/10/08
# Description: This Python/Pygame script demonstrates how to load and
# display an image file. Altered to switch between multiple
# images using the number keys.
#------------------------------------------------------------------------------
import pygame
from pygame.locals import *
def main():
pygame.init()
screen = pygame.display.set_mode( (800,800) )
background = pygame.Surface( screen.get_size() )
background.fill( (0,0,0) )
image = pygame.image.load( "pygame_powered.bmp" )
# image = pygame.image.load( "Devil.jpg" )
imagePosition = image.get_rect()
imagePosition.bottom = 250
imagePosition.left = 120
screen.blit( background, (0,0) )
screen.blit( image, imagePosition )
pygame.display.flip()
while 1:
pygame.event.pump()
keyinput = pygame.key.get_pressed()
if keyinput[K_ESCAPE] or pygame.event.peek(QUIT):
break
if keyinput[K_1]:
image = pygame.image.load( "image1.jpg" )
imagePosition.top = 0
imagePosition.left = 0
if keyinput[K_2]:
image = pygame.image.load( "image2.jpg" )
imagePosition.top = 0
imagePosition.left = 0
if keyinput[K_3]:
image = pygame.image.load( "image3.jpg" )
imagePosition.top = 0
imagePosition.left = 0
if keyinput[K_4]:
image = pygame.image.load( "image4.jpg" )
imagePosition.top = 0
imagePosition.left = 0
if keyinput[K_5]:
image = pygame.image.load( "image5.jpg" )
imagePosition.top = 0
imagePosition.left = 0
if keyinput[K_6]:
image = pygame.image.load( "image6.jpg" )
imagePosition.top = 0
imagePosition.left = 0
if keyinput[K_7]:
0 comments:
Post a Comment