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

9 years ago by Cadence96

Hi, my EntityPlayer can kill enemies by jumping then it bounces. But it can receive damage if it touches an enemy by axis x. After receiving damage the player becomes invincible for a few seconds.

Until that everything works. The problem is that I want the player walk through enemies (axis x) while is invincible. But it is not possible since my player uses collideWith to detect axis and it doesn't work with collides.PASSIVE.

I've tried changing collides from ACTIVE to PASSIVE if collideWith axis is x. But collides executes ACTIVE first before setting to PASSIVE.

1) Is it a way to make collideWith method work if player collides is PASSIVE ? If collides is PASSIVE, I can not make the player bounce when jumping over enemy.
or
2) Is a way I can change to PASSIVE before executing collideWith?


EntityPlayer = ig.Entity.extend({
    collides: ig.Entity.COLLIDES.ACTIVE,

    init: function() {
      this.invincibleTimer = new ig.Timer();
    },
    collideWith: function(other, axis) {
      if (other instanceof EntityEnemy ) {
        if ( axis == 'y' ) {
          this.vel.y -= 500; // bounce
        }
        if ( axis == 'x') {  
          this.collides = ig.Entity.COLLIDES.PASSIVE;
          this.receiveDamage(other.ap, other);
        }
      }
    },
    receiveDamage: function(amount, from) {
        this.currentAnim.alpha = 0.5;      
        if ( this.invincibleTimer.delta() > 0) {
          this.invincibleTimer.set(2);
          this.health-=amount;
        }
    },
});


EntityEnemy = ig.Entity.extend({
  ap: 1,
  collides: ig.Entity.COLLIDES.PASSIVE,
  collideWith: function ( other, axis ) {    
    if( other instanceof EntityPlayer ) {
        if( axis == 'y' ) {
            this.kill();
        }
    }
  }
});

9 years ago by TC

In your EntityPlayer update method add this at the top before calling this.parent();

this.collides = (this.invincibleTimer.delta() <= 0) ?  ig.Entity.COLLIDES.PASSIVE : ig.Entity.COLLIDES.ACTIVE;
Page 1 of 1
« first « previous next › last »