Skip to content

Commit 5842d92

Browse files
committed
Slide in animations for players.
1 parent 7bfe9db commit 5842d92

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

src/animations.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { animate } from "motion";
2-
import type { Container } from "pixi.js";
2+
import type { Container, Point } from "pixi.js";
3+
import { WIDTH } from "./constants";
34

45
export async function pulse(obj: Container, amount: number = 1.15) {
56
await animate([
@@ -11,3 +12,16 @@ export async function pulse(obj: Container, amount: number = 1.15) {
1112
[obj.scale, { x: 1, y: 1 }, { duration: 0.15, ease: "easeInOut" }],
1213
]);
1314
}
15+
16+
export async function slideIn(
17+
obj: Container,
18+
position: Point,
19+
direction: Point
20+
) {
21+
obj.position = position.add(direction.multiplyScalar(WIDTH));
22+
obj.alpha = 0;
23+
await animate([
24+
[obj.position, { ...position }, { duration: 1, ease: "easeOut" }],
25+
[obj, { alpha: 1 }, { at: 0, duration: 1 }],
26+
]);
27+
}

src/nodes/Multiplayer.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Ticker } from "pixi.js";
1+
import { Point, type Ticker } from "pixi.js";
22
import { WIDTH } from "../constants";
33
import GameNode from "./GameNode";
44
import Player from "./Player";
@@ -8,6 +8,8 @@ import { inputs } from "../inputs";
88
import Countdown from "./Countdown";
99
import type { IMediaInstance } from "@pixi/sound";
1010
import { playSound } from "../audio";
11+
import { LEFT, RIGHT } from "../points";
12+
import { slideIn } from "../animations";
1113

1214
export default class Multiplayer extends GameNode {
1315
players: Player[];
@@ -31,15 +33,6 @@ export default class Multiplayer extends GameNode {
3133
startLevel,
3234
}),
3335
];
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-
};
42-
4336
for (let player of this.players) {
4437
player.onTopOut = () => {
4538
this.music?.stop();
@@ -55,11 +48,24 @@ export default class Multiplayer extends GameNode {
5548
// TODO show win screen
5649
this.onFinish?.();
5750
};
58-
this.view.addChild(player.view);
5951
}
6052
}
6153

6254
async start() {
55+
for (let player of this.players) {
56+
this.view.addChild(player.view);
57+
}
58+
slideIn(
59+
this.players[0].view,
60+
new Point((1 / 4) * WIDTH - this.players[0].view.width / 2, 0),
61+
LEFT
62+
);
63+
slideIn(
64+
this.players[1].view,
65+
new Point((3 / 4) * WIDTH - this.players[1].view.width / 2, 0),
66+
RIGHT
67+
);
68+
6369
const countdown = new Countdown();
6470
this.view.addChild(countdown.view);
6571
await countdown.start();

src/nodes/SinglePlayer.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Ticker } from "pixi.js";
1+
import { Point, type Ticker } from "pixi.js";
22
import { WIDTH } from "../constants";
33
import GameNode from "./GameNode";
44
import Player from "./Player";
@@ -9,6 +9,8 @@ import ScoreScreen from "./ScoreScreen";
99
import Countdown from "./Countdown";
1010
import { type IMediaInstance } from "@pixi/sound";
1111
import { playSound } from "../audio";
12+
import { slideIn } from "../animations";
13+
import { UP } from "../points";
1214

1315
type Mode = "game" | "score";
1416

@@ -27,12 +29,6 @@ export default class SinglePlayer extends GameNode {
2729
levels: campaign,
2830
startLevel,
2931
});
30-
this.player.view.position = {
31-
x: WIDTH / 2 - this.player.view.width / 2,
32-
y: 0,
33-
};
34-
this.view.addChild(this.player.view);
35-
3632
this.player.onLevelUp = (level) => {
3733
this.background.setGenerator(level.randomQubit);
3834
};
@@ -54,6 +50,13 @@ export default class SinglePlayer extends GameNode {
5450
}
5551

5652
async start() {
53+
this.view.addChild(this.player.view);
54+
slideIn(
55+
this.player.view,
56+
new Point(WIDTH / 2 - this.player.view.width / 2, 0),
57+
UP
58+
);
59+
5760
const countdown = new Countdown();
5861
this.view.addChild(countdown.view);
5962
await countdown.start();

0 commit comments

Comments
 (0)