Im have this idea of creating a endless runner but i cant seem to create a function for the player's character to move forward without any user inputs(much like how flappy bird moves forward)
please help me get some idea in how to do this and how it works so that i can implement it on future stuff...
function love.load()
-- FullScreen
love.window.setFullscreen(true, "desktop")
end
--Player Stats
player ={x = 100, y = 375, speed = 5 }
function love.update(dt)
--Auto Forward Action
--Keyboard S and W or Up and Down
if love.keyboard. isDown("s") then
player.y = player.y + player.speed
end
if love.keyboard. isDown("w") then
player.y = player.y - player.speed
end
end
function love.draw()
--CharacterRectangleWhite
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle("fill", player.x, player.y, 50 , 50)
end
A Man who can fly a rocket to orbit will have a hard time dealing with women
Question:
What do you think could possibly happen if you do the same that you did with the y axis to the x axis, but without the if loop?
(And btw, you might want to use dt to calculate your movement.)
If you take away the if where you check if someone's pressing the key, the characters moves without any user input.
In this case it keeps moving forward
MadByte wrote: ↑Fri Dec 01, 2017 9:24 am
Question:
What do you think could possibly happen if you do the same that you did with the y axis to the x axis, but without the if loop?
(And btw, you might want to use dt to calculate your movement.)
Ahhh so i need the dt to create a much smoother control system?
and that`s what i am missing in my last attempt because i simply put player.x = player.x + player.speed...
Thanks a lot!!
A Man who can fly a rocket to orbit will have a hard time dealing with women
xNick1 wrote: ↑Fri Dec 01, 2017 10:08 am
If you take away the if where you check if someone's pressing the key, the characters moves without any user input.
In this case it keeps moving forward
function love.update(dt)
player.y = player.y + player.speed * dt
end
thanks!! now that`s the use of delta time..
one question.. if i change the variables so that it may affect something else, will i be able to use it for moving obstacles??
A Man who can fly a rocket to orbit will have a hard time dealing with women