Skip to content

Commit 37a18ad

Browse files
committed
Add small animation moving left and right.
1 parent a8ed163 commit 37a18ad

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

src/animations.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ export async function slideIn(
2525
[obj, { alpha: 1 }, { at: 0, duration: 1 }],
2626
]);
2727
}
28+
29+
export async function bump(obj: Container, direction: Point, amount: number) {
30+
await animate(obj.position, direction.multiplyScalar(amount), {
31+
duration: 0.05,
32+
ease: "easeIn",
33+
});
34+
await animate(
35+
obj.position,
36+
{ x: 0, y: 0 },
37+
{ duration: 0.1, ease: "easeOut" }
38+
);
39+
}

src/nodes/GatePiece.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const rotationSpeed = Math.PI / 16;
1111
export default class GatePiece extends GameNode {
1212
angle: number;
1313
axis: Axis;
14+
15+
container: Container;
1416
background: Graphics;
1517
angleMarker: Graphics;
1618
outline: Graphics;
@@ -19,7 +21,9 @@ export default class GatePiece extends GameNode {
1921
super();
2022
this.axis = axis;
2123
this.angle = angle;
22-
this.view = new Container();
24+
this.container = new Container();
25+
this.view.addChild(this.container);
26+
2327
this.angleMarker = new Graphics();
2428
this.background = new Graphics();
2529
this.outline = new Graphics()
@@ -32,7 +36,7 @@ export default class GatePiece extends GameNode {
3236
)
3337
.stroke({ color: "white", width: 2, alpha: 0.5 });
3438
this.outline.alpha = 0;
35-
this.view.addChild(this.outline);
39+
this.container.addChild(this.outline);
3640
const colorMap = octet(axis);
3741
for (let i = 0; i < 8; i++) {
3842
let angle = (i / 8) * 2 * Math.PI - Math.PI / 2;
@@ -48,8 +52,8 @@ export default class GatePiece extends GameNode {
4852
)
4953
.fill(getColor(getBlochCoords(colorMap[i])));
5054
}
51-
this.view.addChild(this.background);
52-
this.view.addChild(this.angleMarker);
55+
this.container.addChild(this.background);
56+
this.container.addChild(this.angleMarker);
5357
this.drawAngle();
5458
}
5559

src/nodes/MeasurementPiece.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
import { Graphics } from "pixi.js";
1+
import { Container, Graphics } from "pixi.js";
22
import { getBlochCoords, getOrtho, randomQubit, type Qubit } from "../quantum";
33
import { getColor } from "../colors";
44
import { PIECE_RADIUS } from "../constants";
55
import GameNode from "./GameNode";
66

77
// Represents a measurement along an axis
88
export default class MeasurementPiece extends GameNode {
9+
container: Container;
10+
911
sprite: Graphics;
1012
rod: Graphics;
1113
base: Qubit;
1214
ortho: Qubit;
1315
constructor(base: Qubit) {
1416
super();
17+
this.container = new Container();
18+
this.view.addChild(this.container);
19+
1520
this.base = base;
1621
this.ortho = getOrtho(base);
1722
this.sprite = new Graphics();
1823
this.rod = new Graphics();
19-
this.view.addChild(this.sprite);
20-
this.view.addChild(this.rod);
24+
this.container.addChild(this.sprite);
25+
this.container.addChild(this.rod);
2126
this.draw();
2227
}
2328

src/nodes/Player.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { campaign, type Level } from "../levels";
1818
import GameNode from "./GameNode";
1919
import { animate } from "motion";
2020
import { inputs, type PlayerInput } from "../inputs";
21-
import { pulse } from "../animations";
21+
import { bump, pulse } from "../animations";
2222
import { delay } from "../util";
2323
import { playSound } from "../audio";
2424
import HoldArea from "./HoldArea";
@@ -323,6 +323,7 @@ export default class Player extends GameNode {
323323
break;
324324
this.board.setCurrentPosition(left);
325325
playSound("move");
326+
bump(this.board.current!.container, LEFT, CELL_SIZE / 8);
326327
break;
327328
}
328329
case this.inputMap.right: {
@@ -344,6 +345,7 @@ export default class Player extends GameNode {
344345
}
345346
this.board.setCurrentPosition(right);
346347
playSound("move");
348+
bump(this.board.current!.container, RIGHT, CELL_SIZE / 8);
347349
break;
348350
}
349351
// If the player presses down, speed up the steps

src/nodes/QubitPair.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ import { CELL_SIZE } from "../constants";
22
import { randomQubit, type Qubit } from "../quantum";
33
import QubitPiece from "./QubitPiece";
44
import GameNode from "./GameNode";
5+
import { Container } from "pixi.js";
56

67
type Orientation = "vertical" | "horizontal";
78
// A pair of qubits
89
export default class QubitPair extends GameNode {
10+
container: Container;
911
first: QubitPiece;
1012
second: QubitPiece;
1113
orientation: Orientation = "vertical";
1214

1315
constructor(first: Qubit, second: Qubit) {
1416
super();
17+
this.container = new Container();
18+
this.view.addChild(this.container);
19+
1520
this.first = new QubitPiece(first);
1621
this.second = new QubitPiece(second);
17-
this.view.addChild(this.first.view);
18-
this.view.addChild(this.second.view);
22+
this.container.addChild(this.first.view);
23+
this.container.addChild(this.second.view);
1924
this.setPositions();
2025
}
2126

0 commit comments

Comments
 (0)