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
enemy-spawner
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); } } }); });