Skip to content

Commit dde913b

Browse files
chore: copy rhythm game prototype from replit
https://replit.com/@remarkablemark/Rhythm-Game
1 parent 540cbba commit dde913b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+123
-167
lines changed

.env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_APP_NAME=$npm_package_name
2+
VITE_APP_VERSION=$npm_package_version
3+
VITE_GOOGLE_ANALYTICS_ID=

.prettierrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"singleQuote": true,
3-
"semi": false
2+
"singleQuote": true
43
}

index.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@
4343
<body>
4444
<noscript>You need to enable JavaScript to play this game.</noscript>
4545
<script type="module">
46-
import kaboom from 'kaboom'
47-
kaboom()
46+
import kaboom from 'kaboom';
47+
48+
kaboom({
49+
width: 360,
50+
height: 480,
51+
});
4852
</script>
4953
<script type="module" src="src/main.ts"></script>
5054

public/sounds/music.mp3

3.17 MB
Binary file not shown.

public/sounds/music.webm

1.36 MB
Binary file not shown.
File renamed without changes.

public/sprites/down.png

1.18 KB

public/sprites/left.png

1.09 KB

public/sprites/right.png

1.1 KB

public/sprites/up.png

1.18 KB

src/events/cursors.ts

-22
This file was deleted.

src/events/index.ts

-1
This file was deleted.

src/gameobjects/enemy.ts

-5
This file was deleted.

src/gameobjects/index.ts

-2
This file was deleted.

src/gameobjects/player.ts

-5
This file was deleted.

src/main.ts

+110-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,111 @@
1-
import { start } from './scenes'
1+
import 'kaboom/global';
22

3-
start()
3+
enum Sound {
4+
score = 'score',
5+
music = 'music',
6+
}
7+
8+
loadSound(Sound.score, 'sounds/score.mp3');
9+
loadSound(Sound.music, 'sounds/music.webm');
10+
11+
play(Sound.music, { loop: true });
12+
13+
enum Direction {
14+
left = 'left',
15+
down = 'down',
16+
up = 'up',
17+
right = 'right',
18+
}
19+
20+
const directions = Object.values(Direction);
21+
22+
directions.forEach((direction) => {
23+
loadSprite(direction, `sprites/${direction}.png`);
24+
});
25+
26+
function getPosition(direction: Direction, y = 400) {
27+
switch (direction) {
28+
case Direction.left:
29+
return pos(30, y);
30+
case Direction.down:
31+
return pos(110, y);
32+
case Direction.up:
33+
return pos(190, y);
34+
case Direction.right:
35+
return pos(270, y);
36+
}
37+
}
38+
39+
enum Tag {
40+
left = 'left',
41+
down = 'down',
42+
up = 'up',
43+
right = 'right',
44+
direction = 'direction',
45+
}
46+
47+
const keys = {
48+
[Direction.left]: add([
49+
sprite(Direction.left),
50+
getPosition(Direction.left),
51+
area(),
52+
opacity(0.5),
53+
Tag.left,
54+
]),
55+
56+
[Direction.down]: add([
57+
sprite(Direction.down),
58+
getPosition(Direction.down),
59+
area(),
60+
opacity(0.5),
61+
Tag.down,
62+
]),
63+
64+
[Direction.up]: add([
65+
sprite(Direction.up),
66+
getPosition(Direction.up),
67+
area(),
68+
opacity(0.5),
69+
Tag.up,
70+
]),
71+
72+
[Direction.right]: add([
73+
sprite(Direction.right),
74+
getPosition(Direction.right),
75+
area(),
76+
opacity(0.5),
77+
Tag.right,
78+
]),
79+
};
80+
81+
directions.forEach((direction) => {
82+
onCollideUpdate(direction, Tag.direction, () => {
83+
if (isKeyPressed(direction)) {
84+
play(Sound.score);
85+
addKaboom(center());
86+
}
87+
});
88+
89+
onKeyDown(direction, () => {
90+
keys[direction].opacity = 1;
91+
});
92+
93+
onKeyRelease(direction, () => {
94+
keys[direction].opacity = 0.5;
95+
});
96+
});
97+
98+
loop(1, () => {
99+
const direction = directions[randi(4)];
100+
101+
add([
102+
sprite(direction),
103+
getPosition(direction, -60),
104+
move(DOWN, 250),
105+
area(),
106+
offscreen({ destroy: true }),
107+
Tag.direction,
108+
]);
109+
});
110+
111+
// debug.inspect = true;

src/scenes/game.ts

-22
This file was deleted.

src/scenes/index.ts

-2
This file was deleted.

src/scenes/start.ts

-5
This file was deleted.

src/sprites/apple.png

-512 Bytes
Binary file not shown.

src/sprites/bag.png

-630 Bytes
Binary file not shown.

src/sprites/bean.png

-708 Bytes
Binary file not shown.

src/sprites/bean.ts

-6
This file was deleted.

src/sprites/bobo.png

-606 Bytes
Binary file not shown.

src/sprites/boom.png

-1.74 KB
Binary file not shown.

src/sprites/btfly.png

-647 Bytes
Binary file not shown.

src/sprites/cloud.png

-426 Bytes
Binary file not shown.

src/sprites/coin.png

-309 Bytes
Binary file not shown.

src/sprites/cursor_default.png

-263 Bytes
Binary file not shown.

src/sprites/cursor_pointer.png

-266 Bytes
Binary file not shown.

src/sprites/dino.png

-965 Bytes
Binary file not shown.

src/sprites/door.png

-569 Bytes
Binary file not shown.

src/sprites/egg.png

-430 Bytes
Binary file not shown.

src/sprites/egg_crack.png

-491 Bytes
Binary file not shown.

src/sprites/ghosty.png

-586 Bytes
Binary file not shown.

src/sprites/ghosty.ts

-6
This file was deleted.

src/sprites/gigagantrum.png

-1.21 KB
Binary file not shown.

src/sprites/grape.png

-562 Bytes
Binary file not shown.

src/sprites/grass.png

-543 Bytes
Binary file not shown.

src/sprites/gun.png

-359 Bytes
Binary file not shown.

src/sprites/heart.png

-368 Bytes
Binary file not shown.

src/sprites/index.ts

-2
This file was deleted.

src/sprites/jumpy.png

-694 Bytes
Binary file not shown.

src/sprites/k.png

-895 Bytes
Binary file not shown.

src/sprites/ka.png

-1.53 KB
Binary file not shown.

src/sprites/key.png

-433 Bytes
Binary file not shown.

src/sprites/lightening.png

-361 Bytes
Binary file not shown.

src/sprites/mark.png

-557 Bytes
Binary file not shown.

src/sprites/meat.png

-687 Bytes
Binary file not shown.

src/sprites/moon.png

-480 Bytes
Binary file not shown.

src/sprites/mushroom.png

-563 Bytes
Binary file not shown.

src/sprites/note.png

-439 Bytes
Binary file not shown.

src/sprites/pineapple.png

-510 Bytes
Binary file not shown.

src/sprites/portal.png

-778 Bytes
Binary file not shown.

src/sprites/spike.png

-370 Bytes
Binary file not shown.

src/sprites/src

-1
This file was deleted.

src/sprites/steel.png

-599 Bytes
Binary file not shown.

src/sprites/sun.png

-523 Bytes
Binary file not shown.

src/sprites/sword.png

-315 Bytes
Binary file not shown.

src/sprites/watermelon.png

-550 Bytes
Binary file not shown.

src/types/gameobject.ts

-3
This file was deleted.

src/types/index.ts

-3
This file was deleted.

src/types/scene.ts

-3
This file was deleted.

src/types/sprite.ts

-4
This file was deleted.

src/types/vite-env.d.ts

-66
This file was deleted.

vite.config.mts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineConfig } from 'vite'
2-
import { createHtmlPlugin } from 'vite-plugin-html'
1+
import { defineConfig } from 'vite';
2+
import { createHtmlPlugin } from 'vite-plugin-html';
33

44
export default defineConfig({
55
build: {
@@ -9,4 +9,4 @@ export default defineConfig({
99
minifySyntax: false,
1010
},
1111
plugins: [createHtmlPlugin()],
12-
})
12+
});

0 commit comments

Comments
 (0)