- Update all class
This commit is contained in:
Kum1ta
2024-08-21 14:58:28 +02:00
parent 3498f32635
commit ede59c6d4b
21 changed files with 3563 additions and 4169 deletions

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/08/21 00:10:46 by edbernar ### ########.fr */
/* Updated: 2024/08/21 14:51:31 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,10 @@ import * as THREE from 'three';
import { Player } from './class/Player'
import { Map } from './class/Map'
import { Ball } from './class/Ball'
import { Opponent } from './class/Opponent'
import { OrbitControls } from 'three/examples/jsm/Addons.js';
let debug = false;
function createBarPlayer(color)
{
@ -21,7 +25,6 @@ function createBarPlayer(color)
const material = new THREE.MeshPhysicalMaterial({color: color});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 0.2, 0);
mesh.castShadow = true;
return (mesh);
}
@ -30,24 +33,35 @@ function loop()
{
player.update();
map.update(ball.object);
renderer.render(scene, player.camera);
if (debug)
{
controls.update();
renderer.render(scene, cameraTmp);
}
else
renderer.render(scene, player.camera);
}
const scene = new THREE.Scene();
const map = new Map(scene, 13);
const bar = createBarPlayer(0xed56ea);
const bar1 = createBarPlayer(0xed56ea);
const renderer = new THREE.WebGLRenderer({antialias: true});
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const player = new Player(bar, map);
const player = new Player(bar1, map);
const spotLight = new THREE.SpotLight(0xffffff, 10000, 0, 0.2);
spotLight.castShadow = true;
const ambiantLight = new THREE.AmbientLight(0xffffff, 0.5);
const ball = new Ball(scene, map)
const ball = new Ball(scene, map);
const bar2 = createBarPlayer(0xf3e11e);
const opponent = new Opponent(bar2, map);
scene.add(player.object);
scene.add(opponent.object);
console.log(player.object.position);
console.log(opponent.object.position);
scene.add(ambiantLight);
spotLight.position.set(0, 100, 0);
scene.add(spotLight);
@ -55,10 +69,28 @@ scene.background = new THREE.Color(0x1a1a1a);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
ball.initMoveBallTmp();
map.ballObject = ball.object;
// map.addDecor('blender/exported/map1.glb')
map.createGravityChanger(1, 1, false);
/*---------------DEBUG----------------*/
const cameraTmp = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight);
const controls = new OrbitControls(cameraTmp, renderer.domElement);
cameraTmp.position.set(15, 0, 15);
controls.target = new THREE.Vector3(map.centerPos.x, 0, map.centerPos.z);
/*------------------------------------*/
document.addEventListener('keypress', (e) => {
if (e.key == 'g')
player.pointAnimation(scene);
player.pointAnimation(map);
if (e.key == 'h')
player.pointOpponentAnimation(map, opponent.object);
if (e.key == 'c')
debug = !debug;
})
renderer.setAnimationLoop(loop)