### 大地图相对运动scratch小猫过桥

```"""本程序操作一只小猫在一个绿色的园林中行走,其实小猫的坐标是不变的,变的是地图坐标"""

import time
import pygame
from pygame.locals import *
from actor import Actor

width,height = 480,360
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("大地图相对运动scratch小猫过桥 www.lixingqiu.com")

pygame.mixer.init()
pygame.mixer.music.play(-1,0)

size = ground.get_size()
ground = pygame.transform.scale(ground,(size[0] * 3,size[1] * 3)) # 放大3倍地图
ground_rect = ground.get_rect()
ground_rect.center = width//2 - 100,height//2 - 250
ground_dx = 0
ground_dy = 0

amounts = 16
images_right = [pygame.image.load(f"images/Walk{i}.png").convert_alpha() for i in range(amounts)]
images_sizes = [image.get_size() for image in images_right]
images_right = [pygame.transform.scale(images_right[index],(int(images_sizes[index][0]*0.2),
int(images_sizes[index][1]*0.2))) for index in range(amounts)]

images_left = [pygame.transform.flip(image,True,False) for image in images_right]

cat = Actor(images_right,images_left)
cat.rect.center = width//2,height//2
running = True
cat.start_time = time.time()
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == QUIT:running = False
if event.type == KEYDOWN:
cat.alt_costume = True
if event.key == K_LEFT : cat.images_index = 1  ; ground_dx = 5
if event.key == K_RIGHT : cat.images_index = 0 ; ground_dx = -5
if event.key == K_UP : ground_dy = 5
if event.key == K_DOWN : ground_dy = -5

if event.type == KEYUP:
cat.alt_costume = False
if event.key == K_LEFT : ground_dx = 0
if event.key == K_RIGHT : ground_dx = 0
if event.key == K_UP : ground_dy = 0
if event.key == K_DOWN : ground_dy = 0
ground_rect.move_ip(ground_dx,ground_dy)
cat.update()
screen.fill((102,226,60))
screen.blit(ground,ground_rect)
screen.blit(cat.image,cat.rect)

pygame.display.update()
clock.tick(60)

pygame.quit()

```