在电子游戏中将滚动添加到血小板中。好的,我在下面列出了我的项目的代码,我只是在做一些关于制作一个平台的玩玩游戏的实验。我试图弄清楚如何做一些非常简单的滚动跟随玩家,所以播放器是相机的中心,它反弹/跟随他。有谁可以帮我?import pygamefrom pygame import *WIN_WIDTH = 800WIN_HEIGHT = 640HALF_WIDTH = int(WIN_WIDTH / 2)HALF_HEIGHT = int(WIN_HEIGHT / 2)
DISPLAY = (WIN_WIDTH, WIN_HEIGHT)DEPTH = 32FLAGS = 0CAMERA_SLACK = 30def main():
global cameraX, cameraY
pygame.init()
screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
pygame.display.set_caption("Use arrows to move!")
timer = pygame.time.Clock()
up = down = left = right = running = False
bg = Surface((32,32))
bg.convert()
bg.fill(Color("#000000"))
entities = pygame.sprite.Group()
player = Player(32, 32)
platforms = []
x = y = 0
level = [
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P P",
"P PPPPPPPPPPP P",
"P P",
"P P",
"P P",
"P P",
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",]
# build the level
for row in level:
for col in row:
if col == "P":
p = Platform(x, y)
platforms.append(p)
entities.add(p)
if col == "E":
e = ExitBlock(x, y)
platforms.append(e)
entities.add(e)
x += 32
y += 32
x = 0
entities.add(player)
while 1:
timer.tick(60)
3 回答

桃花长相依
TA贡献1860条经验 获得超8个赞
如果你的地图是小的,你可以有一个大的IMG A,并得到一个矩形,根据播放器的位置,将是屏幕的大小。这样,球员将永远处于中间。Rect.钳(RECT)或Rect.钳_IP(RECT)将在这方面帮助您。 另一种方法是为屏幕上的位置设置一个不同的元组。播放器将在屏幕中心有一个恒定的值,而背景位置将是播放器位置的负值。

开心每一天1111
TA贡献1836条经验 获得超13个赞
.rect
.rect
添加回答
举报
0/150
提交
取消