Page 1 of 1

Soo what now?

Posted: Thu Sep 08, 2016 7:42 am
by KayleMaster
I've done my terrain engine, I've never actually gotten this far because of game maker (I was trying so hard to optimize I ran in all kinds of walls, walls that don't exist in Love2D) so I'm not sure what's the next step.
I want units, but how exactly would I approach this? Do I have to adopt some kind of OOP ? Any ideas/tips?

Re: Soo what now?

Posted: Thu Sep 08, 2016 8:39 am
by marco.lizza
Do I have to adopt some kind of OOP ?
Not necessarily. An entity functional mixin-based model would be more than enough.

Re: Soo what now?

Posted: Thu Sep 08, 2016 8:40 am
by KayleMaster
entity functional mixin-based model

Yes, yes.... I know some of these words.
EDIT: are you referring to something like this : https://www.reddit.com/r/gamedev/commen ... nd_mixins/

Re: Soo what now?

Posted: Thu Sep 08, 2016 9:03 am
by marco.lizza
Yes, the approach I suggest is similiar to this. However, keep in mind that you don't necessarily need to incorporate a full-fledged abstraction model and/or library.

Re: Soo what now?

Posted: Thu Sep 08, 2016 4:34 pm
by Inny
Lua's tables are "Duck Typed", as in "If it looks like a duck and walks like a duck, it is a duck." What's becoming all the rage these days are "Entity Component Systems" where you write your code to do some basic level inspection of the tables passed to it in order to determine which code applies to it.

To put it another way, let's say you're making a 2d platformer. Some things will be affected by gravity (like the player), and some things will not (like powerups). The player entity would have a property that says gravity affects it, and the code to apply gravity would check for gravity, and check for the Y position. That would look like this:

Code: Select all

function run_gravity_system(entities)
  for i, entity in ipairs(entities) do
    if entity.gravity and entity.Y then
      entity.Y = entity.Y + entity.gravity
    end
  end
end
In this way, you can always add or remove gravity from any entity in your world.

(Of course, gravity as presented here is not very good, you'd want a deltaY property and some other math going on.)