Need help with my 1st simple game

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Posts: 2
Joined: Tue Aug 28, 2018 12:36 am

Need help with my 1st simple game

Post by TheGypsy » Tue Aug 28, 2018 12:59 am

Hello lovers!

After years of getting into coding for a week....realising I didn't know enough to make Zelda. Getting frustrated and quitting for months. Changing from c# to python and back. Visual studio, unity and game maker studio. I finally know what's made me fail so often. The plight of setting dreams beyond my current capabilities. :(

I've started from square one...learning basic coding concepts that apply to all languages. Simple calculations etc. And I've worked my way up to settling on Lua and am loving it (pun slightly intended.)

I've built a little code that moves 2 joined squares every time variable and change direction when a key is pressed (wasd) the issue I'm having is I'm trying to emulate snake movement.

Now I've just been running an x1 = x1 + 10 or - 10 for each movement period in love.update. the issue I'm having is I can't get the tail square to go where the head square was. They just move as a 10 × 20 pixel rectangle. I'm trying to figure out how to remedy this in my own before I move on to learning collision detection for snake food pickups.

I find that I learn best by figuring the bulk out on my own without direct code in front if me, otherwise I just get lazy and copy code without understanding it. So I just need help with the concept. I'm thinking what I need to do is create a table that holds the x, y coords of each square And cycling the coords down the table index (the idea being a table can be added to later when the snake eats food) but is this the easiest way to do what I'm trying to achieve?

Also what concept do I need to understand to get the coords to trail down the table?

This is my 1st post on any game dev forum so sorry it's long. I've been lurking your forums and you're all very friendly/knowledgable/helpful so thank you in advance for
a) reading this far and
b) any insight you can offer

and sorry for the rant!


User avatar
Posts: 19
Joined: Tue Jun 19, 2018 4:09 am

Re: Need help with my 1st simple game

Post by Link » Tue Aug 28, 2018 11:57 am

Your idea sounds fine. Each square in the snake's body (e.g. a snake might be 3 squares long) is represented by a x/y coordinate. Every update delete the last x/y coordinate at the end of the list (its tail), and add a new x/y coordinate to the front of the list (its head). The other squares in the list don't need to alter, only the tail and head.

Party member
Posts: 383
Joined: Sat Oct 22, 2011 7:37 am

Re: Need help with my 1st simple game

Post by Santos » Tue Aug 28, 2018 1:13 pm

Hi Gypsy!

I think the experience that you had of trying to do something beyond your current capabilities (and being frustrated because of it) is very relatable.

I'm glad you've started again from square one. It can be daunting and confusing and, again, frustrating because of the gap between what you're making now and what you eventually want to make.

I can't quite understand how the "try to figure things out on your own" view is very useful. Of course, as you've experienced, copying code without understanding it isn't very useful either, but I think that learning how other people have solved problems is an essential part of learning programming (and probably anything else). I think that doing things on your own is also essential; it puts what you've learned in to practice and lets you know what you know, and what you don't know, and what you need to learn next, and helps solidify your understanding.

Proflific LOVE user josefnpat's first game was mostly copied code mixed with copied graphics (as mentioned in this blog post), and then he went on to make heaps more (original!) games as you can see on his website. I mention this because I think it's an interesting point of reference, and it challenges assumptions you may have (or at least I had). I went into programming with a lot of assumptions about what I should and shouldn't do, "real programmers don't do/use that", and an anxiety about "do I need to learn this?", "how do I do this the proper way?", "am I using the best tools?" etc. I think that if I had instead tried to make small but real projects like josefnpat did I would have been more focused, and what was and wasn't necessary to learn right now would have been more apparent. (And I would have had more fun.)

I remember being in a similar situation to you right now I think. I was trying to make Tetris, and I managed to make a square and then I made it go down the screen, and then I think I made it go left and right using the keyboard, and then I was just totally stuck. I didn't know what concepts I needed to continue.

I found that reading other people's code, line by line, and trying to figure out what was going on, really increased my understanding more than whatever I was trying to do before that. I knew what if statements and functions and tables and all that stuff was, but until I really saw them in action I couldn't "think" in them, I couldn't imagine something and then code it. I also realized that the programming process was also important, not just the solution but how one goes about getting to that solution.

I've written some tutorials including one on how to make a snake game:

These tutorials are my attempt at creating what I wish I had access to when I was just beginning. They involve reading code, but unlike a complete game with hundreds of lines of code to make sense of, they start off with just a few lines, and then the next step adds a few more, until the game is complete. My intention was to make each change to the code small enough that the new code could be easily read, and you do need to think a little bit about what the code does and how it works, but hopefully it's easy to digest being in bite-sized morsels. It also mimics the programming process of changing a little bit of code and then testing it.

It was also important to me that I made numerous tutorials so the reader could see the same concepts used again and again in slightly different contexts. Once you learn the concepts you can then apply them to your own things. For example, if I had read some of these tutorials before I tried to make Tetris maybe I would have thought "I'll use a grid with strings representing the blocks like in Sokoban, and a timer to move the blocks down like in Snake". I hope it gives the reader's imagination something to work with.

So, my advice would be going through those tutorials and the bigger and better tutorials here and not just copying the code but reading them slowly and trying to understand every line (or if you don't understand something and you're feeling bogged down maybe making a note of it and skipping over it for now), and then using the concepts that you pick up in your own projects and expanding on them and experimenting.

My advice is probably terrible, but whatever you do I hope you have fun and enjoy the process of learning, and if you keep learning and practising then I'm sure you'll be making Zelda before you know it! :)

Posts: 2
Joined: Tue Aug 28, 2018 12:36 am

Re: Need help with my 1st simple game

Post by TheGypsy » Wed Aug 29, 2018 1:42 am

Thank you both!

Link that idea has made perfect sense as the table just adds 1 new square and deletes the last place the tail went, then the middle ones don't have to be cycled through because the head becomes a body square and a new head is made! I'll play around with that tonight.

Santos thank you! I've had a quick flick through your codes and they look super helpful. I'll no doubt be choosing another one of your projects once I finish my snake to learn more concepts.
And yeah I have sort of decided that when I've written super simple bits of code that almost every game will use (wasd movement for top down rpgs) (timers for everything that uses timers.) I'll just recycle those bits into new games.

Thank you both for your prompt reply and I cant wait for you both to play my zelda/skyrim hybrid a year or 2 from now once I have the skills.



Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests