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 jizaymes

Hello,

I'm working on a zone entity that I specify the type for in Weltmeister, and refer to that to determine what action it takes. For example, if you walk over rocks, your health will decrease and your speed will slow down.

My implementation for this calls for an outer zone (reset) which sets the speed back to normal, and inner zones (damage). The notion was that as they walk away from the rocks, it'll reset the speed back to normal.

The problems I'm encountering is that the zone entities check function is triggering for the wrong type. The area that should be setting the speed does nothing, and a console.log reports it as being a damage zone which is just not right.

An image is available here which may paint a better picture.

https://skitch.com/amcops/epcx1/world-map

ig.module(
    'game.entities.zone'
).requires(
    'impact.entity'
)
.defines(function() {
    EntityZone = ig.Entity.extend({
        _wmDrawBox: true,
        _wmScalable: true,

        size: {x: 16, y: 16},
        
        checkAgainst: ig.Entity.TYPE.BOTH,
        
        init: function(x, y, settings){
            this.parent(x, y, settings);
            
            switch(this.type) {
            
            	case "damage":
			        this._wmBoxColor = 'rgba(0, 0, 255, 0.7)';
		
					this.tim = new ig.Timer( 0.5 );
					this.tim.pause();

            		break;
            	default:
			        this._wmBoxColor ='rgba(255, 0, 255, 0.7)';
			      	break;
            }

        },
	
		tim: null,
		               
        check: function(other) {

            if( other instanceof EntityPlayer ) {
           	console.log('Colliding with '  + other.name + ' / Zone Type: ' + this.type);
				
	        	switch(this.type) {
    	    		
        			case "damage":
						this.tim.unpause();
					
			        	if( this.tim.delta() > 0.5 ) {
			               other.receiveDamage(this.damageAmount);                
			
		  					other.speed = other.defaultSpeed * 0.30;
		  					console.log("Slowing down player " + other.speed);
		 					this.tim.reset();
						}
						break;
        

					default:
						if (other.speed != other.defaultSpeed) { 
							other.speed = other.defaultSpeed;
							console.log('Settings speed to: ' + other.speed);
						}
						break;

        		}

            this.parent();


			}			

        }
    });
});

Any help appreciated. Thanks

1 decade ago by jizaymes

I think it may be because both are triggering at the same time and thus negating the effect. Any ideas how to only trigger for the player (other) entity is directly on top of?

1 decade ago by StuartTresadern

You will need to look at the zindex of all the entities to find whicih is nearest your player entity. I did something like this before and to be honest it got a bit messy. To solve the same problem I created the value tile plugin which may be worth a look if your zones are aligned to tiles !.

http://impactjs.com/forums/code/tile-value-plugin
Page 1 of 1
« first « previous next › last »