Re: 3 doesn't equal 3?
Posted: Fri Aug 02, 2019 11:52 am
Hello there! To be honest there are millions of ways to write snake game. The repo that I provided is very simple and easy to understand. And about the old version - well you can run it quick using the appImages for linux or binaries for windows. But if you want to program in the latest version then here's a youtube video which might help you. The author is an instructor at Harvard Extension School - so you shouldn't have much problem understanding what's going on
And if you don't like watching youtube tutorials then head on to this site. The last time I saw the source-code it was like 150 lines long - so this shouldn't be a head-ache plus everything is modular.
Just as an extra comment- please do not disrespect yourself (even in jokes) - or people won't respect you out of their will
But anyways. I downloaded your files. And just a side-comment you don't really need conf.lua in this context. It's useful when publishing game but in this context it's completely unnecessary I'd say. And about your main code- it's humongous and that definitely is not a compliment to a developer. Plus it's broken as well. And I'm no-one to give you advice on programming but - Richard Buckland said this - "It's not the algorithm but the data-structure that is the key to any problem". So rather than working on how to move the snake you should consider "how should I store the snake" and that would be the key to your problem
And finally back to your code. I have seen atleast 5 snake games written in LOVE but not even in one of those did i see anything such as 'alive=true'. Really you should minimize the amount of variables you use - plus the spelling of snake is incorrect (snack - it's no big deal but it can create problems later especially in context of Lua programming). Plus I really can't understand the 'aim in life' of other variables such as place1,etc. And generally speaking there's a rule in programming that if you are using variables that are used only few times or not used at all then you are doing something wrong. In your case many variables are unused like 'success' (even if setMode does return a boolean - you don't need anything to store it to some variable for it to work) 'way' (what's the use of 'way'?) and complementary1,...,complementary3.
Also I strongly discourage on using isDown function for this purpose- i remember when I was programming snake (it's super ugly so I didn't upload it on my github. plus it's not even polished ) it was causing a lot of buggy behaviour since you will only change direction of snake on one frame - but isDown will be true for as long as the key is pressed - which we don't want in this case.
There are lot more errors which I won't point out- since i don't want to discourage you. Well figuring out things on your own is a good idea but you should also look at how other people solved the same problem. In programming is all about - "finding the best possible solution to a problem?" - so how would you know if your solution is the best unless you compare it with that of your peers.
Regards