Skip to content

Commit

Permalink
#24: Messaging for being hurt by an enemy implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
wpernath committed Sep 8, 2022
1 parent a8caa19 commit 933dcf9
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion melonjs-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grumpycat-melonjs",
"version": "0.6.3",
"version": "0.6.4",
"main": "src/main/client/index.js",
"author": "Wanja Pernath",
"license": "GPL",
Expand Down
2 changes: 1 addition & 1 deletion melonjs-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.wanja.grumpycat</groupId>
<artifactId>umbrella</artifactId>
<version>0.6.3</version>
<version>0.6.4</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ export class MPLocalPlayerSprite extends BasePlayerSprite {
* (called when colliding with other objects)
*/
onCollision(response, other) {
if (other.body.collisionType === collision.types.COLLECTABLE_OBJECT && !other.isCollected) {
let mapX = Math.floor(this.pos.x / 32);
let mapY = Math.floor(this.pos.y / 32);
let mapX = Math.floor(this.pos.x / 32);
let mapY = Math.floor(this.pos.y / 32);

if (other.body.collisionType === collision.types.COLLECTABLE_OBJECT && !other.isCollected) {
console.log("other.type: " + other.type);
console.log("other.isCollected: " + other.isCollected);
other.isCollected = true;
if (other.type === BONUS_TILE.closedChest ) {
GlobalGameState.score += GlobalGameState.scoreForChest;
GlobalGameState.collectedChests += 1;
Expand All @@ -251,23 +252,33 @@ export class MPLocalPlayerSprite extends BasePlayerSprite {

if (GlobalGameState.invincible) return false;
if (other.body.collisionType === collision.types.ENEMY_OBJECT && !other.isStunned && !other.isDead && !GlobalGameState.isGameOver) {
let mm = MultiplayerMessage.gameUpdate();
mm.injuredByEnemy = true;
mm.x = mapX;
mm.y = mapY;

if (other.enemyType === ENEMY_TYPES.cat) {
GlobalGameState.catchedByCats++;
GlobalGameState.energy -= GlobalGameState.energyLostByCat;
mm.enemyType = ENEMY_TYPES.cat;
}
else if (other.enemyType === ENEMY_TYPES.spider) {
GlobalGameState.bittenBySpiders++;
GlobalGameState.energy -= GlobalGameState.energyLostBySpider;
mm.enemyType = ENEMY_TYPES.spider;
}
else if (other.enemyType === ENEMY_TYPES.golem) {
GlobalGameState.catchedByGolems++;
GlobalGameState.energy -= GlobalGameState.energyLostByGolem;
mm.enemyType = ENEMY_TYPES.golem;
}

GlobalGameState.invincible = true;
this.flicker(GlobalGameState.playerInvincibleTime, () => {
GlobalGameState.invincible = false;
});

MultiplayerManager.get().sendAction(mm);
}
else if (other.body.collisionType === my_collision_types.REMOTE_BOMB) {
if (other.isExploding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class MPRemotePlayerSprite extends BasePlayerSprite {

// make sure we only interpret movements for THIS sprite
if (message.playerId === this.player.id) {
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;

// only ours
if (message.gutterThrown) {
this.placeBorderTile(message.x + message.dx, message.y + message.dy, false);
Expand All @@ -31,30 +34,18 @@ export class MPRemotePlayerSprite extends BasePlayerSprite {
this.throwMagicSpell(message.x, message.y, message.dx, message.dy, false);
}
else if( message.chestCollected ) {
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;


}
else if (message.magicNebula) {
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;
this.throwMagicNebula(message.x, message.y, false);
}
else if (message.magicProtectionCircle) {
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;
this.throwMagicProtectionCircle(message.x, message.y, false);
}
else if (message.magicFirespin) {
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;
this.throwMagicFireSpin(message.x, message.y, false);
}
else if (message.bombPlaced) {
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;

let bomb = new BombEntity(this.pos.x, this.pos.y);
bomb.body.collisionType = my_collision_types.REMOTE_BOMB;
bomb.body.setCollisionMask(collision.types.PLAYER_OBJECT | collision.types.ENEMY_OBJECT);
Expand All @@ -63,10 +54,7 @@ export class MPRemotePlayerSprite extends BasePlayerSprite {
game.world.addChild(bomb);
}
else {
//console.log(" updating pos of " + this.name + " to " + this.pos );
// just movement
this.pos.x = message.x * 32 + 16;
this.pos.y = message.y * 32 + 16;
this.checkBonusTile(this.pos.x, this.pos.y, false);
}
}
Expand Down
19 changes: 17 additions & 2 deletions melonjs-client/src/main/client/js/stage/hud/hud-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import GlobalGameState from "../../util/global-game-state";
import { BONUS_TILE, PLAYER_COLORS } from "../../util/constants";
import MultiplayerManager, { MultiplayerMessageType } from "../../util/multiplayer";
import PlayerEntity from "../../renderables/player";
import { ENEMY_TYPES } from "../../renderables/base-enemy";

class ScoreItem extends Container {
/**
Expand Down Expand Up @@ -276,14 +277,13 @@ class MultiplayerMessageCenter extends Container {
constructor(x,y,w,h) {
super(x,y,w,h);

this.currentMessage = "Test message: Hallo, echo!";
this.clipping = true;
this.floating = false;

this.textBox = new BitmapText(this.pos.x + 4, 0, {
font: "24Outline",
textBaseline: "top",
text: this.currentMessage,
text: "",
});
this.addChild(this.textBox);
this.gradient = null;
Expand Down Expand Up @@ -343,6 +343,21 @@ class MultiplayerMessageCenter extends Container {
else if( message.magicProtectionCircle ) {
this.textBox.setText(player.name + " has casted a magic protection circle!");
}
else if( message.injuredByEnemy ) {
let text = "Oh nooo... " + player.name + " has been ";
switch(message.enemyType) {
case ENEMY_TYPES.cat:
text += "catched by a cat!";
break;
case ENEMY_TYPES.spider:
text += "bitten by a spider!";
break;
case ENEMY_TYPES.golem:
text += "in touch with a golem!";
break;
}
this.textBox.setText(text);
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions melonjs-client/src/main/client/js/util/multiplayer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CONFIG from "../../config";
import { ENEMY_TYPES } from "../renderables/base-enemy";
import { EventEmitter } from "./eventemitter";
import GlobalGameState from "./global-game-state";
import { LevelManager } from "./level";
Expand Down Expand Up @@ -77,6 +78,8 @@ export class MultiplayerMessage {
this.magicProtectionCircle = false;
this.magicFirespin = false;
this.chestCollected = false;
this.injuredByEnemy = false;
this.enemyType = null;
this.score = 0;
this.energy = 0;

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.wanja.grumpycat</groupId>
<artifactId>umbrella</artifactId>
<version>0.6.3</version>
<version>0.6.4</version>
<packaging>pom</packaging>

<modules>
Expand All @@ -20,7 +20,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.11.2.Final</quarkus.platform.version>
<quarkus.platform.version>2.12.1.Final</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion quarkus-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.wanja.grumpycat</groupId>
<artifactId>umbrella</artifactId>
<version>0.6.3</version>
<version>0.6.4</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum MessageType {
public boolean magicProtectionCircle = false;

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

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

0 comments on commit 933dcf9

Please sign in to comment.