Code: Select all
player = {}
function player.load()
player.x = 300
player.y = 350
player.speed = 1
player.collided = {}
player.collided.left = false
player.collided.right = false
player.collided.up = false
player.collided.down = false
player.weapon = {}
player.weapon.current = 0
player.image = love.graphics.newImage("Explorer.png")
player.frame = {}
player.frame.delay = 20
player.frame.one = love.graphics.newQuad(0,0 +((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.two = love.graphics.newQuad(128,0 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.three = love.graphics.newQuad(128 * 2,0 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.four = love.graphics.newQuad(128 * 3,0 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.five = love.graphics.newQuad(0,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.six = love.graphics.newQuad(128,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.seven = love.graphics.newQuad(128 * 2,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.eight = love.graphics.newQuad(128 * 3,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.nine = love.graphics.newQuad(0,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.ten = love.graphics.newQuad(128,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.eleven = love.graphics.newQuad(128 * 2,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twelve = love.graphics.newQuad(128 * 3,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirteen = love.graphics.newQuad(0,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.fourteen = love.graphics.newQuad(128,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.fifteen = love.graphics.newQuad(256,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.sixteen = love.graphics.newQuad(256 + 128,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.seventeen = love.graphics.newQuad(0,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.eighteen = love.graphics.newQuad(128,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.nineteen = love.graphics.newQuad(128 * 2,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twenty = love.graphics.newQuad(128 * 3,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyone = love.graphics.newQuad(0,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentytwo = love.graphics.newQuad(128,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentythree = love.graphics.newQuad(256,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyfour = love.graphics.newQuad(256 + 128,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyfive = love.graphics.newQuad(0,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentysix = love.graphics.newQuad(128,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyseven = love.graphics.newQuad(128 * 2,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyeight = love.graphics.newQuad(128 * 3,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentynine = love.graphics.newQuad(0,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirty = love.graphics.newQuad(128,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirtyone = love.graphics.newQuad(128 * 2,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirtytwo = love.graphics.newQuad(128 * 3,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.current = player.frame.one
player.direction = "up"
end
function player.drawMain()
if map.title.currentMap == false
and map.credits.currentMap == false then
love.graphics.draw(player.image, player.frame.current, player.x, player.y)
end
end
function player.animation()
if player.direction == "right" then
if player.frame.delay > 0 then
player.frame.delay = player.frame.delay - 1
elseif player.frame.delay == 0 then
if player.frame.current == player.frame.one then
player.frame.current = player.frame.two
elseif player.frame.current == player.frame.two then
player.frame.current = player.frame.three
elseif player.frame.current == player.frame.three then
player.frame.current = player.frame.four
elseif player.frame.current == player.frame.four then
player.frame.current = player.frame.five
elseif player.frame.current == player.frame.five then
player.frame.current = player.frame.six
elseif player.frame.current == player.frame.six then
player.frame.current = player.frame.seven
elseif player.frame.current == player.frame.seven then
player.frame.current = player.frame.eight
elseif player.frame.current == player.frame.eight then
player.frame.current = player.frame.one
else
player.frame.current = player.frame.one
end
player.frame.delay = 20
end
elseif player.direction == "left" then
if player.frame.delay > 0 then
player.frame.delay = player.frame.delay - 1
elseif player.frame.delay == 0 then
if player.frame.current == player.frame.nine then
player.frame.current = player.frame.ten
elseif player.frame.current == player.frame.ten then
player.frame.current = player.frame.eleven
elseif player.frame.current == player.frame.eleven then
player.frame.current = player.frame.twelve
elseif player.frame.current == player.frame.twelve then
player.frame.current = player.frame.thirteen
elseif player.frame.current == player.frame.thirteen then
player.frame.current = player.frame.fourteen
elseif player.frame.current == player.frame.fourteen then
player.frame.current = player.frame.fifteen
elseif player.frame.current == player.frame.fifteen then
player.frame.current = player.frame.sixteen
elseif player.frame.current == player.frame.sixteen then
player.frame.current = player.frame.nine
else
player.frame.current = player.frame.nine
end
player.frame.delay = 20
end
elseif player.direction == "up" then
if player.frame.delay > 0 then
player.frame.delay = player.frame.delay - 1
elseif player.frame.delay == 0 then
if player.frame.current == player.frame.seventeen then
player.frame.current = player.frame.eighteen
elseif player.frame.current == player.frame.eighteen then
player.frame.current = player.frame.nineteen
elseif player.frame.current == player.frame.nineteen then
player.frame.current = player.frame.twenty
elseif player.frame.current == player.frame.twenty then
player.frame.current = player.frame.twentyone
elseif player.frame.current == player.frame.twentyone then
player.frame.current = player.frame.twentytwo
elseif player.frame.current == player.frame.twentytwo then
player.frame.current = player.frame.twentythree
elseif player.frame.current == player.frame.twentythree then
player.frame.current = player.frame.twentyfour
elseif player.frame.current == player.frame.twentyfour then
player.frame.current = player.frame.seventeen
else
player.frame.current = player.frame.seventeen
end
player.frame.delay = 20
end
elseif player.direction == "down" then
if player.frame.delay > 0 then
player.frame.delay = player.frame.delay - 1
elseif player.frame.delay == 0 then
if player.frame.current == player.frame.twentyfive then
player.frame.current = player.frame.twentysix
elseif player.frame.current == player.frame.twentysix then
player.frame.current = player.frame.twentyseven
elseif player.frame.current == player.frame.twentyseven then
player.frame.current = player.frame.twentyeight
elseif player.frame.current == player.frame.twentyeight then
player.frame.current = player.frame.twentynine
elseif player.frame.current == player.frame.twentynine then
player.frame.current = player.frame.thirty
elseif player.frame.current == player.frame.thirty then
player.frame.current = player.frame.thirtyone
elseif player.frame.current == player.frame.thirtyone then
player.frame.current = player.frame.thirtytwo
elseif player.frame.current == player.frame.thirtytwo then
player.frame.current = player.frame.twentyfive
else
player.frame.current = player.frame.twentyfive
end
player.frame.delay = 20
end
end
end
function player.movement()
if love.keyboard.isDown("left")
and player.collided.left == false then
player.x = player.x - player.speed
player.direction = "left"
elseif love.keyboard.isDown("right")
and player.collided.right == false then
player.x = player.x + player.speed
player.direction = "right"
elseif love.keyboard.isDown("up")
and player.collided.up == false then
player.y = player.y - player.speed
player.direction = "up"
elseif love.keyboard.isDown("down")
and player.collided.down == false then
player.y = player.y + player.speed
player.direction = "down"
end
end
function player.collision()
if map.forest.room == 1
and map.forest.currentMap then
if player.x == 203
and player.y > 174 then
player.collided.left = true
elseif player.x > 203 then
player.collided.left = false
end
if player.y == 174
and player.x < 279 then
player.collided.up = true
elseif player.y > 274
or player.x > 279 then
player.collided.up = false
end
if player.x == 279
and player.y < 179 then
player.collided.left = true
elseif player.x > 279 then
player.collided.left = false
end
if player.y == 179 - 50 then
player.collided.up = true
elseif player. y < 179 - 50 then
player.collided.up = false
end
if player.x + 128 - 40 == 413
and player.y + 128 > 295 then
player.collided.right = true
elseif player.x + 128 - 40 < 413
or player.y + 128 < 295 then
player.collided.right = false
end
if player.y + 128 == 295
and player.x + 128 - 40 > 413 then
player.collided.down = true
elseif player.y + 128 < 295
or player.x + 128 - 40 < 413 then
player.collided.down = false
end
if player.y + 128 == 500 then
player.collided.down = true
elseif player.y + 128 < 500 then
player.collided.down = false
end
elseif map.forest.room == 2
and map.forest.currentMap then
if player.x + 32 < 268
and player.y == 129 then
player.collided.up = true
elseif player.x + 32 > 268
or player.y > 129 then
player.collided.up = false
end
if player.x + 32 == 268
and player.y < 129 then
player.collided.left = true
elseif player.x + 32 > 268
or player.y > 129 then
player.collided.left = false
end
if player.y + 128 == 293 then
player.collided.down = true
elseif player.y + 128 < 293 then
player.collided.down = false
end
if player.x + 98 == 418 then
player.collided.right = true
elseif player.x + 98 < 418 then
player.collided.right = false
end
elseif map.forest.room == 3
and map.forest.currentMap then
if player.x + 128 - 40 == 403 then
player.collided.right = true
elseif player.x + 128 - 40 < 403 then
player.collided.right = false
end
if player.y - 20 == 118 then
player.collided.up = true
elseif player.y - 20 > 118 then
player.collided.up = false
end
if player.y + 128 == 500 then
player.collided.down = true
elseif player.y + 128 < 500 then
player.collided.down = false
end
if player.x == 0 then
player.collided.left = true
elseif player.x > 0 then
player.collided.left = false
end
elseif map.forest.room == 4
and map.forest.currentMap then
if player.y == 120 then
player.collided.up = true
elseif player.y > 120 then
player.collided.up = false
end
if player.y + 128 == 340 then
player.collided.down = true
elseif player.y + 128 < 340 then
player.collided.down = false
end
if player.x == 50 then
player.collided.left = true
elseif player.x > 50 then
player.collided.left = false
end
elseif map.temple.currentMap then
if player.x == 0 then
player.collided.left = true
elseif player.x > 0 then
player.collided.left = false
end
if player.y == 0 then
player.y = player.y + 2
end
if player.x + 128 == 800 then
player.collided.right = true
elseif player.x + 128 < 800 then
player.collided.right = false
end
if player.y + 128 == 500 then
player.collided.down = true
elseif player.y + 128 < 500 then
player.collided.down = false
end
if map.temple.room == 2 then
if player.y == 145 - 40
and player.x + 128 - 40 > 370 then
player.collided.up = true
elseif player.y > 145 - 40
or player.x + 128 - 40 < 370 then
player.collided.up = false
end
if player.x + 128 - 40 == 370
and player.y < 145 - 40 then
player.collided.right = true
elseif player.x + 128 - 40 < 370
or player.y > 145 - 40 then
player.collided.right = false
end
elseif map.temple.room == 3 then
if player.y == 145 - 40 then
player.collided.up = true
elseif player.y > 145 - 40 then
player.collided.up = false
end
elseif map.temple.room == 4 then
if player.y == 145 - 40
and player.x < 330 - 40 then
player.collided.up = true
elseif player.y > 145 - 40
or player.x > 330 - 40 then
player.collided.up = false
end
if player.y == 145 - 40
and player.x + 128 - 40 > 465 then
player.collided.up = true
elseif player.y > 105
or player.x > 290 then
player.collided.up = false
end
if player.x == 330 - 4
and player.y < 105 then
player.collided.left = true
elseif player.x < 330 - 4
or player.y > 105 then
player.collided.left = false
end
if player.x + 128 - 40 == 465
and player.y < 105 then
player.collided.right = true
else
player.collided.right = false
end
elseif map.temple.room == 8 then
if player.y == 30 then
player.collided.up = true
elseif player.y > 30 then
player.collided.up = false
end
end
end
end
function player.weaponUpdate()
player.frame.one = love.graphics.newQuad(0,0 +((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.two = love.graphics.newQuad(128,0 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.three = love.graphics.newQuad(128 * 2,0 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.four = love.graphics.newQuad(128 * 3,0 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.five = love.graphics.newQuad(0,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.six = love.graphics.newQuad(128,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.seven = love.graphics.newQuad(128 * 2,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.eight = love.graphics.newQuad(128 * 3,128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.nine = love.graphics.newQuad(0,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.ten = love.graphics.newQuad(128,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.eleven = love.graphics.newQuad(128 * 2,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twelve = love.graphics.newQuad(128 * 3,256 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirteen = love.graphics.newQuad(0,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.fourteen = love.graphics.newQuad(128,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.fifteen = love.graphics.newQuad(256,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.sixteen = love.graphics.newQuad(256 + 128,256 + 128 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.seventeen = love.graphics.newQuad(0,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.eighteen = love.graphics.newQuad(128,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.nineteen = love.graphics.newQuad(128 * 2,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twenty = love.graphics.newQuad(128 * 3,512 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyone = love.graphics.newQuad(0,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentytwo = love.graphics.newQuad(128,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentythree = love.graphics.newQuad(256,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyfour = love.graphics.newQuad(256 + 128,640 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyfive = love.graphics.newQuad(0,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentysix = love.graphics.newQuad(128,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyseven = love.graphics.newQuad(128 * 2,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentyeight = love.graphics.newQuad(128 * 3,768 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.twentynine = love.graphics.newQuad(0,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirty = love.graphics.newQuad(128,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirtyone = love.graphics.newQuad(128 * 2,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
player.frame.thirtytwo = love.graphics.newQuad(128 * 3,896 + ((128 * 8) * player.weapon.current),128,128,128 * 4, 128 * 16)
end
function player.update()
if map.title.currentMap == false
and map.credits.currentMap == false then
player.movement()
end
player.collision()
player.animation()
player.weaponUpdate()
end
function player.draw()
player.drawMain()
end
Sorry its so long
I feel like