slide effect
Posted: Mon Feb 06, 2017 8:14 pm
when it comes to making a game more realistic, I suck. I created a jump and move effect with the player, the only thing is when the player stops moving and you take your hand of the key to move him it is a very abrupt stop. I want to create an effect for the player to be able to slide a couple pixels after the player takes their hand off of the move key, but don't know where to start with this.
Thank you for any help!
Thank you for any help!
Code: Select all
world = {}
world.ground = 590
player = {}
player.x = 300
player.y = world.ground - 60
player.h = 60
player.speed = 200
player.vy = 0
player.vx = 0
player.canJump = true
player.moveleft = true
player.moveright = true
gravity = 1800
jumpv = -900
function love.load()
mattlemen1 = love.graphics.newImage("graphics/mattlemen1.jpg")
end
function love.draw()
love.graphics.setBackgroundColor(0, 128, 128)
--draw player
love.graphics.setColor(255, 255, 255, 255)
--love.graphics.draw(mattlemen1, player.x, player.y)
love.graphics.rectangle("fill", player.x, player.y, player.h, player.h)
--ground
love.graphics.setColor(0, 128, 0, 100)
love.graphics.rectangle("fill", 0, world.ground, 800, 800)
--drawlevel1()
end
function love.update(dt)
--controls
if player.moveleft == true then
if love.keyboard.isDown("left") then
player.x = player.x - player.speed*dt
end
end
if player.moveright == true then
if love.keyboard.isDown("right") then
player.x = player.x + player.speed*dt
end
end
--gravity
player.y = player.y + (player.vy * dt)
player.vy = player.vy + ( gravity * dt)
if player.y >= world.ground - player.h then
player.y = world.ground - player.h; player.vy = 0;
player.canJump = true
end
end
function love.keypressed(key, unicode)
if key == "space" and player.canJump then
player.vy = jumpv
player.canJump = false
end
end