2013年8月23日星期五

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


# in this tutorial, we will see something cool than a crusher, which you can
# control your mouse of a picture, when your mouse go , the pic will go...

bg_img = "crusher.png"
mouse_img = "quarry.png"

import pygame
from pygame.locals import *
from sys import exit

pygame.init()

screen = pygame.display.set_mode((640,480),0,32)
pygame.display.set_caption("Crusher for sale")

background = pygame.image.load(bg_img).convert()
mouse_cursor = pygame.image.load(mouse_img).convert_alpha()

while 1:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()

        screen.blit(background,(0,0,))
     
        # get the position of the pic
        x, y = pygame.mouse.get_pos()
        x -= mouse_cursor.get_width() / 2
        y -= mouse_cursor.get_height() / 2
        screen.blit(mouse_cursor, (x, y))

        pygame.display.update()


没有评论:

发表评论