update() {
     if (this.checkCollision() || this.gameRef.physics.arcade.collide(this.sprite, globals.player,
             (sprite, enemy) => this.onCollideEnemy(enemy.wrapper))) {
         this.destroy();
     }
     if (this.initalPos.distance(this.sprite.position) >= 600) {
         this.destroy();
     }
 }
Ejemplo n.º 2
0
    update() {
        // this.state.game.physics.arcade.collide(this, this.state.layers.collision);

        if (this.path.length > 0) {
            let nextPosition = this.path[this.pathStep];

            if (!this.hasReachedTargetPosition(nextPosition)) {
                let velocity = new Phaser.Point(nextPosition.x - this.position.x, nextPosition.y - this.position.y);
                velocity.normalize();
                this.body.velocity.x = velocity.x * this.walkingSpeed;
                this.body.velocity.y = velocity.y * this.walkingSpeed;
            } else {
                this.position.x = nextPosition.x;
                this.position.y = nextPosition.y;

                if (this.pathStep < this.path.length - 1) {
                    this.pathStep += 1;
                    nextPosition = this.path[this.pathStep];

                    // Update animation
                    if (nextPosition.x - this.position.x > 0) {
                        this.animations.play("walk-right");
                    } else if (nextPosition.x - this.position.x < 0) {
                        this.animations.play("walk-left");
                    } else if (nextPosition.y - this.position.y > 0) {
                        this.animations.play("walk-down");
                    } else if (nextPosition.y - this.position.y < 0) {
                        this.animations.play("walk-up");
                    }
                } else {
                    // Last position
                    this.path = [];
                    this.pathStep = -1;
                    this.body.velocity.x = 0;
                    this.body.velocity.y = 0;
                    this.animations.stop(true);
                }
            }
            this.onMove.dispatch(this.position.x, this.position.y);
        }
    }
Ejemplo n.º 3
0
function checkIntersects(fruit, callback) {
    var l1 = new Phaser.Line(fruit.body.right - fruit.width, fruit.body.bottom - fruit.height, fruit.body.right, fruit.body.bottom);
    var l2 = new Phaser.Line(fruit.body.right - fruit.width, fruit.body.bottom, fruit.body.right, fruit.body.bottom-fruit.height);
    l2.angle = 90;

    if(Phaser.Line.intersects(line, l1, true) ||
        Phaser.Line.intersects(line, l2, true)) {

        contactPoint.x = game.input.x;
        contactPoint.y = game.input.y;
        var distance = Phaser.Point.distance(contactPoint, new Phaser.Point(fruit.x, fruit.y));
        if (Phaser.Point.distance(contactPoint, new Phaser.Point(fruit.x, fruit.y)) > 110) {
            return;
        }

        if (fruit.parent == good_objects) {
            killFruit(fruit);
        } else {
            resetScore();
        }
    }

}
Ejemplo n.º 4
0
 hasReachedTargetPosition(targetPosition) {
     return Phaser.Point.distance(this.position, targetPosition) < 1;
 }
Ejemplo n.º 5
0
 execute(puck) {
     // reverse the velocity of the puck
     Phaser.Point.negative(this.player.puck.body.velocity, this.player.puck.body.velocity);
 }