继续

创建背景框和可移动方块

function love.load()

    player = {
        grid_x = 256,
        grid_y = 256,
        act_x = 200,
        act_y = 200,
speed = 16    }
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
        { 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
end


function love.update(dt)
    --player.act_y = player.act_y - (player.act_y - player.grid_y)*dt
    --player.act_x = player.act_x - (player.act_x - player.grid_x)*dt
player.act_y = player.act_y - (player.act_y - player.grid_y)*dt*player.speed
    player.act_x = player.act_x - (player.act_x - player.grid_x)*dt*player.speed
end


function love.draw()
    for y = 1, #map do
for x = 1, #map[1] do
if map[y][x] == 1 then
                love.graphics.rectangle("line", x * 32, y * 32, 32, 32)
            end
end
end


love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32)
end


function love.keypressed(key)
    if key == "up" then
        if testMap(0,-1) then
player.grid_y = player.grid_y - 32
end
--player.grid_y = player.grid_y - 32
    elseif key == "down" then
        if testMap(0,1) then
player.grid_y = player.grid_y + 32
end
--player.grid_y = player.grid_y + 32
    elseif key == "left" then
        if testMap(-1,0) then
player.grid_x = player.grid_x - 32
end
--player.grid_x = player.grid_x - 32
    elseif key == "right" then
if testMap(1,0) then
player.grid_x = player.grid_x + 32
end
        --player.grid_x = player.grid_x + 32
    end
end


function testMap(x,y)
if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
return false
end
return true
end









评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值