Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25,176 changes: 25,176 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
"vite": "^3.1.0"
},
"dependencies": {
"three": "^0.145.0"

"libxmljs": "^0.19.10",
"node-gyp": "^9.3.0",
"src": "^1.1.2",
"three": "^0.128.0"

},
"staticFiles": {
"staticPath": "src/images"
Expand Down
30 changes: 30 additions & 0 deletions src/audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as THREE from "three";

export const addAudioListenerToCamera = (camera) => {
camera.camera.add(createAudioListener());
};

const songUrl = require("./sounds/bg1.mp3");
const songUrl1 = require("./sounds/tile.mp3");

export const createAudioListener = () => {
const listener = new THREE.AudioListener();

const audioLoader = new THREE.AudioLoader();

const sound = new THREE.Audio(listener);

audioLoader.load(songUrl, (buffer) => {
sound.setBuffer(buffer);
sound.setLoop(true);
sound.setVolume(0.3);
sound.play();
});

return listener;
};

export const tile_sound = () => {
const audio = new Audio(songUrl1);
audio.play();
}
2 changes: 1 addition & 1 deletion src/game-camera.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BoxGeometry, Clock, Color, Mesh, MeshPhongMaterial, OrthographicCamera, PerspectiveCamera, Scene, Vector2, Vector3 } from 'three';
import { BoxGeometry, Audio, AudioLoader, Clock, Color, Mesh, MeshPhongMaterial, OrthographicCamera, PerspectiveCamera, Scene, Vector2, Vector3, AudioListener } from 'three';

export class GameCamera {
camera: PerspectiveCamera
Expand Down
13 changes: 12 additions & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
Audio,
AudioLoader,
AmbientLight,
Box3,
BoxGeometry,
Expand All @@ -11,15 +13,19 @@ import {
Vector2,
Vector3,
WebGLRenderer,
AudioListener,
} from "three";
import * as THREE from "three";
import { addAudioListenerToCamera } from "./audio";
import { tile_sound } from "./audio";

import { GameCamera } from "./game-camera";
import { MovingTile } from "./moving-tile";
import { PerfectEffect } from "./perfect-effect";
import { Tile } from "./tile";
import { FadingTile } from './fading-tile';

import { Stats } from "./stats";

export class Game {
cubes: Tile[] = [];
effects: PerfectEffect[] = [];
Expand All @@ -38,6 +44,7 @@ export class Game {
debug = false;
clicked = false;


constructor() {
const urlParams = new URLSearchParams(window.location.search);
this.debug = Boolean(urlParams.get('debug'));
Expand All @@ -58,6 +65,8 @@ export class Game {
this.renderer.domElement.addEventListener("click", this.onClick.bind(this));

this.animate();
addAudioListenerToCamera(this.camera);

}

onClick() {
Expand All @@ -66,6 +75,7 @@ export class Game {
this.cutBox();
this.moveUp();
this.clicked = false
tile_sound();
}

onWindowResize() {
Expand Down Expand Up @@ -199,6 +209,7 @@ export class Game {
});
this.scene.add(plane.mesh);
this.effects.push(plane);

}

reset() {
Expand Down
63 changes: 41 additions & 22 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,47 @@
html {
overflow: hidden;
}
body {
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
background: black;
user-select: none;
}

body {
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
background: black;
cursor: none;
user-select: none;
}
#points {
text-align: center;
color: white;
font-size: 5rem;
position: fixed;
top: 2rem;
width: 100%;
}

#btn {
display: flex;
justify-content: center;
background-color: white;
font-size: 2.5rem;
position: fixed;
bottom: 2rem;
left: 2rem;
width: 3.3rem;
height: 3rem;
border-radius: 50%;
padding: 0.4rem;
}
</style>
<script defer src="./index.ts"></script>
</head>
<body>

<div id="points">0</div>
<button id="btn">
A
</button>
<script>
</script>
</body>

#points {
text-align: center;
color: white;
font-size: 5rem;
position: fixed;
top: 2rem;
width: 100%;
}
</style>
<script type="module" defer src="./index.ts"></script>
</head>
<body>
<div id="points">0</div>
</body>
</html>
Binary file added src/sounds/bg1.mp3
Binary file not shown.
Binary file added src/sounds/tile.mp3
Binary file not shown.
Loading