[HOW DO I] make a snake game's tail work?
Posted: Fri Sep 13, 2013 12:18 pm
I have no F'ing idea and im stuck just here please help me my snake isnt gridlocked. im being special. Its gridlocked now lol
how to get the tail to follow the player.micha wrote:Please be more specific: What have you got and what parts are not working/ what parts can you not figure out?
Code: Select all
if snake.move then
if snake.head.direction == "left" then
map[snake.head.x][snake.head.y] = "snake left" -- record where head went
snake.head.x = snake.head.x + 1 -- dummy for moving left
--snake.head.y = snake.head.y
map[snake.head.x][snake.head.y] = "snake left" -- place head to the next position
end -- etc.
local piece = map[snake.tail.x][snake.tail.y]
if piece == "snake left" then
map[snake.tail.x][snake.tail.y] = "empty"
snake.tail.x = snake.tail.x + 1
--snake.tail.y = snake.tail.y
end
end
That's genius, also how do i do every tick is it like love.everytick or something like that i cant find it anywherePlu 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.
It's called love.update(dt)get52 wrote:That's genius, also how do i do every tick is it like love.everytick or something like that i cant find it anywherePlu 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.
god I feel like a dumbass...When i do that it makes it go super fast. also i made the snake gridlocked.Davidobot wrote:It's called love.update(dt)get52 wrote:That's genius, also how do i do every tick is it like love.everytick or something like that i cant find it anywherePlu 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.
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