Page 1 of 2

LOVE:Snake

Posted: Fri Aug 01, 2008 11:09 pm
by Jon93
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 :D .

Re: LOVE:Snake

Posted: Sat Aug 02, 2008 9:03 am
by Xfcn
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.

Re: LOVE:Snake

Posted: Sat Aug 02, 2008 12:26 pm
by qubodup
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:
path3432.png
path3432.png (8.73 KiB) Viewed 11617 times

Re: LOVE:Snake

Posted: Sun Aug 03, 2008 7:57 pm
by Jon93
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.
Ground up, I knew very little C#, and that was at least 2 years ago, and now I just started to learn Lua.

I know most base Lua, syntax, tables, functions,callbacks, and what they all mean.

Re: LOVE:Snake

Posted: Sun Aug 03, 2008 9:13 pm
by qubodup
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

Re: LOVE:Snake

Posted: Mon Aug 04, 2008 5:19 pm
by Jon93
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.

Re: LOVE:Snake

Posted: Mon Aug 04, 2008 10:38 pm
by qubodup
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.
I recommend to take one of the tutorials from the homepage and look at the code, then screw with it a bit.

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:
snake.png
snake.png (148.2 KiB) Viewed 11512 times

Re: LOVE:Snake

Posted: Tue Aug 05, 2008 3:46 pm
by Jon93
qubodup wrote:
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.
I recommend to take one of the tutorials from the homepage and look at the code, then screw with it a bit.

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:
snake.png

I'm still thoroughly lost, but I'll go through the documentation and see what I can come up with.

Re: LOVE:Snake

Posted: Tue Aug 05, 2008 8:18 pm
by rude
Here's a minimal snake game.

15 minutes, 90 lines of code. ^^

Re: LOVE:Snake

Posted: Wed Aug 06, 2008 12:46 am
by Xfcn
Awesome stuff, rude!