How do i declare row and tile? I tried it without declaraation, because i thought, it is in the ipairs function and i get an error at line 170 - i think, because the variables tile and row are not declared.
so here is my code:
Code: Select all
local player
local direction
local ground
local tilemap
function love.load()
FrameDuration = 0.08
FrameTimer = 0
FrameIndex = 1
FramesWalkingDown = {
love.graphics.newImage("/Character_Sprites/going_down_01.png"),
love.graphics.newImage("/Character_Sprites/going_down_02.png"),
love.graphics.newImage("/Character_Sprites/going_down_03.png"),
love.graphics.newImage("/Character_Sprites/going_down_04.png"),
love.graphics.newImage("/Character_Sprites/going_down_05.png"),
love.graphics.newImage("/Character_Sprites/going_down_06.png")
}
FramesWalkingUp = {
love.graphics.newImage("/Character_Sprites/going_up01.png"),
love.graphics.newImage("/Character_Sprites/going_up02.png"),
love.graphics.newImage("/Character_Sprites/going_up03.png"),
love.graphics.newImage("/Character_Sprites/going_up04.png"),
love.graphics.newImage("/Character_Sprites/going_up05.png"),
love.graphics.newImage("/Character_Sprites/going_up06.png")
}
FramesWalkingRight = {
love.graphics.newImage("/Character_Sprites/going_right01.png"),
love.graphics.newImage("/Character_Sprites/going_right02.png"),
love.graphics.newImage("/Character_Sprites/going_right03.png"),
love.graphics.newImage("/Character_Sprites/going_right04.png"),
love.graphics.newImage("/Character_Sprites/going_right05.png"),
love.graphics.newImage("/Character_Sprites/going_right06.png")
}
FramesWalkingLeft = {
love.graphics.newImage("/Character_Sprites/going_left01.png"),
love.graphics.newImage("/Character_Sprites/going_left02.png"),
love.graphics.newImage("/Character_Sprites/going_left03.png"),
love.graphics.newImage("/Character_Sprites/going_left04.png"),
love.graphics.newImage("/Character_Sprites/going_left05.png"),
love.graphics.newImage("/Character_Sprites/going_left06.png")
}
FrameEnabledDown = FramesWalkingDown[FrameIndex]
FrameEnabledUp = FramesWalkingUp[FrameIndex]
FrameEnabledRight = FramesWalkingRight[FrameIndex]
FrameEnabledLeft = FramesWalkingLeft[FrameIndex]
tilemap = {
{16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
{16, 16, 16, 16, 16, 16, 11, 12, 13, 12, 13, 12, 13, 12, 13, 15},
{16, 16, 16, 16, 16, 16, 21, 22, 23, 22, 23, 22, 23, 22, 23, 25},
{16, 16, 16, 16, 16, 16, 31, 33, 32, 33, 32, 33, 32, 33, 32, 35},
{16, 16, 16, 16, 16, 16, 31, 33, 32, 33, 32, 33, 32, 33, 32, 35},
{16, 16, 16, 16, 16, 16, 31, 33, 32, 33, 32, 33, 32, 33, 32, 35},
{16, 16, 16, 16, 16, 16, 31, 33, 32, 33, 32, 33, 32, 33, 32, 35},
{11, 12, 13, 12, 13, 12, 25, 33, 32, 33, 32, 33, 32, 33, 32, 35},
{21, 22, 23, 22, 23, 22, 25, 33, 32, 33, 32, 33, 32, 33, 32, 35},
{31, 32, 33, 32, 33, 32, 33, 32, 33, 32, 32, 33, 32, 32, 33, 35},
{31, 32, 33, 32, 33, 32, 33, 32, 33, 32, 32, 33, 32, 32, 33, 35},
{31, 32, 33, 32, 33, 32, 33, 32, 33, 32, 32, 33, 32, 32, 33, 35},
{51, 52, 53, 52, 53, 15, 32, 33, 32, 33, 32, 33, 11, 52, 53, 55},
{16, 16, 16, 16, 16, 31, 32, 33, 32, 33, 32, 33, 35, 16, 16, 16},
{16, 16, 16, 16, 16, 31, 32, 33, 32, 33, 32, 33, 35, 16, 16, 16},
{16, 16, 16, 16, 16, 51, 52, 53, 54, 52, 53, 54, 55, 16, 16, 16}
}
tile_11 = love.graphics.newImage("/DungeonTiles01/11.png")
tile_12 = love.graphics.newImage("/DungeonTiles01/12.png")
tile_13 = love.graphics.newImage("/DungeonTiles01/13.png")
width = 16
height = 16
player = {}
player.x = 70
player.y = 70
player.image = love.graphics.newImage("/Character_Sprites/standing_down.png" )
end
Down={}
function love.joystickpressed( joystick, button )
Down[button]=true
end
function love.joystickreleased( joystick, button )
Down[button]=nil
end
love.update=function (dt)
FrameTimer = FrameTimer + dt
if FrameTimer >= FrameDuration then
FrameTimer = 0
FrameIndex = FrameIndex + 1
if FrameIndex > #FramesWalkingDown then
FrameIndex = 1
end
if FrameIndex > #FramesWalkingUp then
FrameIndex = 1
end
if FrameIndex > #FramesWalkingLeft then
FrameIndex = 1
end
if FrameIndex > #FramesWalkingRight then
FrameIndex = 1
end
if Down[06] then
player.x = player.x + 4
FrameEnabledRight = FramesWalkingRight[FrameIndex]
end
if Down[04] then
player.y = player.y + 4
FrameEnabledDown = FramesWalkingDown[FrameIndex]
end
if Down[02] then
player.x = player.x - 4
FrameEnabledLeft = FramesWalkingLeft[FrameIndex]
end
if Down[00] then
player.y = player.y - 4
FrameEnabledUp = FramesWalkingUp[FrameIndex]
end
end
end
function love.draw()
for i,row in ipairs(tilemap) do
for j,tile in ipairs(row) do
if tile = 11 then
love.graphics.draw( tile_11, j * width, i * height)
end
if tile = 12 then
love.graphics.draw( tile_12, j * width, i * height)
end
if tile = 13 then
love.graphics.draw( tile_13, j * width, i * height)
end
end
end
if Down[06] then
love.graphics.draw( FrameEnabledRight, player.x, player.y )
elseif Down[04] then
love.graphics.draw( FrameEnabledDown, player.x, player.y )
elseif Down[02] then
love.graphics.draw( FrameEnabledLeft, player.x, player.y )
elseif Down[00] then
love.graphics.draw( FrameEnabledUp, player.x, player.y )
else
love.graphics.draw( player.image, player.x, player.y )
end