Page 2 of 2

Re: Newbie here gonna start out small

Posted: Mon Apr 25, 2011 9:24 am
by nevon
mrpoptart wrote:Thank you nevon. It worked like a charm. But now my tank will now move in the image at all. here is my code, can you help me see what is wrong?
You're overwriting your variables. You should probably read through the PiL.

Re: Newbie here gonna start out small

Posted: Mon Apr 25, 2011 9:34 am
by mrpoptart
Thank you for your help. I will read through this and see if i can find my error.

Re: Newbie here gonna start out small

Posted: Mon Apr 25, 2011 9:54 am
by BlackBulletIV
nevon wrote:
BlackBulletIV wrote:Nah I was meaning the real "use", as in put in your game. One thing I did forget though, is conflicting licenses, not just licenses saying "look, but don't touch."
Robin wrote:Also remember: games without a license are subject to full copyright. Luckily, most of the useful code around here is open source.
Oh really? Didn't know that. What about the code snippets we post? It'd be public domain unless otherwise stated I'm guessing?
Depends. See Threshold of Originality. In general though, no, just because you post something on the interwebs, that doesn't mean it automagically becomes public domain.
Argh, this legal world of ours is more wacky than I thought.

Re: Newbie here gonna start out small

Posted: Mon Apr 25, 2011 9:55 am
by kikito
Let's see your love.load function:

Code: Select all

function love.load()
   tank = love.graphics.newImage("tank.png")
   x = 500
   y = 500
   speed = 100 ;
   background = love.graphics.newImage("background.png")
   x = 0
   y = 0
   speed = 0
end
You start by creating a variable called "tank" and assign an image to it. Then you create x,y and speed, with values 500,500 and 100.
Then you create background, with another image.

And then you reset x,y and speed to 0,0,0

You are re-using x,y and speed for both the tank and the background. If you want the tank to move differently from the background, you need to use different variables for it. Try calling the tank variables tank_x, tank_y and tank_speed - in all your functions, not only love.load. This should give you a nice moving tank.

Re: Newbie here gonna start out small

Posted: Mon Apr 25, 2011 10:08 am
by mrpoptart
Well thank you a bunch kikito. I redid my code, and it works like a charm. Now im on my way to some collision detection, and shooting some missiles.

here is the code that i redid and it worked, with your help.

Code: Select all

function love.load()
   tank = love.graphics.newImage("tank.png")
   x = 500
   y = 500
   speed = 100 ;
   background = love.graphics.newImage("background.png")
   bg_x = 0
   bg_y = 0
   bg_speed = 0
end


function love.update(dt)
   if love.keyboard.isDown("right") then
      x = x + (speed * dt)
   elseif love.keyboard.isDown("left") then
      x = x - (speed * dt)
   end
   if love.keyboard.isDown( "escape" ) then
        love.event.push( "q" )
    end
end

function love.draw()
   love.graphics.draw(background, bg_x, bg_y)
   love.graphics.draw(tank, x, y)
end

Re: Newbie here gonna start out small

Posted: Mon Apr 25, 2011 12:18 pm
by Taehl
When your game starts getting more complex, you'll want to look into tables. That will allow you to have objects, in a sense, which contain their own data. So instead of needing new global variables for everything, you can call, for instance, tank.x = tank.speed*100*dt. It would also allow you to have arbitrary numbers of enemies. In general, tables are the best part of Lua, in my humble opinion.

Re: Newbie here gonna start out small

Posted: Thu Apr 28, 2011 5:09 am
by Wulfie
Taehl wrote:When your game starts getting more complex, you'll want to look into tables. That will allow you to have objects, in a sense, which contain their own data. So instead of needing new global variables for everything, you can call, for instance, tank.x = tank.speed*100*dt. It would also allow you to have arbitrary numbers of enemies. In general, tables are the best part of Lua, in my humble opinion.

..... metatables???