Skip to content

Commit 7bfe9db

Browse files
committed
Adjust player position calculations.
1 parent 2b9175c commit 7bfe9db

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/nodes/Multiplayer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ export default class Multiplayer extends GameNode {
2020
this.background = background;
2121
this.players = [
2222
new Player({
23-
position: { x: 0, y: 0 },
2423
inputMap: inputs.player1,
2524
levels: campaign,
2625
startLevel,
2726
}),
2827

2928
new Player({
30-
position: { x: WIDTH / 2, y: 0 },
3129
inputMap: inputs.player2,
3230
levels: campaign,
3331
startLevel,
3432
}),
3533
];
34+
this.players[0].view.position = {
35+
x: (1 / 4) * WIDTH - this.players[0].view.width / 2,
36+
y: 0,
37+
};
38+
this.players[1].view.position = {
39+
x: (3 / 4) * WIDTH - this.players[1].view.width / 2,
40+
y: 0,
41+
};
3642

3743
for (let player of this.players) {
3844
player.onTopOut = () => {

src/nodes/Player.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTMLText, Point, Ticker, type PointData } from "pixi.js";
1+
import { HTMLText, Ticker } from "pixi.js";
22
import "pixi.js/math-extras";
33
import MeasurementPiece from "./MeasurementPiece";
44
import { DOWN, LEFT, RIGHT, UP } from "../points";
@@ -38,7 +38,6 @@ const BOARD_OFFSET_Y = 80;
3838

3939
interface Options {
4040
levels: Level[];
41-
position: PointData;
4241
inputMap: PlayerInput;
4342
startLevel: number;
4443
}
@@ -74,7 +73,7 @@ export default class Player extends GameNode {
7473
inputMap: PlayerInput;
7574
keyDelays: Record<string, number> = {};
7675

77-
constructor({ position, inputMap, levels, startLevel }: Options) {
76+
constructor({ inputMap, levels, startLevel }: Options) {
7877
super();
7978
this.#level = startLevel;
8079
// TODO be able to reference the "current" position based on the board.
@@ -128,11 +127,7 @@ export default class Player extends GameNode {
128127
this.levelSign.position = { x: 50, y: 10 };
129128
this.view.addChild(this.levelSign);
130129

131-
this.view.pivot.set(this.view.width / 2, this.view.height / 2);
132-
this.view.position = new Point(
133-
position.x + this.view.width / 2,
134-
position.y + this.view.height / 2
135-
);
130+
this.view.origin.set(this.view.width / 2, this.view.height / 2);
136131

137132
this.newCurrent();
138133
}

src/nodes/SinglePlayer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ export default class SinglePlayer extends GameNode {
2323
super();
2424
this.background = background;
2525
this.player = new Player({
26-
position: { x: WIDTH / 2 - 300, y: 0 },
2726
inputMap: inputs.player1,
2827
levels: campaign,
2928
startLevel,
3029
});
30+
this.player.view.position = {
31+
x: WIDTH / 2 - this.player.view.width / 2,
32+
y: 0,
33+
};
3134
this.view.addChild(this.player.view);
3235

3336
this.player.onLevelUp = (level) => {

0 commit comments

Comments
 (0)