- Updating ball moves
This commit is contained in:
Hugo Bourgeon
2024-08-20 17:29:41 +02:00
parent 2543e1ea3b
commit d46f1636b4
15 changed files with 960 additions and 41 deletions

View File

@ -6,7 +6,7 @@
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/08/20 16:11:26 by hubourge ### ########.fr */
/* Updated: 2024/08/20 17:28:36 by hubourge ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@ import * as THREE from 'three';
import { Player } from './class/Player'
import { Map } from './class/Map'
import { OrbitControls } from 'three/examples/jsm/Addons.js';
import { update } from 'three/examples/jsm/libs/tween.module.js';
function createBarPlayer(color)
{
@ -29,6 +30,9 @@ function loop()
{
player.update();
renderer.render(scene, player.camera);
// ===== test ball =====
updateBall();
}
function createMap()
@ -50,6 +54,40 @@ const player = new Player(bar);
const spotLight = new THREE.SpotLight(0xffffff, 10000, 0, Math.PI / 4);
const ambiantLight = new THREE.AmbientLight(0xffffff, 1);
// ===== test ball =====
const geometryBall = new THREE.SphereGeometry(0.15, 32, 32);
const materialBall = new THREE.MeshPhysicalMaterial({color: 0xff0000});
const ball = new THREE.Mesh(geometryBall, materialBall);
ball.position.x = map.centerPos.x;
ball.position.y = map.centerPos.y + 0.15;
ball.position.z = map.centerPos.z;
ball.receiveShadow = true;
ball.castShadow = true;
scene.add(ball);
function updateBall()
{
// pressedButton = [];
let i = 0;
let interval = null;
let speed = 0.01;
const limits = {
up : 3,
down: 0.2,
left: -3,
right: 3,
}
document.addEventListener('keypress', (e) => {
if (e.key == '9')
{
ball.position.z += speed;
console.log(e.key);
}
});
}
// =====================
scene.add(player.object);
scene.add(ambiantLight);
spotLight.position.set(0, 100, 0);