Hey guys,
I'm very new to Lua, and just started experimenting with LOVE today. I've spend a while trying to brain storm how to do a "Snake" game in LOVE, but I have come up stumped.
My idea is that I make an animation with the snake growing as it gets in contact with the "food", and just having it go frame by frame as you touched more "food". But I am at a loss on how to do that, and as I said before I'm quite new to Lua, so my lack of experience is a factor too.
Another issue is detecting when the snake touches his "tail" and ending the game.
Any pushes in the right direction are greatly appreciated .
LOVE:Snake
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: LOVE:Snake
That's a tall order, honestly. Before I go through a lot of effort, how much previous programming experience do you have? Am I teaching you things from the ground up or are you already familiar with Cartesian coordinates and array variables? It's pretty important to what I wind up putting here.
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
- qubodup
- Inner party member
- Posts: 775
- Joined: Sat Jun 21, 2008 9:21 pm
- Location: Berlin, Germany
- Contact:
Re: LOVE:Snake
I started creating some hints, but then realized that I probably would use an unclean style, so I now started to implement a snake game to make sure my game logic design makes sense.
This is the only image that has survived:
This is the only image that has survived:
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
Re: LOVE:Snake
Ground up, I knew very little C#, and that was at least 2 years ago, and now I just started to learn Lua.Xfcn wrote:That's a tall order, honestly. Before I go through a lot of effort, how much previous programming experience do you have? Am I teaching you things from the ground up or are you already familiar with Cartesian coordinates and array variables? It's pretty important to what I wind up putting here.
I know most base Lua, syntax, tables, functions,callbacks, and what they all mean.
- qubodup
- Inner party member
- Posts: 775
- Joined: Sat Jun 21, 2008 9:21 pm
- Location: Berlin, Germany
- Contact:
Re: LOVE:Snake
Well, how about creating an array of arrays, which will be the map matrix, from which you will draw the tile-based map.
The map can contain empty, snake or fruit fields.
Then create an array of arrays, which will contain the coordinates of each snake pieces and be the length of the snake (1+fruits eaten) - arrayOfCoordinates{}
Then create an input listener, which will will create an array containing the coordinates of the field next entered by the snake (nextCoordinate{}), depending of the last pressed key.
Each step do:
Check if nextCoordinate{} is contained in arrayOfCoordinates, because then the snake will run into itself.
Then increase the length of the snake array by one and write for each 2 ... i coordinate to become arrayOfCoordinates[i-1] then set arrayOfCoordinates[1]=nextCoordinate
Then put the coordinates of the snake from arrayOfCoordinates{} into the map array and draw from it
The map can contain empty, snake or fruit fields.
Then create an array of arrays, which will contain the coordinates of each snake pieces and be the length of the snake (1+fruits eaten) - arrayOfCoordinates{}
Then create an input listener, which will will create an array containing the coordinates of the field next entered by the snake (nextCoordinate{}), depending of the last pressed key.
Each step do:
Check if nextCoordinate{} is contained in arrayOfCoordinates, because then the snake will run into itself.
Then increase the length of the snake array by one and write for each 2 ... i coordinate to become arrayOfCoordinates[i-1] then set arrayOfCoordinates[1]=nextCoordinate
Then put the coordinates of the snake from arrayOfCoordinates{} into the map array and draw from it
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
Re: LOVE:Snake
qubodup wrote:Well, how about creating an array of arrays, which will be the map matrix, from which you will draw the tile-based map.
The map can contain empty, snake or fruit fields.
Then create an array of arrays, which will contain the coordinates of each snake pieces and be the length of the snake (1+fruits eaten) - arrayOfCoordinates{}
Then create an input listener, which will will create an array containing the coordinates of the field next entered by the snake (nextCoordinate{}), depending of the last pressed key.
Each step do:
Check if nextCoordinate{} is contained in arrayOfCoordinates, because then the snake will run into itself.
Then increase the length of the snake array by one and write for each 2 ... i coordinate to become arrayOfCoordinates[i-1] then set arrayOfCoordinates[1]=nextCoordinate
Then put the coordinates of the snake from arrayOfCoordinates{} into the map array and draw from it
Thank you for the help, but I have no idea where to start with this. I'm very new to LOVE and Lua in general.
- qubodup
- Inner party member
- Posts: 775
- Joined: Sat Jun 21, 2008 9:21 pm
- Location: Berlin, Germany
- Contact:
Re: LOVE:Snake
I recommend to take one of the tutorials from the homepage and look at the code, then screw with it a bit.Jon93 wrote:Thank you for the help, but I have no idea where to start with this. I'm very new to LOVE and Lua in general.
If you need help you need to more clearly state what you want ("I want to create a window of 800x644pixels with two red dots rotating around the center of it!")
Have some more concepting:
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
Re: LOVE:Snake
qubodup wrote:I recommend to take one of the tutorials from the homepage and look at the code, then screw with it a bit.Jon93 wrote:Thank you for the help, but I have no idea where to start with this. I'm very new to LOVE and Lua in general.
If you need help you need to more clearly state what you want ("I want to create a window of 800x644pixels with two red dots rotating around the center of it!")
Have some more concepting:
I'm still thoroughly lost, but I'll go through the documentation and see what I can come up with.
Re: LOVE:Snake
Here's a minimal snake game.
15 minutes, 90 lines of code.
15 minutes, 90 lines of code.
- Attachments
-
- snake.love
- (1.04 KiB) Downloaded 467 times
Re: LOVE:Snake
Awesome stuff, rude!
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
Who is online
Users browsing this forum: Bing [Bot] and 2 guests