Explenation of the Type & Group system?
Closed this issue · 8 comments
I'm reading the impact++ docs and I don't understand anything.
What are 'bitflags'? How do I add a type to my 'player' entity and my 'item' entity?
I need my player to check against 'items'. This is what I need, right?
Bitflags: http://www.cplusplus.com/forum/general/1590/
In original impact, you have 3 types (bitflags): A, B, and BOTH. The nice thing about these bitflags is that we can combine up to 32 different bitflags into a single bitflag and then check for any one of them using the "&". So we do that in impact++. For example, you have an entity that is of type ITEM and POWERUP, another entity that is of type CHECKPOINT, and a third entity of type CREATURE and PAINFUL. You want your player should check against all, which is easy, just set the check against to ITEM | CHECKPOINT | PAINFUL. The "|" combines the types and checking for any one of the types in the combination will be true, but instead of doing 3 checks, you only need to do 1 check.
The player already has the type PLAYER and CHARACTER. You can add types to any entity like so: https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/creature.js#L359 (Basically what happens is that the type system checks if that type exists, and if not it makes a new unique bitflag for it, then it combines the bitflag into whatever property you passed to the method. In this example it is the type, but it could just as easily be the checkAgainst)
Groups are just another bitflag, separate from the type property. Two entities in the same group won't collide or check against each other. This is particularly useful for things like projectiles.
Ok, I think I understand now, thanks.
I don't understand this...
how do I exactly set a type for my EntityShuriken
and EntityRad
.
My EntityShuriken is a projectile thrown by my player and it should damage EntityRad
.
So Now I have in my EntityShuriken:
initTypes: function() {
this.parent();
ig.utils.addType(ig.EntityExtended, this, 'group', "FRIEND");
},
And in my EntityRad:
initTypes: function() {
this.parent();
ig.utils.addType(ig.EntityExtended, this, 'group', "ENEMY");
ig.utils.addType(ig.EntityExtended, this, 'type', "DAMAGABLE");
},
But it doesn't work?
Does it work when you don't use groups? You are not adding groups correctly at the moment, you need 1 extra argument like so: https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/player.js#L82 (This is because the type system defaults to using TYPE to store the bitflags, and you want GROUP because the group bitflags are unique from the type bitflags).
Oh, and make sure your shuriken is extending the abstract ig.Projectile! The projectile abstract automatically adds the check against for DAMAGEABLE entities: https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/abstractities/projectile.js#L91 (fyi, you spelled DAMAGEABLE wrong when adding the type to your rad, so that could also be why the shuriken won't hit the rad).
Also, anytime you use the ig.AbilityShoot to shoot a projectile, it automatically adds the group of the entity using the ability to the projectile. In other words, you don't need to add any group to the shuriken if you use the ig.AbilityShoot to shoot shurikens, it is all handled automatically.
I managed to get it to work and yes I believe I had a typo in that 'damageable' type. The shuriken does extend ig.Projectile and I'm also using ig.AbilityShoot.
Anyway, I'll take a look later and see what I did to fix it.
If you could write some more about the group & type system in the docs, that would be great :P