Player movement

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Incrypt
Prole
Posts: 5
Joined: Thu Oct 04, 2012 3:22 am

Player movement

Post by Incrypt »

My player moves only right and down and Im not very sure how to make him go up and left.

Also I use a windows 7 and not sure how to change the zip but I'll just give you the main.lua coding

function love.load()

love.graphics.setBackgroundColor(0,0,0)

medium = love.graphics.newFont(45)

picture = love.graphics.newImage("test.jpg")

testx = 300
testy = 300

end

function love.update()
if love.keyboard.isDown("right") then
testx = testx + 1
end

if love.keyboard.isDown("down") then
testy = testy + 1
end


end

function love.draw()
love.graphics.draw(picture,testx, testy)

end
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Player movement

Post by Roland_Yonaba »

Hi, Incrypt.
Welcome on the Love forums, where everyone makes löve everyday!
First of all, please consider wrapping your snippets of code with code tags. It makes it easier to read.
Incrypt wrote: Also I use a windows 7 and not sure how to change the zip but I'll just give you the main.lua coding
I don't get this one. Restate, please.
Incrypt wrote:My player moves only right and down and Im not very sure how to make him go up and left.
Fair enough, just make use of "left" and "up" keys, and act on coordinates in the opposite of what you already did for "right" and "down" moves.

Code: Select all

-- same as before

function love.update()
  if love.keyboard.isDown("right") then
    testx = testx + 1
  end
  if love.keyboard.isDown("left") then
    testx = testx - 1
  end
  if love.keyboard.isDown("down") then
    testy = testy + 1
  end
  if love.keyboard.isDown("up") then
    testy = testy - 1
  end
end

-- same as before
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Player movement

Post by Nixola »

Roland_Yonaba wrote:
Incrypt wrote: Also I use a windows 7 and not sure how to change the zip but I'll just give you the main.lua coding
I don't get this one. Restate, please.
"Also, I'm using Windows 7 and I'm not sure on how to change the .zip extension to .love, so I'll just give you main.lua content" (I think)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Player movement

Post by Roland_Yonaba »

So just follow this guide to unhide file extensions, then change the "zip" part to "love".
Incrypt
Prole
Posts: 5
Joined: Thu Oct 04, 2012 3:22 am

Re: Player movement

Post by Incrypt »

Roland_Yonaba wrote:Hi, Incrypt.
Welcome on the Love forums, where everyone makes löve everyday!
First of all, please consider wrapping your snippets of code with code tags. It makes it easier to read.

Sorry,But thanks anyway I never guessed the + and - change it.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests