1 decade ago by fulvio
Could anyone give me a hand creating a Button Entity that's triggered by a Crate Entity when it falls on the button?
What I would like to do in Weltmeister is connect the Button Entity via
These are what I have so far for. Unfortunately it's not quite working as expected.
This is my Crate Entity:
What I would like to do in Weltmeister is connect the Button Entity via
target.x
to another Entity that kills the target Entity when the Crate collides with it.These are what I have so far for. Unfortunately it's not quite working as expected.
EntityButton = ig.Entity.extend({ size: { x: 16, y: 8 }, offset: { x: 0, y: 8 }, type: ig.Entity.TYPE.A, checkAgainst: ig.Entity.TYPE.A, collides: ig.Entity.COLLIDES.ACTIVE, target: null, animSheet: new ig.AnimationSheet('media/sprites/button-switch.png', 16, 16), init: function (x, y, settings) { this.addAnim('idle', 0.2, [0]); this.addAnim('activated', 0.2, [1]); if (settings.checks) { this.checkAgainst = ig.Entity.TYPE[settings.checks.toUpperCase()] || ig.Entity.TYPE.A; delete settings.check; } this.parent(x, y, settings); }, check: function (other) { // "Activated" animation frame. this.currentAnim = this.anims.activated; 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') { if (ent instanceof EntityCrate) { ent.triggeredBy(other, this); } } } } });
This is my Crate Entity:
EntityCrate = ig.Entity.extend({ size: { x: 14, y: 14 }, offset: { x: 1, y: 1 }, maxVel: { x: 60, y: 150 }, friction: { x: 100, y: 0 }, health: 5, bounciness: 0.4, damage: 20, type: ig.Entity.TYPE.B, checkAgainst: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.ACTIVE, sfxCrack: new ig.Sound('media/sounds/crack.ogg'), animSheet: new ig.AnimationSheet('media/sprites/crate.png', 16, 16), init: function (x, y, settings) { this.addAnim('idle', 1, [0]); this.parent(x, y, settings); }, kill: function () { this.sfxCrack.play(); var gibs = ig.ua.mobile ? 10 : 20; for (var i = 0; i < gibs; i++) { ig.game.spawnEntity(EntityCrateDebris, this.pos.x, this.pos.y); } this.parent(); }, triggeredBy: function (other, trigger) { if (typeof (trigger.target) == 'object') { for (var t in trigger.target) { var ent = ig.game.getEntityByName(trigger.target[t]); ent.kill(); } } } });