我从头开始构建了一个简单的蛇游戏,作为PICO-8和Lua的练习。
我试图通过创建一个旧的身体位置的副本来让身体跟随头部,并沿着长度更新。
我创建了一个t_old变量来存储原始的主体位置,但它与t同时被更新。我对此缺乏解释。
function train_move(t,d)
local t_old=t --grab existing
--update head based on direction of movement
if d==0 then
t[1].x-=sprite_size --left
elseif d==1 then
t[1].x+=sprite_size --right
elseif d==2 then
t[1].y-=sprite_size --up
else
t[1].y+=sprite_size --down
end
--update body **I have noticed that t[1]==t_old[1] here??
for i=2,#train do
t[i].x=t_old[i-1].x
t[i].y=t_old[i-1].y
end
return t
end发布于 2021-03-08 00:52:17
https://stackoverflow.com/questions/66518476
复制相似问题