Snake Game Movement
Snake Game Movement
I am fairly new to LÖVE2D though i have experience with lua. I currently want to make a snake game, but I'm having trouble with making the movement of it. The best I've got is a white square that can move, and cant change opposite directions. Though, if you press up/down then press the opposite direction button, you will be able to. any idea's of how to make the movement like the snake, where it jumps a certain amount?
Re: Snake Game Movement
By incrementing the x and y positions in a fixed amount you can make it "jump" as you want. You can also achieve the delay between jumps by following the first example here: https://love2d.org/wiki/love.update only instead of making the npc think, you're making the snake jump to the next position.
Re: Snake Game Movement
Please explain moretuupakku wrote:By incrementing the x and y positions in a fixed amount you can make it "jump" as you want. You can also achieve the delay between jumps by following the first example here: https://love2d.org/wiki/love.update only instead of making the npc think, you're making the snake jump to the next position.
Re: Snake Game Movement
I have created a simple LÖVE project and commented it (perhaps a bit too much), maybe that will give you a better understanding of how it's supposed to work? Here it is:blorbin wrote:Please explain moretuupakku wrote:By incrementing the x and y positions in a fixed amount you can make it "jump" as you want. You can also achieve the delay between jumps by following the first example here: https://love2d.org/wiki/love.update only instead of making the npc think, you're making the snake jump to the next position.
The gist of it is that instead of updating the x and y coordinates every frame, you want to wait for some time before the next step. Also the snake should move at a constant rate every step (the same amount as a side of one of its nodes) top achieve the grid-like movement common to snake games.
If you still have any questions feel free to ask.
Re: Snake Game Movement
Great! Thanks so much! The only thing now is (ex.) if your going right, and press up then left quickly, you will still be able to go the opposite direction). Otherwise that helped a lot. I'm guessing the way to fix that is to create an if statement for how far its traveled, some how?tuupakku wrote:I have created a simple LÖVE project and commented it (perhaps a bit too much), maybe that will give you a better understanding of how it's supposed to work? Here it is:blorbin wrote:Please explain moretuupakku wrote:By incrementing the x and y positions in a fixed amount you can make it "jump" as you want. You can also achieve the delay between jumps by following the first example here: https://love2d.org/wiki/love.update only instead of making the npc think, you're making the snake jump to the next position.
The gist of it is that instead of updating the x and y coordinates every frame, you want to wait for some time before the next step. Also the snake should move at a constant rate every step (the same amount as a side of one of its nodes) top achieve the grid-like movement common to snake games.
If you still have any questions feel free to ask.
Re: Snake Game Movement
Oh damn, you're right. I fixed it by adding the next direction to the snake table and only updating it on the next step.blorbin wrote:Great! Thanks so much! The only thing now is (ex.) if your going right, and press up then left quickly, you will still be able to go the opposite direction). Otherwise that helped a lot. I'm guessing the way to fix that is to create an if statement for how far its traveled, some how?tuupakku wrote:I have created a simple LÖVE project and commented it (perhaps a bit too much), maybe that will give you a better understanding of how it's supposed to work? Here it is:blorbin wrote: Please explain more
The gist of it is that instead of updating the x and y coordinates every frame, you want to wait for some time before the next step. Also the snake should move at a constant rate every step (the same amount as a side of one of its nodes) top achieve the grid-like movement common to snake games.
If you still have any questions feel free to ask.
Here's the fixed version:
Re: Snake Game Movement
Yaay! Thanks! I've seen a tutorial for making the points randomly spawn, and I've got and idea on how the points would make it grow. Thank you!tuupakku wrote:Oh damn, you're right. I fixed it by adding the next direction to the snake table and only updating it on the next step.blorbin wrote:Great! Thanks so much! The only thing now is (ex.) if your going right, and press up then left quickly, you will still be able to go the opposite direction). Otherwise that helped a lot. I'm guessing the way to fix that is to create an if statement for how far its traveled, some how?tuupakku wrote: I have created a simple LÖVE project and commented it (perhaps a bit too much), maybe that will give you a better understanding of how it's supposed to work? Here it is:
The gist of it is that instead of updating the x and y coordinates every frame, you want to wait for some time before the next step. Also the snake should move at a constant rate every step (the same amount as a side of one of its nodes) top achieve the grid-like movement common to snake games.
If you still have any questions feel free to ask.
Here's the fixed version:
Re: Snake Game Movement
No problem man, best of luck with your game.
Re: Snake Game Movement
I've run into a small problem along they way... Any suggestions?tuupakku wrote:By incrementing the x and y positions in a fixed amount you can make it "jump" as you want. You can also achieve the delay between jumps by following the first example here: https://love2d.org/wiki/love.update only instead of making the npc think, you're making the snake jump to the next position.
Re: Snake Game Movement
In the function food:update(dt) you're only increasing the width of the head segment, so you're making a bigger segment, not a bigger snake. Instead what you need to do is create a new segments field inside your snake where you'll keep every segment and iterate through them when updating/drawing.blorbin wrote:I've run into a small problem along they way... Any suggestions?tuupakku wrote:By incrementing the x and y positions in a fixed amount you can make it "jump" as you want. You can also achieve the delay between jumps by following the first example here: https://love2d.org/wiki/love.update only instead of making the npc think, you're making the snake jump to the next position.
Who is online
Users browsing this forum: No registered users and 4 guests