You can’t fly because of your lack of wings component

Entity Component System – what the hell is that thing? It has entity, It has component, and system. But what the hell is that?

200_sCats are funny

I am developing game right now, it’s called Call Of The Death Mask, and about month ago I had a headache. Reason of my headache was the question “How I can make zombies fly?”
What to do if your game designer want to make all treasures chests in game to have teeth and attack player character? And if you ask him “Dude are you crazy?” he will replies to you with magic word “Mimic”
Mimics are fictional living creatures, that looks like ordinary things, but they can attack you.


Mimic by BenWootten on DeviantArt

At this point you probably have class called Chest and it can’t attack anyone, because it’s not belongs to enemy class hierarchy. Damn what to do?
Entity Component System gives good approach that works ideally for games. You create class called Entity, and construct every object in game by filling Enitity with Components. Component is just some property of Entity. For example in my game all zombies have:

  1. Position component (x, y, z – Vector)
  2. Sprite component (Zombie.png – image)
  3. Rotation angle component (x, y, z – Vector)
  4. Zombie AI component (to behave like zombie)

Ok, so how to make all treasure chests into mimics at some point of level. Treasure Chest will have those components in my engine:

  1. Position component (x, y, z – Vector)
  2. Sprite component (Chest.png – image)
  3. Rotation angle component (x, y, z – Vector)
  4. Item component (to give that item to player, when he will open it)

And now we just add Mimic AI component to Treasure Chest at runtime, and he will attack player at right moment. And if some magic spell can make Mimics into Treasure Chests, then we just need to remove Mimic AI component at game runtime for that Treasure Chest, or for all of them (for cool spells that applies to all game map)
What stands for System at this pattern? System handles components for every entity. For example if player character have weapon component, then UI System must get weapon component and render it on screen.

screenshot_2016-09-24_14-33-43

Weapon component must have necessary data for UI System. In my game every weapon have two components:

  1. On map sprite component (it shows if weapon dropped to the ground)
  2. Iron sight component (it shows when player get weapon)

Shotgun weapon component at map, and another in player’s character hands, one rendered by scene renderer, another by ui renderer.

Links about ECS pattern:
https://en.wikipedia.org/wiki/Entity_component_system
https://www.youtube.com/watch?v=NTWSeQtHZ9M

0