From 21b9e264e446bc55edd740a9249ec4a278bcc9c6 Mon Sep 17 00:00:00 2001 From: wpernath Date: Fri, 9 Sep 2022 21:01:18 +0200 Subject: [PATCH] #24: Implementing actions on I was hurt by a remote player --- .../src/main/client/js/renderables/bomb.js | 10 ---------- .../src/main/client/js/renderables/magic-bolt.js | 2 ++ .../main/client/js/renderables/magic-firespin.js | 1 + .../main/client/js/renderables/magic-nebula.js | 3 ++- .../client/js/renderables/magic-protection.js | 3 ++- .../renderables/multiplayer/mp-local-player.js | 16 +++++++++++++--- .../src/main/client/js/stage/base-play-screen.js | 1 - .../main/client/js/stage/multiplayer/mp-play.js | 7 +------ .../src/main/client/js/util/multiplayer.js | 10 ++++++++++ .../wanja/fatcat/model/MultiplayerMessage.java | 10 +++++++++- 10 files changed, 40 insertions(+), 23 deletions(-) diff --git a/melonjs-client/src/main/client/js/renderables/bomb.js b/melonjs-client/src/main/client/js/renderables/bomb.js index 75545eba..c475d503 100644 --- a/melonjs-client/src/main/client/js/renderables/bomb.js +++ b/melonjs-client/src/main/client/js/renderables/bomb.js @@ -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) diff --git a/melonjs-client/src/main/client/js/renderables/magic-bolt.js b/melonjs-client/src/main/client/js/renderables/magic-bolt.js index a68b9a1a..f45f9cc6 100644 --- a/melonjs-client/src/main/client/js/renderables/magic-bolt.js +++ b/melonjs-client/src/main/client/js/renderables/magic-bolt.js @@ -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; diff --git a/melonjs-client/src/main/client/js/renderables/magic-firespin.js b/melonjs-client/src/main/client/js/renderables/magic-firespin.js index 1076a809..d53fbea1 100644 --- a/melonjs-client/src/main/client/js/renderables/magic-firespin.js +++ b/melonjs-client/src/main/client/js/renderables/magic-firespin.js @@ -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); diff --git a/melonjs-client/src/main/client/js/renderables/magic-nebula.js b/melonjs-client/src/main/client/js/renderables/magic-nebula.js index a380f1c9..34a68e2c 100644 --- a/melonjs-client/src/main/client/js/renderables/magic-nebula.js +++ b/melonjs-client/src/main/client/js/renderables/magic-nebula.js @@ -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; diff --git a/melonjs-client/src/main/client/js/renderables/magic-protection.js b/melonjs-client/src/main/client/js/renderables/magic-protection.js index 86d1c171..c579acd5 100644 --- a/melonjs-client/src/main/client/js/renderables/magic-protection.js +++ b/melonjs-client/src/main/client/js/renderables/magic-protection.js @@ -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; diff --git a/melonjs-client/src/main/client/js/renderables/multiplayer/mp-local-player.js b/melonjs-client/src/main/client/js/renderables/multiplayer/mp-local-player.js index 305d081d..5c2a6b5d 100644 --- a/melonjs-client/src/main/client/js/renderables/multiplayer/mp-local-player.js +++ b/melonjs-client/src/main/client/js/renderables/multiplayer/mp-local-player.js @@ -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; @@ -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; }); diff --git a/melonjs-client/src/main/client/js/stage/base-play-screen.js b/melonjs-client/src/main/client/js/stage/base-play-screen.js index 02757a5f..8baa836c 100644 --- a/melonjs-client/src/main/client/js/stage/base-play-screen.js +++ b/melonjs-client/src/main/client/js/stage/base-play-screen.js @@ -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 = []; diff --git a/melonjs-client/src/main/client/js/stage/multiplayer/mp-play.js b/melonjs-client/src/main/client/js/stage/multiplayer/mp-play.js index 6a000559..669f67e2 100644 --- a/melonjs-client/src/main/client/js/stage/multiplayer/mp-play.js +++ b/melonjs-client/src/main/client/js/stage/multiplayer/mp-play.js @@ -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) { diff --git a/melonjs-client/src/main/client/js/util/multiplayer.js b/melonjs-client/src/main/client/js/util/multiplayer.js index c0edddf8..48010602 100644 --- a/melonjs-client/src/main/client/js/util/multiplayer.js +++ b/melonjs-client/src/main/client/js/util/multiplayer.js @@ -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; @@ -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; diff --git a/quarkus-server/src/main/java/org/wanja/fatcat/model/MultiplayerMessage.java b/quarkus-server/src/main/java/org/wanja/fatcat/model/MultiplayerMessage.java index 1574bbef..2795ebe1 100644 --- a/quarkus-server/src/main/java/org/wanja/fatcat/model/MultiplayerMessage.java +++ b/quarkus-server/src/main/java/org/wanja/fatcat/model/MultiplayerMessage.java @@ -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;