Page 1 of 1

Better Snake [1.0]

Posted: Tue Jan 23, 2018 12:20 am
by AngusWP
BetterSnake is my spin on the game snake. I started with Lua and Love2D today, and looked up a snake tutorial. From there I just modified the game and gave it more features. You can look at the code for this if you want, it's not very advanced. The reason I am posting here is to ask: Are there any really informative tutorials on Love2D? I have previously coded in Java and I want to learn Lua as it seems to be a lot easier and just as fun.

https://github.com/AngusWP/bettersnake

Another thing I want to ask - when I tried to run main.lua inside a package, it wouldn't run. I am used to packages through Java but what is the normal way to structure Lua code, and if there is no package system is there a better way to keep everything organized and not just in one huge class?

Another thing, I wanted to add a game icon but I can't convert my image into image data, does anyone know how to make this work?

Code: Select all

icon = love.graphics.newImage("images/snake_icon.png");
love.window.setIcon(icon:getData());
    
Thanks for reading my post! If you would recommend any game projects that don't take too much work but will teach me more about Lua, just let me know. I want to learn!

Re: Better Snake [1.0]

Posted: Tue Jan 23, 2018 4:17 am
by Sir_Silver
I can't speak from experience, but people have recommended checking out sheepolution for love2d specific tutorials: http://sheepolution.com/learn/book/0

With regards to the code you've written, works perfectly fine for me. Is your snake_icon.png image inside of your images folder?

Re: Better Snake [1.0]

Posted: Tue Jan 23, 2018 8:34 am
by zorg
You should load in the image file as an ImageData instead, since you cannot convert Images to ImageData anymore; that way you can pass the ImageData to setIcon. (Use love.image.newImageData)

Also, define packages, since i fail to understand what you mean by keeping everything organized in one "class"; don't use classes? or look at kikito's library tutorial, where he details how to isolate code into separate files: http://kiki.to/blog/2014/03/30/a-guide- ... a-modules/

Re: Better Snake [1.0]

Posted: Tue Jan 23, 2018 11:46 am
by AngusWP
Sir_Silver wrote: Tue Jan 23, 2018 4:17 am With regards to the code you've written, works perfectly fine for me. Is your snake_icon.png image inside of your images folder?
I changed it to image data, and the code runs fine but the actual window does not show it. I googled it and it turns out sometimes there is an issue where other people can see it but the person who wrote it can't? This could be a bug with Zero Brain Studios or something.

Re: Better Snake [1.0]

Posted: Tue Jan 23, 2018 11:47 am
by AngusWP
zorg wrote: Tue Jan 23, 2018 8:34 am Also, define packages, since i fail to understand what you mean by keeping everything organized in one "class"; don't use classes? or look at kikito's library tutorial, where he details how to isolate code into separate files: http://kiki.to/blog/2014/03/30/a-guide- ... a-modules/
Yeah classes are a Java thing sorry, I meant I don't want to have everything in one .lua file and want to be able to keep it organized in different .lua files.