[HOW DO I] make a snake game's tail work?
[HOW DO I] make a snake game's tail work?
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
Last edited by get52 on Fri Sep 13, 2013 6:56 pm, edited 1 time in total.
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?
Please be more specific: What have you got and what parts are not working/ what parts can you not figure out?
Check out my blog on gamedev
Re: [HOW DO I] make a snake game's tail work?
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?
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?
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.
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.
Re: [HOW DO I] make a snake game's tail work?
If you do it via grid, save where head went for each snake piece. If head went to the left (absolute direction) then save to grid "snake left" or whatever, etc. When you move a tail, you read that direction from a grid, erase the cell, and shift tail coordinates one cell in specified direciton.
However you actually do it, you need to keep track of segments' directions.
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
Re: [HOW DO I] make a snake game's tail work?
I assign a number to each segment and I increase each by one every tick, then I check if it's higher than the snake's length and remove it if it is.
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?
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.
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?
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.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
Re: [HOW DO I] make a snake game's tail work?
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.
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?
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
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
Who is online
Users browsing this forum: No registered users and 0 guests