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 janix2011

Hey guys. The game I have been working on is coming along nicely, but I have been thinking about using an enemy spawner entity in weltmeister to spawn my enemies instead of just placing them in weltmeister. I searched the forums for an answer, but all i could find was a thread about limiting the spawner to one entity at a time being spawned. I want to use a combination of a trigger and a enemy spawner entity that are connected with a key/value pair in weltmeister so that the player can literally "farm" enemies for items by being able to spawn a new entity after the last spawns. Here is what I have so far and I am getting no errors, but the skeleton isn't spawning at all.

trigger
ig.module(
	'game.entities.trigger'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntityTrigger = ig.Entity.extend({
	size: {x: 16, y: 16},
	
	_wmScalable: true,
	_wmDrawBox: true,
	_wmBoxColor: 'rgba(196, 255, 0, 0.7)',
	
	target: null,
	wait: -1,
	waitTimer: null,
	canFire: true,
	
	type: ig.Entity.TYPE.NONE,
	checkAgainst: ig.Entity.TYPE.A,
	collides: ig.Entity.COLLIDES.NEVER,
	
	
	init: function( x, y, settings ) {
		if( settings.checks ) {
			this.checkAgainst = ig.Entity.TYPE[settings.checks.toUpperCase()] || ig.Entity.TYPE.A;
			delete settings.check;
		}
		
		this.parent( x, y, settings );
		this.waitTimer = new ig.Timer();
	},
	
	
	check: function( other ) {
		if( this.canFire && this.waitTimer.delta() >= 0 ) {
			if( typeof(this.target) == 'object' ) {
				for( var t in this.target ) {
					var ent = ig.game.getEntityByName( this.target[t] );
					if( ent && typeof(ent.triggeredBy) == 'function' ) {
						ent.triggeredBy( other, this );
					}
				}
			}
			
			if( this.wait == -1 ) {
				this.canFire = false;
			}
			else {
				this.waitTimer.set( this.wait );
			}
		}
	},
	
	
	update: function(){}
});

});

enemy-spawner
ig.module(
    'game.entities.enemy-spawner'
)
.requires(
    'impact.entity',
    'game.entities.skeleton'
)
.defines(function () {

    EntityEnemySpawner = ig.Entity.extend({

        _wmScalable: true,
        _wmDrawBox: true,
        _wmBoxColor: 'rgba(255, 170, 66, 0.7)',

        type: ig.Entity.TYPE.NONE,
        collides: ig.Entity.COLLIDES.NEVER,

        enemy: null,

        triggeredBy: function (other) {
            if (!this.enemy || this.enemy._killed) {
                this.enemy = ig.game.spawnEntity(EntitySkeleton,x,y);
            }
        }

    });

});

1 decade ago by dominic

Did you properly connect those two entities? WM should draw a line between them.

Is the triggers check() method is called at all? Is the spawner&039;s #triggeredBy() method called? Try putting some console.log() messages in there to check.

1 decade ago by janix2011

They are properly connected in WM. I have a line connecting them. Also, when the player passes through the trigger area I get a "hitch" in the game like it was trying to load something. It almost feels like lag, but not.

I will try a console.log and check those methods. Thank you dominic.

1 decade ago by janix2011

I got it.

this.enemy = ig.game.spawnEntity(EntitySkeleton,x,y);

should be:

this.enemy = ig.game.spawnEntity(EntitySkeleton,this.pos.x,this.pos.y);


EDIT: Well I got the initial spawn working, but after the enemy dies I cannot spawn a new one by walking through the trigger again.

1 decade ago by bjennings76

Did your trigger spawner disable itself?

There is a 'wait' property on EntityTrigger that sets how long the trigger will delay after triggering before enabling itself again. By default, it is set to '-1' which causes the trigger to disable itself indefinitely. If you set it to a number > -1, it will wait that long in seconds and then re-enable itself.
Page 1 of 1
« first « previous next › last »