动态背景之中国阁楼风景

"""一个微交互动画,用鼠标移动时,后面的凉亭会动,这本来是一个scratch作品,现在用Python把它做一下."""

import pygame
from pygame.locals import *

width,height = 960,720
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("动态背景之中国阁楼风景 www.lixingqiu.com")

background = pygame.image.load("images/蓝天太阳背景.png")

pavilion = pygame.image.load("images/阁楼.png").convert_alpha()
pavilion_rect = pavilion.get_rect()

green1 = pygame.image.load("images/绿植.png").convert_alpha()
green2 = pygame.image.load("images/前绿.png").convert_alpha()

clock = pygame.time.Clock()
running = True

while running:
    event = pygame.event.poll()
    if event.type == QUIT:running = False
    mx,my = pygame.mouse.get_pos()

    pavilion_rect.centerx = width//2 +  (mx-width//2)/5 
    pavilion_rect.centery = height//2 + (my-height//2)/5 

    # draw all images
    screen.blit(background,(0,0))
    screen.blit(pavilion,pavilion_rect)
    screen.blit(green1,(0,400))
    screen.blit(green2,(0,600))
    
    pygame.display.update()
    clock.tick(30) 
    

pygame.quit()

一个微交互动画,用鼠标移动时,后面的凉亭会动,这本来是一个scratch作品,现在用Python把它做一下