Log In  

Cart #class_inherit_example-1 | 2021-01-30 | Code ▽ | Embed ▽ | No License
4

Classing Example

While I like lua, it drives me crazy that it does not contain a simple class constructor like python, or newer version of javascript. I find the metatable concept to be very awkward and difficult to adjust to, coming from other scripting languages.

Here, I am demonstrating how I typically handle my actor objects when making games using an object-oriented approach. I like all of my game entities (like the player and NPC characters) to be their own objects with methods that are common to them (update and draw being the main needed items).

The snippet here is my starting templet for most of my games. The "Actor" table is my default object. The method "New" can be used for two things:

  • creating a subclass which will inherit all properties and methods of actor, unless they are overwritten explicitly
  • instantiating the "actor" into the game

If you are looking for a code snippet to get started and you want to use an object oriented approach, I encourage you to give this a try. Thanks!

-PBG

P#86967 2021-01-30 16:00


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-16 22:12:09 | 0.013s | Q:14