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 sdwrage

I remember messing around with the unreal engine a while back and remembering that you could set damage zones for areas that you had set for lava or spikes or... whatever needed to cause damage. So I thought it would be cool if you could do it within impact. I created a damage zone entity (look below) with a 16x16 size that can be used in the WM (Weltmeister) editor.

The entity knocks the player back unless you set the entities ignoreknockback value to false. Also, it defaults to a damage value of 9999 unless you set its damage value for the entity. Common usage could be placing it in front of a lava entity that has animation or even next to a spike pit.

If anyone has any improvements, let me know :)

ig.module(
	'game.entities.damagezone'
).requires(
	'impact.entity'
)
.defines(function() {
	EntityDamagezone = ig.Entity.extend({
		_wmDrawBox: true,
		_wmBoxColor: 'rgba(0, 0, 255, 0.7)',
		size: {x: 16, y: 16},
		damage: 9999,
		ignoreknockback: "true",
		
		checkAgainst: ig.Entity.TYPE.BOTH,
		collides: ig.Entity.COLLIDES.ACTIVE,
		
		init: function(x, y, settings){
			this.parent(x, y, settings);
			if (settings.damage) {
				this.damage = settings.damage;
				this.ignoreknockback = this.stringToBoolean(settings.ignoreknockback);
			}
		},
		
		update: function() {},
		
		check: function(other) {
			if( other instanceof EntityPlayer ) {
				other.receiveDamage(this.damage);
				
				if (!this.ignoreknockback) {
					this.knockBack(other);
				}
			}
		},
		
		knockBack: function(other) {
			if (other.pos.x < this.pos.x) {
				other.vel.x = -other.maxVel.x;
			} else if(other.pos.x > this.pos.x) {
				other.vel.x = other.maxVel.x;
			}
			
			if (other.pos.y < this.pos.y) {
				other.vel.y = -other.maxVel.y;
			} else if(other.pos.y > this.pos.y) {
				other.vel.y = other.maxVel.y;
			}
		},
		
		stringToBoolean: function(string){
			if(string != null) {
				switch(string.toLowerCase()){
			    	case "true": case "yes": case "1": return true;
			        case "false": case "no": case "0": return false;
			       	default: return Boolean(string);
			    }
			}
		}
	});
});

1 decade ago by stahlmanDesign

Good idea.
Page 1 of 1
« first « previous next › last »