More strict fixes
This commit is contained in:
parent
082a11b0cd
commit
6f69a62d4d
@ -24,8 +24,8 @@ export const PLAYER_RESOURCES: Array<any> = [
|
|||||||
{name: "Female8", img: "resources/characters/pipoya/Female 16-4.png"/*, x: 128, y: 128*/}
|
{name: "Female8", img: "resources/characters/pipoya/Female 16-4.png"/*, x: 128, y: 128*/}
|
||||||
];
|
];
|
||||||
|
|
||||||
export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
export class PlayableCharacter extends Phaser.Physics.Arcade.Sprite {
|
||||||
private bubble: SpeechBubble;
|
private bubble: SpeechBubble|null = null;
|
||||||
private readonly playerName: BitmapText;
|
private readonly playerName: BitmapText;
|
||||||
public PlayerValue: string;
|
public PlayerValue: string;
|
||||||
public PlayerTexture: string;
|
public PlayerTexture: string;
|
||||||
@ -91,8 +91,10 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
|
|||||||
this.bubble = new SpeechBubble(this.scene, this, text)
|
this.bubble = new SpeechBubble(this.scene, this, text)
|
||||||
//todo make the bubble destroy on player movement?
|
//todo make the bubble destroy on player movement?
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.bubble.destroy();
|
if (this.bubble !== null) {
|
||||||
this.bubble = null;
|
this.bubble.destroy();
|
||||||
|
this.bubble = null;
|
||||||
|
}
|
||||||
}, 3000)
|
}, 3000)
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
import Scene = Phaser.Scene;
|
import Scene = Phaser.Scene;
|
||||||
import {PlayableCaracter} from "./PlayableCaracter";
|
import {PlayableCharacter} from "./PlayableCharacter";
|
||||||
|
|
||||||
export class SpeechBubble {
|
export class SpeechBubble {
|
||||||
private bubble: Phaser.GameObjects.Graphics;
|
private bubble: Phaser.GameObjects.Graphics;
|
||||||
@ -11,7 +11,7 @@ export class SpeechBubble {
|
|||||||
* @param player
|
* @param player
|
||||||
* @param text
|
* @param text
|
||||||
*/
|
*/
|
||||||
constructor(scene: Scene, player: PlayableCaracter, text: string = "") {
|
constructor(scene: Scene, player: PlayableCharacter, text: string = "") {
|
||||||
|
|
||||||
let bubbleHeight = 50;
|
let bubbleHeight = 50;
|
||||||
let bubblePadding = 10;
|
let bubblePadding = 10;
|
||||||
@ -76,13 +76,10 @@ export class SpeechBubble {
|
|||||||
this.content.setPosition(this.bubble.x + (bubbleWidth / 2) - (bounds.width / 2), this.bubble.y + (bubbleHeight / 2) - (bounds.height / 2));
|
this.content.setPosition(this.bubble.x + (bubbleWidth / 2) - (bounds.width / 2), this.bubble.y + (bubbleHeight / 2) - (bounds.height / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
this.bubble.setVisible(false) //todo find a better way
|
this.bubble.setVisible(false) //todo find a better way
|
||||||
this.bubble.destroy();
|
this.bubble.destroy();
|
||||||
this.bubble = null;
|
|
||||||
this.content.destroy();
|
this.content.destroy();
|
||||||
this.content = null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -155,9 +155,8 @@ export class GameManager {
|
|||||||
let sceneKey = GameScene.getMapKeyByUrl(mapUrl);
|
let sceneKey = GameScene.getMapKeyByUrl(mapUrl);
|
||||||
|
|
||||||
let gameIndex = scene.getIndex(sceneKey);
|
let gameIndex = scene.getIndex(sceneKey);
|
||||||
let game : Phaser.Scene = null;
|
|
||||||
if(gameIndex === -1){
|
if(gameIndex === -1){
|
||||||
game = GameScene.createFromUrl(mapUrl, instance);
|
let game : Phaser.Scene = GameScene.createFromUrl(mapUrl, instance);
|
||||||
scene.add(sceneKey, game, false);
|
scene.add(sceneKey, game, false);
|
||||||
}
|
}
|
||||||
return sceneKey;
|
return sceneKey;
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
|
import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
|
||||||
import { DEBUG_MODE, ZOOM_LEVEL, POSITION_DELAY } from "../../Enum/EnvironmentVariable";
|
import { DEBUG_MODE, ZOOM_LEVEL, POSITION_DELAY } from "../../Enum/EnvironmentVariable";
|
||||||
import {ITiledMap, ITiledMapLayer, ITiledTileSet} from "../Map/ITiledMap";
|
import {ITiledMap, ITiledMapLayer, ITiledTileSet} from "../Map/ITiledMap";
|
||||||
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
import {PLAYER_RESOURCES} from "../Entity/PlayableCharacter";
|
||||||
import Texture = Phaser.Textures.Texture;
|
import Texture = Phaser.Textures.Texture;
|
||||||
import Sprite = Phaser.GameObjects.Sprite;
|
import Sprite = Phaser.GameObjects.Sprite;
|
||||||
import CanvasTexture = Phaser.Textures.CanvasTexture;
|
import CanvasTexture = Phaser.Textures.CanvasTexture;
|
||||||
@ -30,7 +30,7 @@ export class GameScene extends Phaser.Scene {
|
|||||||
CurrentPlayer: CurrentGamerInterface;
|
CurrentPlayer: CurrentGamerInterface;
|
||||||
MapPlayers : Phaser.Physics.Arcade.Group;
|
MapPlayers : Phaser.Physics.Arcade.Group;
|
||||||
MapPlayersByKey : Map<string, GamerInterface> = new Map<string, GamerInterface>();
|
MapPlayersByKey : Map<string, GamerInterface> = new Map<string, GamerInterface>();
|
||||||
Map: Phaser.Tilemaps.Tilemap|null = null;
|
Map: Phaser.Tilemaps.Tilemap;
|
||||||
Layers : Array<Phaser.Tilemaps.StaticTilemapLayer>;
|
Layers : Array<Phaser.Tilemaps.StaticTilemapLayer>;
|
||||||
Objects : Array<Phaser.Physics.Arcade.Sprite>;
|
Objects : Array<Phaser.Physics.Arcade.Sprite>;
|
||||||
mapFile: ITiledMap|null;
|
mapFile: ITiledMap|null;
|
||||||
@ -38,7 +38,7 @@ export class GameScene extends Phaser.Scene {
|
|||||||
startX = 704;// 22 case
|
startX = 704;// 22 case
|
||||||
startY = 32; // 1 case
|
startY = 32; // 1 case
|
||||||
circleTexture: CanvasTexture;
|
circleTexture: CanvasTexture;
|
||||||
initPosition: PositionInterface|null = null;
|
private initPosition: PositionInterface|null = null;
|
||||||
private playersPositionInterpolator = new PlayersPositionInterpolator();
|
private playersPositionInterpolator = new PlayersPositionInterpolator();
|
||||||
|
|
||||||
MapKey: string;
|
MapKey: string;
|
||||||
@ -121,7 +121,9 @@ export class GameScene extends Phaser.Scene {
|
|||||||
|
|
||||||
//hook initialisation
|
//hook initialisation
|
||||||
init(initData : GameSceneInitInterface) {
|
init(initData : GameSceneInitInterface) {
|
||||||
this.initPosition = initData.initPosition;
|
if (initData.initPosition !== undefined) {
|
||||||
|
this.initPosition = initData.initPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//hook create scene
|
//hook create scene
|
||||||
@ -338,7 +340,7 @@ export class GameScene extends Phaser.Scene {
|
|||||||
//initialise player
|
//initialise player
|
||||||
//TODO create animation moving between exit and start
|
//TODO create animation moving between exit and start
|
||||||
this.CurrentPlayer = new Player(
|
this.CurrentPlayer = new Player(
|
||||||
null, // The current player is not has no id (because the id can change if connection is lost and we should check that id using the GameManager.
|
null, // The current player has no id (because the id can change if connection is lost and we should check that id using the GameManager.)
|
||||||
this,
|
this,
|
||||||
this.startX,
|
this.startX,
|
||||||
this.startY,
|
this.startY,
|
||||||
@ -503,9 +505,10 @@ export class GameScene extends Phaser.Scene {
|
|||||||
let player = this.MapPlayersByKey.get(userId);
|
let player = this.MapPlayersByKey.get(userId);
|
||||||
if (player === undefined) {
|
if (player === undefined) {
|
||||||
console.error('Cannot find user with id ', userId);
|
console.error('Cannot find user with id ', userId);
|
||||||
|
} else {
|
||||||
|
player.destroy();
|
||||||
|
this.MapPlayers.remove(player);
|
||||||
}
|
}
|
||||||
player.destroy();
|
|
||||||
this.MapPlayers.remove(player);
|
|
||||||
this.MapPlayersByKey.delete(userId);
|
this.MapPlayersByKey.delete(userId);
|
||||||
this.playersPositionInterpolator.removePlayer(userId);
|
this.playersPositionInterpolator.removePlayer(userId);
|
||||||
}
|
}
|
||||||
@ -525,8 +528,9 @@ export class GameScene extends Phaser.Scene {
|
|||||||
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
|
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
|
||||||
let groupId = groupPositionMessage.groupId;
|
let groupId = groupPositionMessage.groupId;
|
||||||
|
|
||||||
if (this.groups.has(groupId)) {
|
let group = this.groups.get(groupId);
|
||||||
this.groups.get(groupId).setPosition(Math.round(groupPositionMessage.position.x), Math.round(groupPositionMessage.position.y));
|
if (group !== undefined) {
|
||||||
|
group.setPosition(Math.round(groupPositionMessage.position.x), Math.round(groupPositionMessage.position.y));
|
||||||
} else {
|
} else {
|
||||||
// TODO: circle radius should not be hard stored
|
// TODO: circle radius should not be hard stored
|
||||||
let sprite = new Sprite(
|
let sprite = new Sprite(
|
||||||
@ -541,10 +545,11 @@ export class GameScene extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deleteGroup(groupId: string): void {
|
deleteGroup(groupId: string): void {
|
||||||
if(!this.groups.get(groupId)){
|
let group = this.groups.get(groupId);
|
||||||
|
if(!group){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.groups.get(groupId).destroy();
|
group.destroy();
|
||||||
this.groups.delete(groupId);
|
this.groups.delete(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import {TextInput} from "../Components/TextInput";
|
|||||||
import {ClickButton} from "../Components/ClickButton";
|
import {ClickButton} from "../Components/ClickButton";
|
||||||
import Image = Phaser.GameObjects.Image;
|
import Image = Phaser.GameObjects.Image;
|
||||||
import Rectangle = Phaser.GameObjects.Rectangle;
|
import Rectangle = Phaser.GameObjects.Rectangle;
|
||||||
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
import {PLAYER_RESOURCES} from "../Entity/PlayableCharacter";
|
||||||
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
||||||
import {SelectCharacterSceneInitDataInterface, SelectCharacterSceneName} from "./SelectCharacterScene";
|
import {SelectCharacterSceneInitDataInterface, SelectCharacterSceneName} from "./SelectCharacterScene";
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import {TextField} from "../Components/TextField";
|
|||||||
import {ClickButton} from "../Components/ClickButton";
|
import {ClickButton} from "../Components/ClickButton";
|
||||||
import Image = Phaser.GameObjects.Image;
|
import Image = Phaser.GameObjects.Image;
|
||||||
import Rectangle = Phaser.GameObjects.Rectangle;
|
import Rectangle = Phaser.GameObjects.Rectangle;
|
||||||
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
import {PLAYER_RESOURCES} from "../Entity/PlayableCharacter";
|
||||||
|
|
||||||
//todo: put this constants in a dedicated file
|
//todo: put this constants in a dedicated file
|
||||||
export const SelectCharacterSceneName = "SelectCharacterScene";
|
export const SelectCharacterSceneName = "SelectCharacterScene";
|
||||||
|
@ -2,16 +2,16 @@ import {PlayerAnimationNames} from "./Animation";
|
|||||||
import {GameScene, Textures} from "../Game/GameScene";
|
import {GameScene, Textures} from "../Game/GameScene";
|
||||||
import {MessageUserPositionInterface, PointInterface} from "../../Connection";
|
import {MessageUserPositionInterface, PointInterface} from "../../Connection";
|
||||||
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
|
||||||
import {PlayableCaracter} from "../Entity/PlayableCaracter";
|
import {PlayableCharacter} from "../Entity/PlayableCharacter";
|
||||||
|
|
||||||
|
|
||||||
export const hasMovedEventName = "hasMoved";
|
export const hasMovedEventName = "hasMoved";
|
||||||
export interface CurrentGamerInterface extends PlayableCaracter{
|
export interface CurrentGamerInterface extends PlayableCharacter{
|
||||||
moveUser(delta: number) : void;
|
moveUser(delta: number) : void;
|
||||||
say(text : string) : void;
|
say(text : string) : void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GamerInterface extends PlayableCaracter{
|
export interface GamerInterface extends PlayableCharacter{
|
||||||
userId : string;
|
userId : string;
|
||||||
updatePosition(position: PointInterface): void;
|
updatePosition(position: PointInterface): void;
|
||||||
say(text : string) : void;
|
say(text : string) : void;
|
||||||
@ -27,7 +27,7 @@ interface AnimationData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class Player extends PlayableCaracter implements CurrentGamerInterface, GamerInterface {
|
export class Player extends PlayableCharacter implements CurrentGamerInterface, GamerInterface {
|
||||||
userId: string;
|
userId: string;
|
||||||
userInputManager: UserInputManager;
|
userInputManager: UserInputManager;
|
||||||
previousDirection: string;
|
previousDirection: string;
|
||||||
|
@ -4,7 +4,7 @@ import {TextInput} from "../Components/TextInput";
|
|||||||
import {ClickButton} from "../Components/ClickButton";
|
import {ClickButton} from "../Components/ClickButton";
|
||||||
import Image = Phaser.GameObjects.Image;
|
import Image = Phaser.GameObjects.Image;
|
||||||
import Rectangle = Phaser.GameObjects.Rectangle;
|
import Rectangle = Phaser.GameObjects.Rectangle;
|
||||||
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
import {PLAYER_RESOURCES} from "../Entity/PlayableCharacter";
|
||||||
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
||||||
import Sprite = Phaser.GameObjects.Sprite;
|
import Sprite = Phaser.GameObjects.Sprite;
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ import Map = Phaser.Structs.Map;
|
|||||||
import {GameScene} from "../Game/GameScene";
|
import {GameScene} from "../Game/GameScene";
|
||||||
|
|
||||||
interface UserInputManagerDatum {
|
interface UserInputManagerDatum {
|
||||||
keyCode: number;
|
|
||||||
keyInstance: Phaser.Input.Keyboard.Key;
|
keyInstance: Phaser.Input.Keyboard.Key;
|
||||||
event: UserInputEvent
|
event: UserInputEvent
|
||||||
}
|
}
|
||||||
@ -33,27 +32,26 @@ export class ActiveEventList {
|
|||||||
|
|
||||||
//this class is responsible for catching user inputs and listing all active user actions at every game tick events.
|
//this class is responsible for catching user inputs and listing all active user actions at every game tick events.
|
||||||
export class UserInputManager {
|
export class UserInputManager {
|
||||||
private KeysCode: UserInputManagerDatum[] = [
|
private KeysCode: UserInputManagerDatum[];
|
||||||
{keyCode: Phaser.Input.Keyboard.KeyCodes.Z, event: UserInputEvent.MoveUp, keyInstance: null},
|
|
||||||
{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 : GameScene) {
|
constructor(Scene : GameScene) {
|
||||||
this.KeysCode.forEach(d => {
|
|
||||||
d.keyInstance = Scene.input.keyboard.addKey(d.keyCode);
|
this.KeysCode = [
|
||||||
});
|
{event: UserInputEvent.MoveUp, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z) },
|
||||||
|
{event: UserInputEvent.MoveLeft, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q) },
|
||||||
|
{event: UserInputEvent.MoveDown, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S) },
|
||||||
|
{event: UserInputEvent.MoveRight, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D) },
|
||||||
|
|
||||||
|
{event: UserInputEvent.MoveUp, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP) },
|
||||||
|
{event: UserInputEvent.MoveLeft, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT) },
|
||||||
|
{event: UserInputEvent.MoveDown, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN) },
|
||||||
|
{event: UserInputEvent.MoveRight, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT) },
|
||||||
|
|
||||||
|
{event: UserInputEvent.SpeedUp, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SHIFT) },
|
||||||
|
|
||||||
|
{event: UserInputEvent.Interact, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E) },
|
||||||
|
{event: UserInputEvent.Shout, keyInstance: Scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.F) },
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
getEventListForGameTick(): ActiveEventList {
|
getEventListForGameTick(): ActiveEventList {
|
||||||
|
Loading…
Reference in New Issue
Block a user