Esempio n. 1
0
function tick() {
    if (!paused) {
        for (var key in players) {
            if (playing(players[key])) {
                scores[key].add_score();
            }
        }
    }
}
Esempio n. 2
0
    add_score(amount=1) {
        this.score += amount;

        if (playing(players[this.__player_name__])) {
            var event = new CustomEvent('score', {
                'detail': {
                    player: players[this.__player_name__],
                    score: this.score
                }
            });

            document.dispatchEvent(event);
        }

        console.log(`SCORE: ${this.__player_name__} player gains ${amount} points, now at ${this.score}`);
    }
Esempio n. 3
0
function move_paddle(player) {
    // move the player with gamepad if player is active.  else let AI decide
    // how to move.

    let pl = players[player];
    let pad = paddles[player];

    if (playing(pl)) {
        // handle gamepad controls
        if (input[pl.neg](pl.pad)) {
            move[pl.neg].execute(pl, pad);
        }
        if (input[pl.pos](pl.pad)) {
            move[pl.pos].execute(pl, pad);
        }

        // handle keyboard controls
        if (input.left_kb() || input.up_kb()) {
            move[pl.neg].execute(pl, pad);
        }

        if (input.right_kb() || input.down_kb()) {
            move[pl.pos].execute(pl, pad);
        }
    }
    else {

        // AI IS HERE!
        // find the distance between the puck and the paddle, but only on the
        // axis of movement
        let on_axis        = pl.axis;
        let on_axis_d      = puck.body.center[on_axis]  - pad.body.center[on_axis];
        let motive_surface = Math.max(pad.body.height, pad.body.width) / (1/conf.AI_LAZINESS);
        let move_speed     = Math.min(conf.AI_UNFAIR_PADDLE_VELOCITY, Math.abs(on_axis_d / motive_surface));

        move[on_axis_d > 0 ? pl.pos : pl.neg].execute(pl, pad, move_speed);
    }
}
Esempio n. 4
0
function execute_powerup_if_a(player) {
    if (playing(players[player]) && input.a(players[player].pad)) {
        players[player].execute_powerup();
    }
}
Esempio n. 5
0
function rotate_powerup_if_b(player) {
    if (playing(players[player]) && input.b(players[player].pad)) {
        players[player].rotate_powerups();
    }
}