Skip to content

Commit

Permalink
#24: Implementing actions on I was hurt by a remote player
Browse files Browse the repository at this point in the history
  • Loading branch information
wpernath committed Sep 9, 2022
1 parent 933dcf9 commit 21b9e26
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
10 changes: 0 additions & 10 deletions melonjs-client/src/main/client/js/renderables/bomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ class BombEntity extends Sprite {
});
}

/**
* update the entity
*/
update(dt) {
// call the parent method

super.update(dt);
return true;
}

/**
* colision handler
* (called when colliding with other objects)
Expand Down
2 changes: 2 additions & 0 deletions melonjs-client/src/main/client/js/renderables/magic-bolt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class MagicBolt extends Sprite {
anchorPoint: new Vector2d(0.5,0.5),
});

this.thrownByPlayer = null;

this.owner = owner;
this.dx = dx;
this.dy = dy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class MagicFirespin extends Sprite {
anchorPoint: new Vector2d(0.5, 0.5),
});

this.thrownByPlayer = null;
this.owner = owner;

this.body = new Body(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default class MagicNebula extends Sprite {
this.mapX = x;
this.mapY = y;
this.owner = owner;

this.thrownByPlayer = null;

this.body = new Body(this);
this.body.addShape(new Rect(28, 32, 34, 30));
this.body.ignoreGravity = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default class MagicProtectionCircle extends Sprite {
});

this.owner = owner;

this.thrownByPlayer = null;

this.body = new Body(this);
this.body.addShape(new Rect(28, 32, 34, 30));
this.body.ignoreGravity = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,15 @@ export class MPLocalPlayerSprite extends BasePlayerSprite {
console.log("other.isCollected: " + other.isCollected);
other.isCollected = true;
if (other.type === BONUS_TILE.closedChest ) {
GlobalGameState.score += GlobalGameState.scoreForChest;
GlobalGameState.score += other.score;
GlobalGameState.bombs += other.numBombs;
GlobalGameState.magicBolts += other.numMagicBolts;
GlobalGameState.magicFirespins += other.numMagicFirespins;
GlobalGameState.magicNebulas += other.numMagicNebulas;
GlobalGameState.magicProtections += other.numMagicProtectionCircles;
GlobalGameState.collectedChests += 1;

let mm = MultiplayerMessage.gameUpdate();
mm.message = this.player.name + " has opened a CHEST!";
let mm = MultiplayerMessage.gameUpdate();
mm.chestCollected = true;
mm.x = mapX;
mm.y = mapY;
Expand Down Expand Up @@ -286,6 +290,12 @@ export class MPLocalPlayerSprite extends BasePlayerSprite {
GlobalGameState.energy -= GlobalGameState.energyLostByRemoteBomb;
GlobalGameState.hitByRemotePlayerBomb++;
GlobalGameState.invincible = true;

let mm = MultiplayerMessage.gameUpdate();
mm.hurtByBomb = true;
mm.x = mapX;
mm.y = mapY;

this.flicker(GlobalGameState.playerInvincibleTime, () => {
GlobalGameState.invincible = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { BONUS_TILE } from "../util/constants.js";
import ChestBonusSprite from "../renderables/terrain/chest-sprite.js";
import { LevelObject } from "../util/level.js";
import { EventEmitter } from "../util/eventemitter.js";

export class BasePlayScreen extends Stage {
player;
enemies = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ export default class MultiplayerPlayScreen extends BasePlayScreen {
* @returns
*/
playersFromGame(theGame) {
let players = [];
players[0] = theGame.player1 !== undefined ? theGame.player1 : null;
players[1] = theGame.player2 !== undefined ? theGame.player2 : null;
players[2] = theGame.player3 !== undefined ? theGame.player3 : null;
players[3] = theGame.player4 !== undefined ? theGame.player4 : null;
return players;
return MultiplayerManager.get().getPlayersFromGame();
}

update(dt) {
Expand Down
10 changes: 10 additions & 0 deletions melonjs-client/src/main/client/js/util/multiplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export class MultiplayerMessage {
this.y = 0;
this.dx = 0;
this.dy = 0;

// actions I did
this.bombPlaced = false;
this.gutterThrown = false;
this.magicBolt = false;
Expand All @@ -80,6 +82,14 @@ export class MultiplayerMessage {
this.chestCollected = false;
this.injuredByEnemy = false;
this.enemyType = null;

// Being hurt by a remote player
this.hurtByBomb = false;
this.hurtByNebula = false;
this.hurtByBolt = false;
this.hurtByFirespin = false;
this.remotePlayerIdWhoHurtMe = null;

this.score = 0;
this.energy = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ public enum MessageType {
public int x;
public int y;

// Actions I did
public boolean bombPlaced = false;
public boolean gutterThrown = false;
public boolean magicBolt = false;
public boolean magicFirespin = false;
public boolean magicNebula = false;
public boolean magicProtectionCircle = false;

public boolean chestCollected = false;
public boolean injuredByEnemy = false;
public String enemyType;

// I was hurt by a remote player
public boolean hurtByBomb=false;
public boolean hurtByNebula=false;
public boolean hurtByBolt=false;
public boolean hurtByFirespin=false;
public Long remotePlayerIdWhoHurtMe=null;


public long score = 0L;
public int energy;
Expand Down

0 comments on commit 21b9e26

Please sign in to comment.