Page 1 of 1

help with moving entities

Posted: Sat Aug 04, 2012 12:55 am
by Chasm.Creativeworks
I want to preface this post with two apologies. One for the inevitable "why couldn't you find this via the search option?" comments, and the other for being such a massive n00b, not only at LOVE/Lua itself, but at programming/coding universally.

Ive been following the Goature youtube videos to learn the basis of LOVE2d and Lua coding and such, and I feel like I've come a long way, at least in my general understanding of how the program functions and how code is interpreted.

However, upon completion of my first few initial goals (get entities to work, get a tile map built, move the map around via directional keys) I have come to a point where I have no idea how to go about working towards the next goal of making an entity that I can move with the directional keys, and that will, as its moving, move the map with it.

I downloaded a few .loves here off of various other threads to check their code, and it almost (to me) looks like theyre just making the code up as they go. There are all sorts of functions and things going on that I dont see anywhere in the Love wiki, etc.

Can anyone explain this simply to me? Can I just make/name a function, and then as long as code it right itll do whatever i want? Is it really that simple??

Any advice, guidance would be VASTLY appreciated.

Thank you,
Justin

Re: help with moving entities

Posted: Sat Aug 04, 2012 3:01 am
by Qcode
How do you mean making stuff up? Because really they're not "making" it up, they are following all the rules of love and Lua while programming. However if you mean that they are constructing this code without getting the code from a website or a video tutorial, then you are correct. Yes if you make a function and code it correctly, then call it somewhere else (in a love function such as love.update or even in another function that will then later be called in a love function) then that will work in your game. If you call the function without it existing, however it will error, and if you don't call it at all then it won't have an effect in your game. Don't be embarrassed by this, when I started learning love, it took me a while to learn this concept as well. Once you do though, coding and programming your games becomes a lot more fun, as you are no longer restricted to following others tutorials and copying people directly. You can make things freely and with enough thought any of your game ideas are possible! Heck, people have been making 3d tests for love. If you've been living under a rock for the past 3 months then you'd be surprised to know someone even combined the original new super Mario bros with Valve's Portal, using love.

Tl;dr: Yes, Yes but I recommend you read my long paragraph as it explains things a lot better and it has an inspirational speech at the end :3

Re: help with moving entities

Posted: Sat Aug 04, 2012 3:15 am
by Roland_Yonaba
Here is a very basic code that draws a circle, and let you move it with directionnal keys.
That's fairly simple, and the logic is pretty straight-forward to catch.

Code: Select all

function love.load()
   x,y = 0,0
   radius = 10
end

function love.update(dt)
    if love.keyboard.isDown('left') then x = x - 100*dt end
    if love.keyboard.isDown('right') then x = x + 100*dt end
    if love.keyboard.isDown('up') then y = y - 100*dt end
    if love.keyboard.isDown('down') then y = y + 100*dt end
end

function love.draw()
    love.graphics.circle('line',x,y,radius)
end
Well, Love is framework for 2D games, which runs Lua code.
So, you have to now the basics of Lua programming.
Second, to dive into Love2d, a good place to start is the wiki.
Take a quick peek at this: Getting Started
And also this: Love Module (basics you have to catch are Modules and Callbacks)

There are some good resources over the net:
Love2D for beginners
headchant's tutorial
Eben's Tutorial

Hope that might help.

Re: help with moving entities

Posted: Sun Aug 05, 2012 6:00 am
by Chasm.Creativeworks
Thank you both so much! I talked with a friend a bit and he helped me figure some of it out, but your code helped finalize the understanding in my head.

Now my problem is that I want my tile/sprite to move EXACTLY the tile size (32x32) when I press a directional key.

1 press of "right" = a full 32pixel move onto another tile (x+32). I cant seem to make it move that exact amount.... if I use x+32*dt, it moves 32p per second, but will stop whenever I let go of the key. If i remove the [*dt], then the test tile/cursor just FLIES off the map in any direction I press.

Thoughts? Is it some simple code I'm just not seeing?

Thanks again,
Justin

Re: help with moving entities

Posted: Sun Aug 05, 2012 6:41 am
by Santos
The gridlocked player tutorial may be of help! ^^