Browse Source

add bomb bonus

master
zapashcanon 6 years ago
parent
commit
6383eb9ac9
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 4
      src/js/bomb.js
  2. 19
      src/js/mover.js
  3. 19
      src/js/state.js

4
src/js/bomb.js

@ -8,9 +8,11 @@ import * as consts from "./consts.js";
export class Bomb extends temporary.Temporary {
/*:: power: number */
constructor (p /*: point.Point */, super_bomb /*: boolean */) {
/*:: owner: number */
constructor (p /*: point.Point */, super_bomb /*: boolean */, owner /*: number */) {
super(p, consts.bomb_ttl);
// the size of the explosion
this.power = super_bomb ? consts.super_bomb_power : consts.bomb_power;
this.owner = owner;
};
}

19
src/js/mover.js

@ -15,19 +15,21 @@ export class Mover extends point.Point {
/*:: moving: boolean */
/*:: state: state.State */
/*:: bonuses: Array<bonus.Bonus> */
constructor (x /*: number */, y /*: number */, s /*: state.State */) {
/*:: id: number */
constructor (x /*: number */, y /*: number */, s /*: state.State */, id /*: number */) {
super(x, y);
this.state = s;
this.alive = true;
this.moving = false; // this prevent the rendering from being shitty
this.dir = consts.dir.Bottom; // the direction in which the character looks
this.bonuses = [];
this.id = id;
};
kill () {
this.alive = false;
};
copy () {
let c = new Mover(this.x, this.y, this.state);
let c = new Mover(this.x, this.y, this.state, this.id);
c.alive = this.alive;
c.dir = this.dir;
c.moving = this.moving;
@ -57,11 +59,14 @@ export class Mover extends point.Point {
};
add_bomb() {
if (this.alive) {
const p = this.round();
if (this.has_fire_power()) {
this.state.add_super_bomb(p);
} else {
this.state.add_bomb(p);
// we can add a bomb only if we have the bonus for multi-bombs or if we have 0 bomb
if (this.has_bomb_power() || !this.state.mover_has_bomb(this.id)) {
const p = this.round();
if (this.has_fire_power()) {
this.state.add_super_bomb(p, this.id);
} else {
this.state.add_bomb(p, this.id);
}
}
}
};

19
src/js/state.js

@ -36,13 +36,13 @@ export class State extends map.TMap {
};
this.win = false;
this.p1 = new mover.Mover(map.p1_pos.x, map.p1_pos.y, this);
this.p1 = new mover.Mover(map.p1_pos.x, map.p1_pos.y, this, 1);
if (two_player) {
if (!map.p2_pos) {
throw "missing p2 pos in map !";
}
this.p2 = new mover.Mover(map.p2_pos.x, map.p2_pos.y, this);
this.p2 = new mover.Mover(map.p2_pos.x, map.p2_pos.y, this, 2);
this.exit = null;
} else {
if (!map.exit) {
@ -78,18 +78,21 @@ export class State extends map.TMap {
};
block_has_bomb(p /*: point.Point */) {
return this.bombs.some(function (b) { return b.is_on_block(p) });
}
};
block_has_bonus(p /*: point.Point */) {
return this.bonuses.some(function (b) { return b.is_on_block(p) });
}
add_bomb(p /*: point.Point */) {
};
mover_has_bomb(id /*: number */) {
return this.bombs.some(function (b) { return b.owner == id });
};
add_bomb(p /*: point.Point */, owner /*: number */) {
if (!this.block_has_bomb(p)) {
this.bombs.push(new bomb.Bomb(p, false));
this.bombs.push(new bomb.Bomb(p, false, owner));
}
};
add_super_bomb(p /*: point.Point */) {
add_super_bomb(p /*: point.Point */, owner /*: number */) {
if (!this.block_has_bomb(p)) {
this.bombs.push(new bomb.Bomb(p, true));
this.bombs.push(new bomb.Bomb(p, true, owner));
}
}
add_fire(p /*: point.Point */) {

Loading…
Cancel
Save