gpt4 book ai didi

python - Pygame 相机跟随 2d 平铺游戏

转载 作者:行者123 更新时间:2023-11-28 20:47:03 27 4
gpt4 key购买 nike

<分区>

 import pygame, sys 
from pygame.locals import *

pygame.init()

size = width, height = 480,320
screen = pygame.display.set_mode(size)
r = 0
bif = pygame.image.load("map5.png")
pygame.display.set_caption("Pygame 2D RPG !")
x,y=0,0
movex, movey=0,0
character="boy.png"
player=pygame.image.load(character).convert_alpha()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_a:
movex=-1
elif event.key==K_d:
movex=+1
elif event.key==K_w:
movey=-1
elif event.key==K_s:
movey=+1
if event.type==KEYUP:
if event.key==K_a:
movex=0
elif event.key==K_d:
movex=0
elif event.key==K_w:
movey=0
elif event.key==K_s:
movey=0

x+=movex
y+=movey

screen.fill((r,0,0))
screen.blit(bif,(0,0))
screen.blit(player,(x,y))
pygame.display.flip()

一切正常,除了我想知道我究竟要如何才能将相机移动到玩家所在的地方抱歉,我无法向您显示 map 文件,因为您无法向其中添加图像。但是谢谢你的时间

map 在这里:https://dl.dropboxusercontent.com/u/110087275/2d%20pygame/map5.png最后代码在这里:https://dl.dropboxusercontent.com/u/110087275/2d%20pygame/2d_pygame.py

再次感谢您的时间和努力!!!!!!

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com