Skip to content

Commit 6404d64

Browse files
committed
feat(app): add secret toggles for deparkanoid options
This includes the ability to toggle sounds and autoplay features in the game using `Meta + /` and `Meta + .` respectively.
1 parent b71e833 commit 6404d64

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/components/derparkanoid.tsx

+33-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function Deparkanoid() {
3434
let soundDie: p5.MediaElement;
3535
let ballImage: p5.Image;
3636
let paddleImage: p5.Image;
37+
let autoPlay = false;
3738

3839
function game(p: p5) {
3940
p.preload = () => {
@@ -72,7 +73,12 @@ export function Deparkanoid() {
7273
if (e.key === " ") {
7374
enableGame = true;
7475
ball.reset();
75-
return false;
76+
}
77+
if (e.key === "≥" && e.altKey) {
78+
autoPlay = !autoPlay;
79+
}
80+
if (e.key === "÷" && e.altKey) {
81+
enableSounds = !enableSounds
7682
}
7783
});
7884
el.addEventListener("contextmenu", (e) => {
@@ -100,7 +106,12 @@ export function Deparkanoid() {
100106
}
101107

102108
paddle.show();
103-
paddle.move();
109+
110+
if (autoPlay) {
111+
paddle.automove(ball);
112+
} else {
113+
paddle.move();
114+
}
104115

105116
ball.show();
106117
if (enableGame) {
@@ -917,6 +928,14 @@ export function Deparkanoid() {
917928
this.x,
918929
);
919930
}
931+
932+
automove(ball: Ball) {
933+
this.x = uncheckedClamp(
934+
PADDLE_HEIGHT / 2,
935+
this.p.width - this.width - PADDLE_HEIGHT / 2,
936+
ball.x - this.width / 2,
937+
);
938+
}
920939
}
921940

922941
class Ball {
@@ -965,7 +984,10 @@ export function Deparkanoid() {
965984
}
966985
if (this.y > this.p.height) {
967986
enableGame = false;
968-
if (enableSounds) soundDie.play();
987+
if (enableSounds) {
988+
soundDie.stop();
989+
soundDie.play();
990+
}
969991
this.reset();
970992
}
971993
}
@@ -979,7 +1001,10 @@ export function Deparkanoid() {
9791001
this.ySpeed *= -1;
9801002
this.y = paddle.y - this.radius;
9811003

982-
if (enableSounds) soundBounce.play();
1004+
if (enableSounds) {
1005+
soundBounce.stop();
1006+
soundBounce.play();
1007+
}
9831008
}
9841009
}
9851010

@@ -1007,7 +1032,10 @@ export function Deparkanoid() {
10071032
collision ||= true;
10081033
score += BRICK_SCORE;
10091034
bricks.splice(i, 1);
1010-
if (enableSounds) soundBreak.play();
1035+
if (enableSounds) {
1036+
soundBreak.stop();
1037+
soundBreak.play();
1038+
}
10111039
}
10121040
}
10131041
if (collision) this.ySpeed *= -1;

0 commit comments

Comments
 (0)