Re: Newbie has a few basic questions
Posted: Wed Mar 02, 2011 5:59 pm
Use something like this:obur wrote:i löve you! i really löve you!
oh, but there's a problem. i'm making 2 different if statements for walking in 2 directions at the same time. like going up and right at the same time. however, if i make 2 different if statements in here, one of them will drop to else all the time.
now, if i make only 1 if statement, i can't go in 2 directions at the same time.Code: Select all
if (up) go up; else if (down) go down; if (right) go right; else if (left) go left;
by the way, do you know why my previous idea didn't work? i mean that sentinel stuff. thanks again
Code: Select all
function love.load()
player = {
x = 100,
y = 100,
speed = 100
}
end
function love.update(dt)
if love.keyboard.isDown(key.up) and love.keyboard.isDown(key.down) then
-- canceled out
elseif love.keyboard.isDown(key.up) then
move(0, -dt)
elseif love.keyboard.isDown(key.down) then
move(0, dt)
end
if love.keyboard.isDown(key.left) and love.keyboard.isDown(key.right) then
-- canceled out
elseif love.keyboard.isDown(key.left) then
move(-dt, 0)
elseif love.keyboard.isDown(key.right) then
move(dt, 0)
end
end
function move(x, y)
player.x = player.x + (x * player.speed)
player.y = player.y + (y * player.speed)
end
Really, I think you need to focus on learning Lua a bit. Download https://github.com/vrld/love-console and play around with it, get the hang of the language.