- Starting class
This commit is contained in:
Kum1ta
2024-08-27 15:26:38 +02:00
parent fb725b2c18
commit 76a746efb1
7 changed files with 107 additions and 78 deletions

View File

@ -3,22 +3,14 @@
/* ::: :::::::: */
/* Ball.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 17:02:47 by edbernar #+# #+# */
/* Updated: 2024/08/26 17:19:01 by hubourge ### ########.fr */
/* Updated: 2024/08/27 14:31:15 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import * as THREE from '/node_modules/three/build/three.module.js';
// import * as THREE from '/static/javascript/three/build/three.module.js';
/*
Todo (Eddy) :
- Ajouter fonction pour changer la gravité de la balle (OK)
- Ajouter un effet plus naturel pour le déplacement de la balle (OK)
*/
import * as THREE from 'three';
class Ball
{
@ -107,6 +99,11 @@ class Ball
});
}
/*---------------------------------------------------*/
dispose()
{
}
}

View File

@ -3,15 +3,15 @@
/* ::: :::::::: */
/* Map.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
/* Updated: 2024/08/26 23:47:10 by hubourge ### ########.fr */
/* Updated: 2024/08/27 14:29:36 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
// import * as THREE from '/static/javascript/three/build/three.module.js';
import * as THREE from '/node_modules/three/build/three.module.js';
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { Video } from './Video.js';

View File

@ -3,16 +3,17 @@
/* ::: :::::::: */
/* Opponent.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/21 10:34:49 by edbernar #+# #+# */
/* Updated: 2024/08/26 17:19:16 by hubourge ### ########.fr */
/* Updated: 2024/08/27 14:27:49 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import { playerExist } from './Player'
import * as THREE from 'three';
// import * as THREE from '/static/javascript/three/build/three.module.js';
import * as THREE from '/node_modules/three/build/three.module.js';
let opponentExist = false;

View File

@ -3,14 +3,14 @@
/* ::: :::::::: */
/* Player.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
/* Updated: 2024/08/26 17:19:30 by hubourge ### ########.fr */
/* Updated: 2024/08/27 14:27:39 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import * as THREE from '/node_modules/three/build/three.module.js';
import * as THREE from 'three';
// import * as THREE from '/static/javascript/three/build/three.module.js';
/*

View File

@ -3,16 +3,13 @@
/* ::: :::::::: */
/* Video.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/26 18:57:00 by hubourge #+# #+# */
/* Updated: 2024/08/26 19:20:32 by hubourge ### ########.fr */
/* Updated: 2024/08/27 14:27:27 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
// import * as THREE from '/static/javascript/three/build/three.module.js';
import * as THREE from '/node_modules/three/build/three.module.js';
class Video
{
video = null;

View File

@ -3,14 +3,14 @@
/* ::: :::::::: */
/* main.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/08/26 17:25:57 by hubourge ### ########.fr */
/* Updated: 2024/08/27 15:21:49 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import * as THREE from '/node_modules/three/build/three.module.js';
import * as THREE from 'three';
// import * as THREE from '/static/javascript/three/build/three.module.js';
import { Player } from './class/Player'
import { Map } from './class/Map'
@ -39,12 +39,86 @@ Controls :
*/
let debug = false;
const fpsLocker = {
status: false,
limit: 60,
};
let previousTime = 0;
let scene = null;
let map = null;
let bar1 = null;
let renderer = null;
let player = null;
let spotLight = null;
let ambiantLight = null;
let ball = null;
let bar2 = null;
let opponent = null;
// ------------------- Stats -------------------- //
// ------------------- (need to be remove) -------------------- //
const stats = new Stats();
stats.showPanel(0); // 0: fps, 1: ms, 2: mémoire
stats.showPanel(0);
document.body.appendChild(stats.dom);
const cameraTmp = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight);
let controls = null;
// ------------------------------------------------------------ //
class Game
{
static create()
{
previousTime = Date.now();
scene = new THREE.Scene()
map = new Map(scene, 13, true);
bar1 = createBarPlayer(0xed56ea);
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
player = new Player(bar1, map);
spotLight = new THREE.SpotLight(0xffffff, 10000, 0, 0.2);
spotLight.castShadow = true;
ambiantLight = new THREE.AmbientLight(0xffffff, 0.5);
ball = new Ball(scene, map);
bar2 = createBarPlayer(0xf3e11e);
opponent = new Opponent(bar2, map);
debug = false;
scene.add(player.object);
scene.add(opponent.object);
scene.add(ambiantLight);
spotLight.position.set(0, 100, 0);
scene.add(spotLight);
scene.background = new THREE.Color(0x1a1a1a);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
ball.initMoveBallTmp();
map.ballObject = ball.object;
controls = new OrbitControls(cameraTmp, renderer.domElement)
cameraTmp.position.set(5, 3, 5);
controls.target = new THREE.Vector3(map.centerPos.x, 0, map.centerPos.z);
document.addEventListener('keypress', (e) => {
if (e.key == 'g')
player.pointAnimation(map);
if (e.key == 'h')
player.pointOpponentAnimation(map, opponent.object);
if (e.key == 'c')
debug = !debug;
})
renderer.setAnimationLoop(loop)
}
static dispose()
{
scene = null;
debug = false;
}
}
function createBarPlayer(color)
{
const geometry = new THREE.BoxGeometry(1, 0.1, 0.1);
@ -55,15 +129,17 @@ function createBarPlayer(color)
return (mesh);
}
let previousTime = Date.now();
function loop()
{
stats.begin();
// ===== FPS locker ===== //
const currentTime = Date.now();
if (currentTime - previousTime < 1000 / 60)
return ;
previousTime = currentTime;
if (fpsLocker.status)
{
const currentTime = Date.now();
if (currentTime - previousTime < 1000 / 60)
return ;
previousTime = currentTime;
}
// ====================== //
player.update();
@ -79,46 +155,4 @@ function loop()
stats.end();
}
const scene = new THREE.Scene();
const map = new Map(scene, 13, true);
const bar1 = createBarPlayer(0xed56ea);
const renderer = new THREE.WebGLRenderer({antialias: true});
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
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 bar2 = createBarPlayer(0xf3e11e);
const opponent = new Opponent(bar2, map);
scene.add(player.object);
scene.add(opponent.object);
scene.add(ambiantLight);
spotLight.position.set(0, 100, 0);
scene.add(spotLight);
scene.background = new THREE.Color(0x1a1a1a);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
ball.initMoveBallTmp();
map.ballObject = ball.object;
/*---------------DEBUG----------------*/
const cameraTmp = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight);
const controls = new OrbitControls(cameraTmp, renderer.domElement);
cameraTmp.position.set(5, 3, 5);
controls.target = new THREE.Vector3(map.centerPos.x, 0, map.centerPos.z);
/*------------------------------------*/
document.addEventListener('keypress', (e) => {
if (e.key == 'g')
player.pointAnimation(map);
if (e.key == 'h')
player.pointOpponentAnimation(map, opponent.object);
if (e.key == 'c')
debug = !debug;
})
renderer.setAnimationLoop(loop)
Game.create();

BIN
site/real_game/textures/.DS_Store vendored Normal file

Binary file not shown.