Refactored and optimized messages
Now, when a user moves, only his/her position is sent back to the other users. The position of all users is not sent each time. The messages sent to the browser are now: - the list of all users as a return to the join_room event (you can send responses to events in socket.io) - a "join_room" event sent when a new user joins the room - a "user_moved" event when a user moved - a "user_left" event when a user left the room The GameScene tracks all these events and reacts accordingly. Also, I made a number of refactoring in the classes and removed the GameSceneInterface that was useless (it was implemented by the LogincScene for no reason at all)
This commit is contained in:
parent
1e6f9bb8d9
commit
125a4d11af
12 changed files with 238 additions and 101 deletions
|
@ -1,5 +1,5 @@
|
|||
import Map = Phaser.Structs.Map;
|
||||
import {GameSceneInterface} from "../Game/GameScene";
|
||||
import {GameScene} from "../Game/GameScene";
|
||||
|
||||
interface UserInputManagerDatum {
|
||||
keyCode: number;
|
||||
|
@ -29,7 +29,7 @@ export class ActiveEventList {
|
|||
set(event: UserInputEvent, value: boolean): boolean {
|
||||
return this.KeysCode[event] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//this class is responsible for catching user inputs and listing all active user actions at every game tick events.
|
||||
export class UserInputManager {
|
||||
|
@ -38,19 +38,19 @@ export class UserInputManager {
|
|||
{keyCode: Phaser.Input.Keyboard.KeyCodes.Q, event: UserInputEvent.MoveLeft, keyInstance: null},
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.S, event: UserInputEvent.MoveDown, keyInstance: null},
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.D, event: UserInputEvent.MoveRight, keyInstance: null},
|
||||
|
||||
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.UP, event: UserInputEvent.MoveUp, keyInstance: null},
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.LEFT, event: UserInputEvent.MoveLeft, keyInstance: null},
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.DOWN, event: UserInputEvent.MoveDown, keyInstance: null},
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.RIGHT, event: UserInputEvent.MoveRight, keyInstance: null},
|
||||
|
||||
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.SHIFT, event: UserInputEvent.SpeedUp, keyInstance: null},
|
||||
|
||||
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.E, event: UserInputEvent.Interact, keyInstance: null},
|
||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.F, event: UserInputEvent.Shout, keyInstance: null},
|
||||
];
|
||||
|
||||
constructor(Scene : GameSceneInterface) {
|
||||
|
||||
constructor(Scene : GameScene) {
|
||||
this.KeysCode.forEach(d => {
|
||||
d.keyInstance = Scene.input.keyboard.addKey(d.keyCode);
|
||||
});
|
||||
|
@ -65,4 +65,4 @@ export class UserInputManager {
|
|||
});
|
||||
return eventsMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue