LOVE:Snake

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Jon93
Prole
Posts: 9
Joined: Fri Aug 01, 2008 10:58 pm

LOVE:Snake

Post 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 .
User avatar
Xfcn
Citizen
Posts: 65
Joined: Sat Jul 12, 2008 6:53 am

Re: LOVE:Snake

Post 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.
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: LOVE:Snake

Post 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 12016 times
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)
Jon93
Prole
Posts: 9
Joined: Fri Aug 01, 2008 10:58 pm

Re: LOVE:Snake

Post 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.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: LOVE:Snake

Post 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
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)
Jon93
Prole
Posts: 9
Joined: Fri Aug 01, 2008 10:58 pm

Re: LOVE:Snake

Post 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.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: LOVE:Snake

Post 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 11911 times
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)
Jon93
Prole
Posts: 9
Joined: Fri Aug 01, 2008 10:58 pm

Re: LOVE:Snake

Post 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.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: LOVE:Snake

Post by rude »

Here's a minimal snake game.

15 minutes, 90 lines of code. ^^
Attachments
snake.love
(1.04 KiB) Downloaded 476 times
User avatar
Xfcn
Citizen
Posts: 65
Joined: Sat Jul 12, 2008 6:53 am

Re: LOVE:Snake

Post by Xfcn »

Awesome stuff, rude!
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests