summaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/src')
-rw-r--r--client/src/GridPhysics.ts18
-rw-r--r--client/src/client.ts4
-rw-r--r--client/src/events.ts25
-rw-r--r--client/src/sprite.ts4
4 files changed, 46 insertions, 5 deletions
diff --git a/client/src/GridPhysics.ts b/client/src/GridPhysics.ts
index d363a60..b1fe459 100644
--- a/client/src/GridPhysics.ts
+++ b/client/src/GridPhysics.ts
@@ -6,7 +6,9 @@ import {
akkamonClient
} from './app';
import {
- StartMovingEvent
+ StartMovingEvent,
+ StopMovingEvent,
+ NewTilePosEvent
} from './events';
export class GridPhysics {
@@ -51,7 +53,7 @@ export class GridPhysics {
private startMoving(direction: Direction): void {
console.log("Sending startMovingEvent");
akkamonClient.send(
- new StartMovingEvent(direction)
+ new StartMovingEvent(this.playerSprite.getScene(), direction)
);
this.playerSprite.startAnimation(direction);
this.movementDirection = direction;
@@ -80,6 +82,12 @@ export class GridPhysics {
}
private updatePlayerSpriteTilePosition() {
+ akkamonClient.send(
+ new NewTilePosEvent(
+ this.playerSprite.getScene(),
+ this.playerSprite.getTilePos()
+ )
+ );
this.playerSprite.setTilePos(
this.playerSprite
.getTilePos()
@@ -127,6 +135,12 @@ export class GridPhysics {
}
private stopMoving(): void {
+ akkamonClient.send(
+ new StopMovingEvent(
+ this.playerSprite.getScene(),
+ this.movementDirection
+ )
+ );
this.playerSprite.stopAnimation(this.movementDirection);
this.movementDirection = Direction.NONE;
}
diff --git a/client/src/client.ts b/client/src/client.ts
index c83c39a..77d6676 100644
--- a/client/src/client.ts
+++ b/client/src/client.ts
@@ -26,8 +26,8 @@ export class Client
in(eventString: string) {
let event: AkkamonEvent = JSON.parse(eventString);
- // console.log("-> client is handling incoming event:");
- // console.log(event);
+ console.log("-> client is handling incoming event:");
+ console.log(event);
switch (event.type) {
case EventType.HEART_BEAT:
this.send(new HeartBeatReplyEvent());
diff --git a/client/src/events.ts b/client/src/events.ts
index 5a64d5b..cc001f7 100644
--- a/client/src/events.ts
+++ b/client/src/events.ts
@@ -6,7 +6,9 @@ import type { Direction } from './Direction';
export enum EventType {
HEART_BEAT = "HeartBeat",
PLAYER_REGISTRATION = "PlayerRegistrationEvent",
- START_MOVING = "StartMoving"
+ START_MOVING = "StartMoving",
+ STOP_MOVING = "StopMoving",
+ NEW_TILE_POS = "NewTilePos"
}
export interface AkkamonEvent {
@@ -26,10 +28,31 @@ export class StartMovingEvent implements AkkamonEvent {
public type: EventType = EventType.START_MOVING;
constructor(
+ public sceneId: string,
public direction: Direction,
) { }
}
+export class StopMovingEvent implements AkkamonEvent {
+
+ public type: EventType = EventType.STOP_MOVING;
+
+ constructor(
+ public sceneId: string,
+ public direction: Direction,
+ ) { }
+}
+
+export class NewTilePosEvent implements AkkamonEvent {
+
+ public type: EventType = EventType.NEW_TILE_POS;
+
+ constructor(
+ public sceneId: string,
+ public tilePos: {x: number, y: number}
+ ) { }
+}
+
export class HeartBeatReplyEvent implements AkkamonEvent {
public type: EventType = EventType.HEART_BEAT;
diff --git a/client/src/sprite.ts b/client/src/sprite.ts
index 77ca2a0..960d374 100644
--- a/client/src/sprite.ts
+++ b/client/src/sprite.ts
@@ -63,4 +63,8 @@ export class PlayerSprite extends Phaser.GameObjects.Sprite implements AkkamonPl
setTilePos(tilePosition: Phaser.Math.Vector2): void {
this.tilePos = tilePosition.clone();
}
+
+ getScene(): string {
+ return this.scene.scene.key;
+ }
}