Hi friends today I have made my first pygame application.I doesn't do much except for graphic rotation and changing the graphic when mouse is clicked.
Here is its execution video :
This is the code for the program:
import pygame, sys ,time
from pygame.locals import *
pygame.init()
FPS = 30 # frames per second setting
fpsClock = pygame.time.Clock()
# set up the window
DISPLAYSURF = pygame.display.set_mode((400, 300), 0, 32)
pygame.display.set_caption('Punch sam')
WHITE = (255, 255, 255)
catImg = pygame.image.load('sam.jpg')
sam_gaali=pygame.image.load('sam_gaali.jpg')
#pygame.mouse.set_cursor(rushi_hand,(self.x,self.y),self.mask,self.data)
catx = 10
caty = 10
direction = 'right'
while True: # the main game loop
DISPLAYSURF.fill(WHITE)
if direction == 'right':
catx += 5
if catx == 280:
direction = 'down'
elif direction == 'down':
caty += 5
if caty == 220:
direction = 'left'
elif direction == 'left':
catx -= 5
if catx == 10:
direction = 'up'
elif direction == 'up':
caty -= 5
if caty == 10:
direction = 'right'
DISPLAYSURF.blit(catImg, (catx, caty))
if pygame.mouse.get_pressed()[0]:
pos=pygame.mouse.get_pos
DISPLAYSURF.fill(WHITE)
DISPLAYSURF.blit(sam_gaali, (catx, caty))
pygame.display.flip()
time.sleep(1)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)
I have made this program with python 2.7 and pygame 1.9.1.
I am also attaching its executable made from it using py2exe.
You can execute it using following steps:
1.go to dist folder after extracting the attachment.
2.execute punch_sam02.exe.