classes and oop


The worst thing ever but also so usefull.

Why do game producers need clasess and in lua? Well… there is this strange tutorial on lua pages about metatables and it has even inheritance but for some reason i stopped using it. The problems with tables is that you define anything there a table for tilemap a table for object a table for background. But you can not tell what the table is used for if you handle many object. So either using IF ELSE that will bloat your code or change to classes and let them handle each instance of tabled object.

After running through lua only with tables and calling functions to handle them i was alright and the game worked fine. Until it changed into a spaghetti mess and i lost the track on what to use and when it will work. So a big project is better handled by using classes. But in lua and LOVE2D you only have a class system that someone else implemented in lua. So maybe it will have flaws and you will find them sooner or later by using them. Currently i tried two class libraries and i found small bugs in them so i skip this part.

Later using spry api i found that the author implemented the class in c++ so it is in lua at least as something hidden that i do not go into the code to look for errors. They work and it is ok. One small problem i had was about the inheritance. Best way is to avoid it if not necesary. Level 2 inheritance is ok. But when you go further and start to inherit more and more onion layers you will cry later trying to figure out where the problem while debugging is. In spry and zerobrane studio IDE the debugging for some reason works but you can not go into the functions call and they are skipped unless you put a breakpoint in and then run over it. While this does not work i do not know, but you can always use visual studio code to have the debugging working.

For the game it is best to have a simple object like class which has image, boundaries and other components based on what the object is in the game. A tilemap is an object but has no image, but tileset and the cells that act as a tiles from the tilemap. Either by using spry tilemap which is for now in this year of release only there to have a simple background walls and entities. Other layers could prove wrong because i did not find any sorting mechanics while using it. But you do small games most of them retro looking so no need to be angry here.

Make the classes and put them in world to render and update. Nothing else needed. The collision system works mostly on box2D which is also limited to simple things. But it will work after you try and try again. Failures need to be explored.

For more better looking games where you even put blending, lights and shadows you need to look elsewhere. And the language used will be propably c#. And the code will also use other API so ou learn again. Choose based on your needs and computer tech used. These c# engines are not small like lua engines. But they may have all that you need and want from the workbench so you can develop small or in team to release a new game that the market will buy.

Leave a comment

Log in with itch.io to leave a comment.