Thank you, you even made me a code snippet. -edit OMG YES ITS NOT SUPER FAST I LOVE YOU.Nixola wrote:You should have a 'timer' variable and only trigger a snake update each time that variable is more than a certain value. Example:Code: Select all
love.load = function() timer = 0 timerLimit = 0.1 --other code end love.update = function(dt) timer = timer + dt if timer > timerLimit then --update the snake, this is what I call 'tick' end --other code end --rest of the code
[HOW DO I] make a snake game's tail work?
Re: [HOW DO I] make a snake game's tail work?
Only douchebags tell the admins to delete threads once they get they're answer.
Re: [HOW DO I] make a snake game's tail work?
How do i make a parent child relationship? (I did it alot in 3D design i just dont know how to do it in love2D im a noob lolPlu wrote:Assign each tail a parent that it's following. For the first part this is the head, for the second part of the tail it's the first part, etc.
On every update, move every part of the tail to the exact location of its parent part, and then finally move the head to its new position. Make sure you start at the end of the tail when doing this, and work your way towards the head.
That should get you the effect you are looking for.
Only douchebags tell the admins to delete threads once they get they're answer.
Re: [HOW DO I] make a snake game's tail work?
Code: Select all
snake = {}
snake.head = --code to create the head, such as direction, position, etc;
snake.children = {}
snake.children[1] = {} --code to create the first tail square
snake.children[1].parent = snake.head
Code: Select all
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a = 6
> b = a
> b = 7
> print(a)
6
> print(b)
7
> --this is what happens with strings, booleans and numbers
> t = {field = 6}
> v = t
> v.field = 7
> print(t.field)
7
> print(v.field)
7
> --you see? it's the exact same table, not a copy
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: [HOW DO I] make a snake game's tail work?
Since each part just needs access to its parent, you can just make them into a sort of linked list:
This leaves you with the tip of the tail in the last variable, and you can loop upwards through all the other parts by using the parent property.
So you could do something like this to loop the snake:
This should work. But I didn't test it, so can't be sure
Code: Select all
function part( parent )
return {
x = 1, y = 2, -- etc, stuff goes here
parent = parent
}
end
local last = nil
for i = 1, 10 do
last = part( last )
end
So you could do something like this to loop the snake:
Code: Select all
local copy = last -- or whatever you called the tip of the snake's tail.
while copy do
-- handle the part, like drawing it or such
drawFuncOrWhatever( copy )
copy = copy.parent
end
Re: [HOW DO I] make a snake game's tail work?
How long did it take you to get good at this ive only used love for a week or so and this is really confuseing I dont know what to do I'm thinking I should do the snake game after i learn more about love/lua how did you get started? I really whanna make games but im really fucking confused ._. I'm 13 and I dont feel that i can do it. ._.Plu wrote:Since each part just needs access to its parent, you can just make them into a sort of linked list:
This leaves you with the tip of the tail in the last variable, and you can loop upwards through all the other parts by using the parent property.Code: Select all
function part( parent ) return { x = 1, y = 2, -- etc, stuff goes here parent = parent } end local last = nil for i = 1, 10 do last = part( last ) end
So you could do something like this to loop the snake:
This should work. But I didn't test it, so can't be sureCode: Select all
local copy = last -- or whatever you called the tip of the snake's tail. while copy do -- handle the part, like drawing it or such drawFuncOrWhatever( copy ) copy = copy.parent end
Only douchebags tell the admins to delete threads once they get they're answer.
Re: [HOW DO I] make a snake game's tail work?
I started at around your age with this kind of stuff as well, that's been about 14 years. The best thing you can do is not give up and keep messing about with stuff you like. You'll learn eventually.
It might also help to get some books on programming, although most of them are probably aimed at people a few years older, so maybe it's better to just keep playing around for a few years. You have to make a lot of crap before you can start producing gems Best get the crap out of the way as early as possible.
It might also help to get some books on programming, although most of them are probably aimed at people a few years older, so maybe it's better to just keep playing around for a few years. You have to make a lot of crap before you can start producing gems Best get the crap out of the way as early as possible.
Re: [HOW DO I] make a snake game's tail work?
you can always read lua first edition.
- shatterblast
- Party member
- Posts: 136
- Joined: Tue Dec 11, 2012 9:47 pm
- Location: Dallas, Texas, USA
Re: [HOW DO I] make a snake game's tail work?
I'm just a hobbyist programmer, and I found this link useful and educating for learning parts of LUA:
http://nova-fusion.com/2012/08/27/lua-f ... rs-part-1/
http://nova-fusion.com/2012/08/27/lua-f ... rs-part-1/
Re: [HOW DO I] make a snake game's tail work?
You can also use Box2D to make the tail, here an example with box2d:
Re: [HOW DO I] make a snake game's tail work?
AwesomeSauce just Awesome sauce thanks for all the help guys lolFireZenk wrote:You can also use Box2D to make the tail, here an example with box2d:
Only douchebags tell the admins to delete threads once they get they're answer.
Who is online
Users browsing this forum: Amazon [Bot] and 2 guests