Skip to content

Commit

Permalink
spawn point is not spaned on invalid regions
Browse files Browse the repository at this point in the history
  • Loading branch information
keshav2010 committed May 5, 2024
1 parent fc5dd98 commit 134c199
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions public/scenes/SpawnSelectionScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BaseScene } from "./BaseScene";
import { PacketType } from "../../common/PacketType";
import { PlayerCastle } from "../gameObjects/playerCastle";
import SessionStateClientHelpers from "../helpers/SessionStateClientHelpers";
import SAT from "sat";

var networkManager: NetworkManager;
var selectorGraphics: Phaser.GameObjects.Graphics;
Expand Down Expand Up @@ -214,11 +215,10 @@ export class SpawnSelectionScene extends BaseScene {
}
);


this.AddSceneEvent(
PacketType.ByServer.SPAWN_POINT_RJCT,
(data: { message: any;}) => {
console.log('spawn point request rejected');
(data: { message: any }) => {
console.log("spawn point request rejected", data);
}
);

Expand Down Expand Up @@ -246,8 +246,8 @@ export class SpawnSelectionScene extends BaseScene {

showSpawnFlag(
networkManager: NetworkManager,
posX?: number,
posY?: number,
posX: number,
posY: number,
playerId?: string
) {
//show new choice on map for player
Expand All @@ -271,6 +271,19 @@ export class SpawnSelectionScene extends BaseScene {
}
const x = posX || posX === 0 ? posX : player!.posX;
const y = posY || posY === 0 ? posY : player!.posY;

const sceneBoundingBox = new SAT.Box(
new SAT.Vector(64, 64),
this.canvasWidth - 64 * 2,
this.canvasHeight - 64 * 2
);
const requestedPoint = new SAT.Vector(x - 64 / 2, y - 64 / 2);
const pointInPolygon = SAT.pointInPolygon(
requestedPoint,
sceneBoundingBox.toPolygon()
);
if (!pointInPolygon) return;

if (spawnFlag) {
spawnFlag.setPosition(x, y);
spawnFlag.setHealth(2);
Expand Down

0 comments on commit 134c199

Please sign in to comment.