2013年8月22日星期四

As strong as a crusher,python game tutorial(4)

In this tutorial, we will make the things move which is very cool:)



#!/usr/bin/env python
#-*- coding:utf-8 -*-

import pygame, sys
from pygame.locals import *

pygame.init()

# set frames per sec
FPS = 10
fpsClock = pygame.time.Clock()

DISPLAYSURF = pygame.display.set_mode((400,600), 0 ,32)

WHITE = (0,255,255)
# load a png file to move
catImg = pygame.image.load('cat.png')

catx = 10
caty = 10

direction = 'down'

while 1:
    DISPLAYSURF.fill(WHITE)
 
    # to control the position of the pic file
 
    if direction == 'right':
        catx += 5
        if catx == 200:
            direction = 'left'
         
    elif direction == 'left':
        catx -= 5
        if catx == 0:
            direction == 'right'

    elif direction == 'down':
        caty += 5
        if caty == 500:
            direction = 'up'
 
    elif direction == 'up':
        caty -= 5
        if caty == 10:
            direction = 'down'

    DISPLAYSURF.blit(catImg, (catx, caty))
 
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
 
    pygame.display.update()
    fpsClock.tick(FPS)


for more you can just click:
www.quarryequipments.com

没有评论:

发表评论