How would I make a Snake game in LÖVE?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
vesper
Prole
Posts: 2
Joined: Fri Jun 23, 2017 5:23 am

How would I make a Snake game in LÖVE?

Post by vesper »

I know some Lua, but I just started using LÖVE. How would I start?
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: How would I make a Snake game in LÖVE?

Post by erasio »

The getting started tutorial would be a good start

(Such general questions are difficult to answer since no one can know what exactly you have issues with. Is it the logic behind a snake game? Or how to draw stuff? Are you getting stuck with lua syntax or have issues with updating your gamestate consistently?)

If you have a more concrete question pop back in and I'm sure the people here will löve to help you! :awesome:
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How would I make a Snake game in LÖVE?

Post by zorg »

And if you don't have a more concrete question for us, then apologies, but "we won't make your game for you".
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: How would I make a Snake game in LÖVE?

Post by MasterLee »

What is good a worms styled games is that you only need an tilemap and an counter score for the gamestate.
So but how about making an game. First define what will happen. Then try to convert it into an algorithm.
So maybe the next thing you should do is to write up how an snake game is defined. Which rules are given and which are are possible by player.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: How would I make a Snake game in LÖVE?

Post by Sir_Silver »

Start writing your game, and if you need help with something specific, I would love to help you.
vesper
Prole
Posts: 2
Joined: Fri Jun 23, 2017 5:23 am

Re: How would I make a Snake game in LÖVE?

Post by vesper »

Yeah, I'm new to Love. I only want to use squares.. I just don't get how first off I would set making the "Grid" system where only 4 directions are possible to move in
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: How would I make a Snake game in LÖVE?

Post by Sir_Silver »

Well, that doesn't require a lot of love knowledge, just lua. What's your experience with lua, do you know what a table is? The simplest way I can think of to make a grid is to make a 2D table.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: How would I make a Snake game in LÖVE?

Post by erasio »

You don't actually need a table for this one.

Basically (as in quite a lot of games), the gameplay has little to do with the graphics. Now you do want to end up in a situation where all relevant information is displayed.

That's why update and draw are different functions / calls.

You absolutely can draw within the update loop. But you shouldn't do that because it's two separate systems. They do separate things (also if you draw during the update loop you have a not complete game state. It's still simulating the next state.

Logically speaking. You need a position system. Regular 2D locations. Since we have very simple and grid based movement we only need full numbers.

So now each movement update (which could be per frame or every x second (0.5 for example) or something along those lines).

Anyway. Each movement update you move your snake forward one "unit" in X OR Y direction (never both).

And you already have gridbased movement!

Now for visualization and screen edge wrapping we need some additional elements. Since the size of one pixel isn't particularly useful. We'll simple scale all the data for the graphics. For example let's say we make each square 50 px large. Now we simply have to multiply all gameplay position data by 50. Done.

To wrap at the screen edges we need to know where they are. You can get the screen size from love.window. Divide screen size by your square (tile) size. Floor the result (so all tiles are completely within the screen). And if the next position would be beyond this max or the min size (1) go the the other max. (Modulo makes your life really easy here).

And that's pretty much all you need to have the complete snake movement.

Edit: I would like to mention here that löve2D isn't particularly friendly to people who are new to game development. As it requires quite a lot of knowledge about software architecture and game engines.

You will often have to implement things on your own systems that are usually provided in game engines.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: How would I make a Snake game in LÖVE?

Post by Santos »

I wrote a tutorial for making a snake game in LÖVE: https://simplegametutorials.github.io/snake/

Try typing or copying the code at each step and running it, and experimenting with it if you want. If there's something Lua or LÖVE related which is used that you don't understand, you can research it. Or, if you don't understand the way in which something works, you can think about it line by line, or run it line by line in a debugger.

More tutorials and an introduction can be found here: https://simplegametutorials.github.io/
TheMajesticMagikarp
Prole
Posts: 8
Joined: Tue Apr 11, 2017 12:11 am

Re: How would I make a Snake game in LÖVE?

Post by TheMajesticMagikarp »

Since you are new to Love2D, I would recommend making small projects and games with the knowledge that you have already. After you complete each project/game dig deeper into what you can do. Also Snake is a common game and it is perfectly fine to download one that has already been made and look at that code. Just don't copy and paste the code and claim that it is yours. The more you mess around with Love2D and researching, the more you will expand your knowledge and be able to complete more difficult tasks.
Post Reply

Who is online

Users browsing this forum: No registered users and 61 guests