Game
- Implement boxMoves with key pressing - Fix moveBox speed
This commit is contained in:
6
site/game/controls.js
vendored
6
site/game/controls.js
vendored
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* controls.js :+: :+: :+: */
|
/* controls.js :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: edbernar <edbernar@student.42.fr> +#+ +:+ +#+ */
|
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/07 15:20:55 by hubourge #+# #+# */
|
/* Created: 2024/08/07 15:20:55 by hubourge #+# #+# */
|
||||||
/* Updated: 2024/08/07 16:19:53 by edbernar ### ########.fr */
|
/* Updated: 2024/08/07 16:53:34 by hubourge ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class Moves {
|
|||||||
class MoveObject {
|
class MoveObject {
|
||||||
#moves = null;
|
#moves = null;
|
||||||
#object = null;
|
#object = null;
|
||||||
#speed = 0.1;
|
#speed = 0.05;
|
||||||
|
|
||||||
constructor(object)
|
constructor(object)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/30 13:50:49 by edbernar #+# #+# */
|
/* Created: 2024/07/30 13:50:49 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/08/07 16:26:11 by hubourge ### ########.fr */
|
/* Updated: 2024/08/07 16:52:45 by hubourge ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -51,13 +51,11 @@ const ball = new THREE.Mesh(geometryBall, materialBall);
|
|||||||
ball.position.y = 0.1;
|
ball.position.y = 0.1;
|
||||||
ball.castShadow = true;
|
ball.castShadow = true;
|
||||||
scene.add(ball);
|
scene.add(ball);
|
||||||
const controlBall = new MoveObject(ball);
|
|
||||||
|
|
||||||
// --------------- Box Constrols -------------- //
|
// --------------- Box Constrols -------------- //
|
||||||
const boxLeft = createBox(scene, -4.45, 0.1 / 2, 0);
|
const boxLeft = createBox(scene, -4.45, 0.1 / 2, 0);
|
||||||
const boxRight = createBox(scene, 4.45, 0.1 / 2, 0);
|
const boxRight = createBox(scene, 4.45, 0.1 / 2, 0);
|
||||||
const controlBoxLeft = new MoveObject(boxLeft);
|
const controlBoxLeft = new MoveObject(boxLeft);
|
||||||
const controlBoxRight = new MoveObject(boxRight);
|
|
||||||
|
|
||||||
let spotLight = createSpotLight(0xffffff, ball, scene);
|
let spotLight = createSpotLight(0xffffff, ball, scene);
|
||||||
let lightAmbient = createLightAmbient(scene);
|
let lightAmbient = createLightAmbient(scene);
|
||||||
@ -80,37 +78,14 @@ function animate() {
|
|||||||
lightPoint = refreshLightPoint(scene, lightPoint);
|
lightPoint = refreshLightPoint(scene, lightPoint);
|
||||||
}
|
}
|
||||||
// controls.update();
|
// controls.update();
|
||||||
ball.position.x = Math.sin(Date.now() * 0.001) * 2;
|
ball.position.x = Math.sin(Date.now() * 0.001) * 2;
|
||||||
ball.position.z = Math.cos(Date.now() * 0.001) * 2;
|
ball.position.z = Math.cos(Date.now() * 0.001) * 2;
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
controlBall.update();
|
controlBoxLeft.update();
|
||||||
stats.end();
|
stats.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.setAnimationLoop(animate)
|
renderer.setAnimationLoop(animate)
|
||||||
document.addEventListener("keydown", onDocumentKeyDown, false);
|
|
||||||
function onDocumentKeyDown(event) {
|
|
||||||
var keyCode = event.which;
|
|
||||||
if (keyCode == 87) {
|
|
||||||
camera.position.z -= 0.1;
|
|
||||||
} else if (keyCode == 83) {
|
|
||||||
camera.position.z += 0.1;
|
|
||||||
} else if (keyCode == 65) {
|
|
||||||
camera.position.x -= 0.1;
|
|
||||||
} else if (keyCode == 68) {
|
|
||||||
camera.position.x += 0.1;
|
|
||||||
} else if (keyCode == 32) {
|
|
||||||
camera.position.set(0, 0, 0);
|
|
||||||
} else if (keyCode == 37) {
|
|
||||||
camera.rotation.y += 0.1;
|
|
||||||
} else if (keyCode == 39) {
|
|
||||||
camera.rotation.y -= 0.1;
|
|
||||||
} else if (keyCode == 38) {
|
|
||||||
camera.position.y += 0.1;
|
|
||||||
} else if (keyCode == 40) {
|
|
||||||
camera.position.y -= 0.1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener("wheel", onDocumentWheel, false);
|
document.addEventListener("wheel", onDocumentWheel, false);
|
||||||
function onDocumentWheel(event) {
|
function onDocumentWheel(event) {
|
||||||
|
Reference in New Issue
Block a user