Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by UziMonkey

I wanted something a bit more expressive than ig.Entity.TYPE.A and ig.Entity.TYPE.B, so I made this plugin. Now you can do things like ig.Entity.TYPE.get('enemy') instead. Entities can have multiple types and can collide with multiple types.

It doesn't change anything about type A and B types, you can keep using them as you wish and mix in the new entity types. It also doesn't change anything about how ImpactJS works. All the functionality was there, it just didn't have an interface to define new names easily.

You can read more about it on my blog, and code is below.

ig.module(
	'plugins.entitytype'
).requires(
	'impact.entity'
).defines(function() {
 
ig.Entity.TYPE._next = 4;
 
ig.Entity.TYPE.get = function(name) {
	if( name.indexOf(" ") != -1 ) {
		type = 0;
		types = name.split(' ');
		for( i = 0; i < types.length; i++ ) {
			type |= ig.Entity.TYPE.get(types[i]);
		}
 
		return type;
	}
 
	if(!ig.Entity.TYPE.hasOwnProperty(name) ) {
		ig.Entity.TYPE[name] = ig.Entity.TYPE._next;
		ig.Entity.TYPE._next <<= 1;
	}
 
	return ig.Entity.TYPE[name];
}
 
})

1 decade ago by gxxaxx

Very encouraging.
I've been hunting for a mechanism to do something like this. Your solution is much cleaner than the one I am using at the moment.

I started this as a means to create barriers that would stop monsters but allow the player to pass. In the older 1.18 engine I hacked the collision-map to allow tiles that would effect A, B or Both. But, the new engine does not look so easy to hack. Just under-scoring the old motto "don't hack the core if you want to get any sleep after an upgrade."

So, maybe I can use your code to duplicate that function.

1 decade ago by UziMonkey

Yes, you can. Just make some invisible entities that have the right collision properties and collide with the right types of enemies.

1 decade ago by Arantor

Should be easier in 1.19 with the new collision-directional tiles, too.

1 decade ago by drailing

hey uziMonkey,

thanks a lot for sharing your plugin, it works great!

@dominic
perhaps a nice extension for a next impact update?
or is there any reason for the limitation of two types?


edit:
is it correct that i have to require the plugin in every entity i want to use it?
Page 1 of 1
« first « previous next › last »