So I'm wanting to use pseudo multiple class inheritance to derive my Player class from the Sprite class, but then extend it with a generic Actor class, which contains common attributes for players and enemies, and after that, add some of my own specific functions. I'd rather just have my Actor class as a map which I can add, instead of having to manually go through and define additional attributes and methods, so I was using something like the following code
Actor = {"lives":3,"speed":0,...}
Player = new Sprite
Player = Player + Actor
Player.status = function()
if self.speed == 0 then
return 'You can't move"
else
return "Keep on movin'"
end function
player = new Player
I just wonder what I am losing doing it this way and if there is a better way to do it? I know doing it this way I won't be able to test if Player isa Actor since I'm not adding the extra class with a "new" command.
Should I instead be doing the following? If so, can I put that Player function in a PlayerPrototype and add it that way instead? I just like the idea of keeping my prototypes nice and compact in a map line rather than spreading it out over a bunch of code lines. Or I suppose you can add a Prototype function which does all the setup to compartmentalise the code a bit more?
ActorPrototype = {"lives":3,"speed":0,...}
Actor= new Sprite
Actor = Actor + ActorPrototype
Player = new Actor
Player.status = function()
if self.speed == 0 then
return 'You can't move"
else
return "Keep on movin'"
end function
player = new Player
Also if the above is valid, how do I use .super to access base methods of either the Sprite or the Actor?