SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- local platform = {}
- local player = {}
- function love.load()
- platform.width = love.graphics.getWidth()
- platform.height = love.graphics.getHeight()
- platform.x = 0
- platform.y = platform.height*2/3
- player.x = love.graphics.getWidth() / 2
- player.y = platform.y
- --horizontal movement sprites
- player.movespriteright = love.graphics.newImage("icons/rightsidemario.png")
- player.movespriteleft = love.graphics.newImage("icons/leftsidemario.png")
- player.movesprite = love.graphics.newImage("icons/rightsidemario.png")
- leftimgWidth, leftimgHeight = player.movespriteleft:getDimensions()
- rightimgWidth, rightimgHeight = player.movespriteright:getDimensions()
- frames = 3
- mariospriteWidth = 16
- mariospriteHeight = 32
- lastquads = love.graphics.newQuad(0, 0, mariospriteWidth, mariospriteHeight, rightimgWidth, rightimgHeight)
- jumpleftquads = love.graphics.newQuad(255, 0, mariospriteWidth, mariospriteHeight, leftimgWidth, leftimgHeight)
- jumprightquads = love.graphics.newQuad(85, 0, mariospriteWidth, mariospriteHeight, rightimgWidth, rightimgHeight)
- jumplastquads = jumprightquads
- leftquads = {}
- rightquads = {}
- leftfirstimgx = 323
- rightfirstimgx = 17
- for i = 0 , frames do
- table.insert(leftquads, love.graphics.newQuad(leftfirstimgx - i - i*mariospriteWidth, 0, mariospriteWidth, mariospriteHeight, leftimgWidth, leftimgHeight))
- end
- for i = 0, frames do
- table.insert (rightquads, love.graphics.newQuad(rightfirstimgx + i + i*mariospriteWidth, 0, mariospriteWidth, mariospriteHeight, rightimgWidth, rightimgHeight))
- end
- timer_horizontal = 0
- framespeed_horizontal = 15
- horizontal_direction = 0
- vertical_jump = 0
- player.speed = 200
- player.speed = 200
- player.ground = player.y
- player.y_velocity = 0
- player.jump_height = -300
- player.gravity = 500
- end
- function love.update(dt)
- --spawning player in opposite sides
- if player.x > love.graphics.getWidth() + mariospriteWidth then
- player.x = - mariospriteWidth
- elseif player.x < - mariospriteWidth then
- player.x = love.graphics.getWidth() + mariospriteWidth
- end
- --moving left and right, and jumping
- if love.keyboard.isDown("right") then
- horizontal_direction = 1
- player.x = player.x + (player.speed * dt)
- timer_horizontal = timer_horizontal + dt * framespeed_horizontal
- end
- if love.keyboard.isDown("left") then
- horizontal_direction = -1
- player.x = player.x - (player.speed * dt)
- timer_horizontal = timer_horizontal + dt * framespeed_horizontal
- end
- if love.keyboard.isDown("space") then
- if player.y_velocity == 0 then
- player.y_velocity = player.jump_height
- end
- end
- if player.y_velocity ~= 0 then
- vertical_jump = 1
- player.y = player.y + player.y_velocity * dt
- player.y_velocity = player.y_velocity + (player.gravity * dt)
- end
- if player.y >= player.ground then
- player.y_velocity = 0
- player.y = player.ground
- vertical_jump = 0
- end
- function love.keyreleased(key)
- if key == "right" or key == "left" or key == "space" then
- horizontal_direction = 0
- end
- end
- end
- function love.draw()
- love.graphics.setColor(255, 255, 255)
- love.graphics.rectangle("fill", platform.x, platform.y, platform.width, platform.height)
- if horizontal_direction == -1 and vertical_jump == 1 then
- love.graphics.draw(player.movespriteleft, jumpleftquads, player.x, player.y, 0, 2, 2, mariospriteWidth/2, mariospriteHeight)
- jumplastquads = jumpleftquads
- player.movesprite = player.movespriteleft
- elseif horizontal_direction == -1 then
- love.graphics.draw(player.movespriteleft, leftquads[math.floor(timer_horizontal) % frames + 1], player.x, player.y, 0, 2, 2, mariospriteWidth/2, mariospriteHeight)
- player.movesprite = player.movespriteleft
- lastquads = love.graphics.newQuad(340, 0, mariospriteWidth, mariospriteHeight, leftimgWidth, leftimgHeight)
- end
- if horizontal_direction == 1 and vertical_jump == 1 then
- love.graphics.draw(player.movespriteright, jumprightquads, player.x, player.y, 0, 2, 2, mariospriteWidth/2, mariospriteHeight)
- jumplastquads = jumprightquads
- player.movesprite = player.movespriteright
- elseif horizontal_direction == 1 then
- love.graphics.draw(player.movespriteright, rightquads[math.floor(timer_horizontal) % frames + 1], player.x, player.y, 0, 2, 2, mariospriteWidth/2, mariospriteHeight)
- player.movesprite = player.movespriteright
- lastquads = love.graphics.newQuad(0, 0, mariospriteWidth, mariospriteHeight, rightimgWidth, rightimgHeight)
- end
- if horizontal_direction == 0 and vertical_jump == 1 then
- love.graphics.draw(player.movesprite, jumplastquads, player.x, player.y, 0, 2, 2, mariospriteWidth/2, mariospriteHeight)
- elseif horizontal_direction == 0 then
- love.graphics.draw(player.movesprite, lastquads, player.x, player.y, 0, 2, 2, mariospriteWidth/2, mariospriteHeight)
- end
- end
RAW Paste Data

