Gane
- Continuing solo game
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/28 12:07:39 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/28 16:48:12 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/29 00:19:01 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,7 +33,7 @@ class SoloGame
|
||||
renderer.shadowMap.enabled = true;
|
||||
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
||||
Map.create(scene);
|
||||
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight);
|
||||
camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight);
|
||||
camera.rotation.x = -Math.PI / 2;
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
scene.background = new THREE.Color(0x252525);
|
||||
@ -42,8 +42,12 @@ class SoloGame
|
||||
Ball.create(scene);
|
||||
|
||||
controls = new OrbitControls(camera, renderer.domElement);
|
||||
camera.position.set(0, 11, 0);
|
||||
renderer.setAnimationLoop(loop)
|
||||
camera.position.set(0, 20, 0);
|
||||
renderer.setAnimationLoop(loop);
|
||||
|
||||
setTimeout(() => {
|
||||
Ball.moveBall();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
static dispose()
|
||||
@ -75,7 +79,6 @@ function loop()
|
||||
stats.begin();
|
||||
controls.update();
|
||||
Players.update();
|
||||
Ball.update();
|
||||
renderer.render(scene, camera);
|
||||
stats.end();
|
||||
}
|
||||
|
@ -6,17 +6,18 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/28 15:58:03 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/28 17:30:09 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/29 00:44:26 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
import * as THREE from 'three';
|
||||
import { wallTop, wallBottom } from './Map.js';
|
||||
import { player1, player2 } from './Players.js';
|
||||
|
||||
let ball = null;
|
||||
let speed = 0.3;
|
||||
// max 0.3 (sinon ca sort);
|
||||
let speed = 0.15;
|
||||
let dir = -1;
|
||||
let interval = null;
|
||||
|
||||
class Ball
|
||||
{
|
||||
@ -26,8 +27,8 @@ class Ball
|
||||
ball = createBall();
|
||||
|
||||
scene.add(ball);
|
||||
ball.rotateY(0.3);
|
||||
|
||||
ball.rotateY(0.8);
|
||||
|
||||
}
|
||||
|
||||
static dispose()
|
||||
@ -35,19 +36,36 @@ class Ball
|
||||
ball = null;
|
||||
}
|
||||
|
||||
static update()
|
||||
static moveBall()
|
||||
{
|
||||
moveForward(ball, speed, false);
|
||||
bounceWallTop();
|
||||
bounceWallTBottom();
|
||||
createInterval();
|
||||
}
|
||||
|
||||
|
||||
static stopBall()
|
||||
{
|
||||
if (interval)
|
||||
clearInterval(interval);
|
||||
}
|
||||
}
|
||||
|
||||
function moveForward(object, speed, bounceTop)
|
||||
function createInterval()
|
||||
{
|
||||
interval = setInterval(() => {
|
||||
console.log(ball.position);
|
||||
moveForward();
|
||||
bounceWallTop();
|
||||
bounceWallTBottom();
|
||||
bouncePlayer1();
|
||||
}, 16);
|
||||
}
|
||||
|
||||
function moveForward()
|
||||
{
|
||||
const direction = new THREE.Vector3(0, 0, dir);
|
||||
direction.applyQuaternion(object.quaternion);
|
||||
object.position.add(direction.multiplyScalar(speed));
|
||||
direction.applyQuaternion(ball.quaternion);
|
||||
|
||||
ball.position.add(direction.multiplyScalar(speed));
|
||||
}
|
||||
|
||||
function createBall()
|
||||
@ -57,7 +75,8 @@ function createBall()
|
||||
const mesh = new THREE.Mesh(geometry, material);
|
||||
|
||||
mesh.position.y += 0.3;
|
||||
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
mesh.position.set (0, mesh.position.y, 0);
|
||||
return (mesh);
|
||||
}
|
||||
@ -74,11 +93,8 @@ function bounceWallTop()
|
||||
|
||||
if (intersects.length > 0)
|
||||
{
|
||||
console.log("Distance du rayon à l'objet : ", intersects[0].distance);
|
||||
if (intersects[0].distance <= 0.5)
|
||||
{
|
||||
ball.rotation.y = Math.PI - ball.rotation.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,11 +110,25 @@ function bounceWallTBottom()
|
||||
|
||||
if (intersects.length > 0)
|
||||
{
|
||||
console.log("Distance du rayon à l'objet : ", intersects[0].distance);
|
||||
if (intersects[0].distance <= 0.5)
|
||||
{
|
||||
if (intersects[0].distance <= 0.4)
|
||||
ball.rotation.y = Math.PI - ball.rotation.y;
|
||||
}
|
||||
}
|
||||
|
||||
function bouncePlayer1()
|
||||
{
|
||||
const origin = new THREE.Vector3(ball.position.x, ball.position.y, ball.position.z);
|
||||
const direction = new THREE.Vector3(ball.position.x - 1, ball.position.y, ball.position.z);
|
||||
|
||||
direction.normalize();
|
||||
const raycaster = new THREE.Raycaster(origin, direction);
|
||||
const objects = [ player1 ];
|
||||
const intersects = raycaster.intersectObjects(objects);
|
||||
|
||||
if (intersects.length > 0)
|
||||
{
|
||||
if (intersects[0].distance <= 0.4)
|
||||
ball.rotation.y = Math.PI - ball.rotation.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/28 15:12:25 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/28 16:29:28 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/29 00:25:50 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -40,17 +40,18 @@ class Players
|
||||
|
||||
static update()
|
||||
{
|
||||
let i = 0;
|
||||
const limits = 4.55;
|
||||
let i = 0;
|
||||
|
||||
while (i < pressedButton.length)
|
||||
{
|
||||
if (pressedButton[i] == 'w' && player1.position.z > -5.05)
|
||||
if (pressedButton[i] == 'w' && player1.position.z > -limits)
|
||||
player1.position.z -= speed;
|
||||
else if (pressedButton[i] == 's' && player1.position.z < 5.05)
|
||||
else if (pressedButton[i] == 's' && player1.position.z < limits)
|
||||
player1.position.z += speed;
|
||||
else if (pressedButton[i] == 'ArrowUp' && player2.position.z > -5.05)
|
||||
else if (pressedButton[i] == 'ArrowUp' && player2.position.z > -limits)
|
||||
player2.position.z -= speed;
|
||||
else if (pressedButton[i] == 'ArrowDown' && player2.position.z < 5.05)
|
||||
else if (pressedButton[i] == 'ArrowDown' && player2.position.z < limits)
|
||||
player2.position.z += speed;
|
||||
i++;
|
||||
}
|
||||
@ -59,14 +60,16 @@ class Players
|
||||
|
||||
function newBarPlayer(nbPlayer)
|
||||
{
|
||||
const geometry = new THREE.BoxGeometry(0.1, 0.2, 2);
|
||||
const geometry = new THREE.BoxGeometry(0.3, 0.4, 2.5);
|
||||
const material = new THREE.MeshPhysicalMaterial({color: 0xffffff});
|
||||
const mesh = new THREE.Mesh(geometry, material);
|
||||
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
if (nbPlayer == 1)
|
||||
mesh.position.set(-12, 0.2, 0);
|
||||
mesh.position.set(-12, 0.4, 0);
|
||||
else
|
||||
mesh.position.set(12, 0.2, 0);
|
||||
mesh.position.set(12, 0.4, 0);
|
||||
return (mesh);
|
||||
}
|
||||
|
||||
@ -92,4 +95,4 @@ function remKeyInArr(e)
|
||||
pressedButton.splice(i, 1);
|
||||
}
|
||||
|
||||
export { Players };
|
||||
export { Players, player1, player2 };
|
30
site/real_game/node_modules/.vite/deps/_metadata.json
generated
vendored
30
site/real_game/node_modules/.vite/deps/_metadata.json
generated
vendored
@ -1,53 +1,47 @@
|
||||
{
|
||||
"hash": "7e76cfec",
|
||||
"configHash": "5fafa2f5",
|
||||
"hash": "aeb97021",
|
||||
"configHash": "0b4c6e74",
|
||||
"lockfileHash": "cd36b699",
|
||||
"browserHash": "93d0ec79",
|
||||
"browserHash": "19562a0a",
|
||||
"optimized": {
|
||||
"stats.js": {
|
||||
"src": "../../stats.js/build/stats.min.js",
|
||||
"file": "stats__js.js",
|
||||
"fileHash": "05a619eb",
|
||||
"fileHash": "02cf6dab",
|
||||
"needsInterop": true
|
||||
},
|
||||
"three": {
|
||||
"src": "../../three/build/three.module.js",
|
||||
"file": "three.js",
|
||||
"fileHash": "de5334d8",
|
||||
"fileHash": "b84c2f0c",
|
||||
"needsInterop": false
|
||||
},
|
||||
"three/addons/loaders/GLTFLoader.js": {
|
||||
"src": "../../three/examples/jsm/loaders/GLTFLoader.js",
|
||||
"file": "three_addons_loaders_GLTFLoader__js.js",
|
||||
"fileHash": "748f8d46",
|
||||
"fileHash": "c571cff0",
|
||||
"needsInterop": false
|
||||
},
|
||||
"three/examples/jsm/Addons.js": {
|
||||
"src": "../../three/examples/jsm/Addons.js",
|
||||
"file": "three_examples_jsm_Addons__js.js",
|
||||
"fileHash": "61a49f6c",
|
||||
"needsInterop": false
|
||||
},
|
||||
"three": {
|
||||
"src": "../../three/build/three.module.js",
|
||||
"file": "three.js",
|
||||
"fileHash": "9f980d32",
|
||||
"fileHash": "b1ac92b5",
|
||||
"needsInterop": false
|
||||
},
|
||||
"three/examples/jsm/controls/OrbitControls.js": {
|
||||
"src": "../../three/examples/jsm/controls/OrbitControls.js",
|
||||
"file": "three_examples_jsm_controls_OrbitControls__js.js",
|
||||
"fileHash": "7f2e8493",
|
||||
"fileHash": "470fb7a7",
|
||||
"needsInterop": false
|
||||
}
|
||||
},
|
||||
"chunks": {
|
||||
"chunk-X4PC2K6Q": {
|
||||
"file": "chunk-X4PC2K6Q.js"
|
||||
},
|
||||
"chunk-PJQOQ23Z": {
|
||||
"file": "chunk-PJQOQ23Z.js"
|
||||
},
|
||||
"chunk-X4PC2K6Q": {
|
||||
"file": "chunk-X4PC2K6Q.js"
|
||||
},
|
||||
"chunk-IS2ZBFBB": {
|
||||
"file": "chunk-IS2ZBFBB.js"
|
||||
},
|
||||
@ -55,4 +49,4 @@
|
||||
"file": "chunk-HKJ2B2AA.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
site/real_game/node_modules/.vite/deps/three_examples_jsm_Addons__js.js
generated
vendored
6
site/real_game/node_modules/.vite/deps/three_examples_jsm_Addons__js.js
generated
vendored
@ -1,6 +1,3 @@
|
||||
import {
|
||||
OrbitControls
|
||||
} from "./chunk-X4PC2K6Q.js";
|
||||
import {
|
||||
BufferGeometryUtils_exports,
|
||||
GLTFLoader,
|
||||
@ -9,6 +6,9 @@ import {
|
||||
mergeGroups,
|
||||
mergeVertices
|
||||
} from "./chunk-PJQOQ23Z.js";
|
||||
import {
|
||||
OrbitControls
|
||||
} from "./chunk-X4PC2K6Q.js";
|
||||
import {
|
||||
ACESFilmicToneMapping,
|
||||
AddEquation,
|
||||
|
Reference in New Issue
Block a user