I have been trying to make a new image appear, but LOVE won't see it exists, which it does when compressed into the .love.
Second, I am trying to do tile scrolling as made in the tile-scrolling tutorial on the Wiki. It's not working. Can someone help me fix this?
Code: Select all
function love.load()
player = {
grid_x = 400,
grid_y = 320,
act_x = 200,
act_y = 200,
speed = 10
}
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 }
}
music = love.audio.newSource("pallet.wav")
love.audio.play(music)
map_w = 20
map_h = 20
map_x = 0
map_y = 0
tile_w = 40
tile_h = 40
map_offset_x = 30
map_offset_y = 30
map_display_w = 14
map_display_h = 10
end
function love.update(dt)
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end
function love.draw()
draw_map()
love.graphics.rectangle("fill", player.act_x, player.act_y, 40, 40)
end
function love.keypressed(key)
if key == "up" then
if testMap(0, -1) then
player.grid_y = player.grid_y - 40
end
elseif key == "down" then
if testMap(0, 1) then
player.grid_y = player.grid_y + 40
end
elseif key == "left" then
if testMap(-1, 0) then
player.grid_x = player.grid_x - 40
end
elseif key == "right" then
if testMap(1, 0) then
player.grid_x = player.grid_x + 40
end
end
if key == 'up' then
map_y = map_y-1
if map_y < 0 then map_y = 0; end
end
if key == 'down' then
map_y = map_y+1
if map_y > map_h-map_display_h then map_y = map_h-map_display_h; end
end
if key == 'left' then
map_x = math.max(map_x-1, 0)
end
if key == 'right' then
map_x = math.min(map_x+1, map_w-map_display_w)
end
end
function testMap(x, y)
if map[(player.grid_y / 40) + y][(player.grid_x / 40) + x] == 1 then
return false
end
return true
end
function draw_map()
for y=1, map_display_h do
for x=1, map_display_w do
if map[y][x] == 1 then
love.graphics.rectangle("line"[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x, (y*tile_h)+map_offset_y)
end
end
end
end