-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created a quitremotegame function, added shaderpass to composer, clea…
…ned up overall game engine code
- Loading branch information
Showing
12 changed files
with
387 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
import * as THREE from 'three'; | ||
|
||
import { BALL_SIZE } from '../constants.js'; | ||
|
||
import { vertexShader } from '../shaders/vertexShader.js'; | ||
import { scoreBoardShader } from '../shaders/scoreBoardShader.js'; | ||
|
||
class Ball { | ||
constructor(scene){ | ||
this.geometry = new THREE.SphereGeometry(BALL_SIZE); | ||
this.geometry = new THREE.TorusGeometry(BALL_SIZE, 2.5); | ||
this.material = new THREE.MeshPhongMaterial( {color: 0xf0f0f0, emissive: 0x00000, specular: 0x111111, shininess: 100} ); | ||
|
||
this.mesh = new THREE.Mesh(this.geometry, this.material); | ||
this.mesh.position.set(0, 0, 0); | ||
//this.mesh.rotation.x = THREE.MathUtils.degToRad(90) | ||
this.mesh.rotation.x = THREE.MathUtils.degToRad(90) | ||
this.scene = scene// console.log(this.direction); | ||
this.dx = 0; | ||
this.dy = 0; | ||
} | ||
updatePosition(position) { | ||
this.mesh.position.set(position.x, this.mesh.position.y, position.z); | ||
// Update bounding sphere position if needed | ||
} | ||
addToScene(){ | ||
this.scene.add(this.mesh); | ||
} | ||
|
||
removeFromScene(){ | ||
this.scene.remove(this.mesh); | ||
if (this.geometry) { | ||
this.geometry.dispose(); | ||
} | ||
if (this.material) { | ||
this.material.dispose(); | ||
} | ||
this.mesh.traverse(child => { | ||
if (child.isMesh) { | ||
if (child.material.map) { | ||
child.material.map.dispose(); | ||
} | ||
|
||
}}); | ||
} | ||
} | ||
|
||
export default Ball; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { PADDLE_SPEED } from './constants.js'; | ||
import { globalState } from './globalState.js'; | ||
|
||
|
||
const keys = {}; | ||
document.addEventListener('keydown', (event) => { | ||
keys[event.key] = true; | ||
}); | ||
document.addEventListener('keyup', (event) => { | ||
keys[event.key] = false; | ||
}); | ||
|
||
export function localGameControls(gameSession) { | ||
let leftDeltaZ = 0; | ||
let rightDeltaZ = 0; | ||
if (gameSession.paused === true) { | ||
return; | ||
} | ||
if ((keys['w'] || keys['W']) && !gameSession.leftPaddle.intersectsWall(gameSession.playingField.upperWall.boundingBox)) { | ||
leftDeltaZ -= PADDLE_SPEED; | ||
} | ||
if ((keys['s'] || keys['S']) && !gameSession.leftPaddle.intersectsWall(gameSession.playingField.lowerWall.boundingBox)) { | ||
leftDeltaZ += PADDLE_SPEED; | ||
} | ||
if ((keys['ArrowUp']) && !gameSession.rightPaddle.intersectsWall(gameSession.playingField.upperWall.boundingBox)) { | ||
rightDeltaZ -= PADDLE_SPEED; | ||
} | ||
if ((keys['ArrowDown']) && !gameSession.rightPaddle.intersectsWall(gameSession.playingField.lowerWall.boundingBox)) { | ||
rightDeltaZ += PADDLE_SPEED; | ||
} | ||
gameSession.leftPaddle.move(leftDeltaZ) | ||
gameSession.rightPaddle.move(rightDeltaZ); | ||
|
||
if (leftDeltaZ !== 0 || rightDeltaZ !== 0) { | ||
let emitData = { | ||
'type': 'move_paddle', | ||
'game_id': gameSession.gameId, | ||
'player1_id': gameSession.player1Id, | ||
'p1_delta_z': leftDeltaZ, | ||
'player2_id': gameSession.player2Id, | ||
'p2_delta_z': rightDeltaZ | ||
}; | ||
gameSession.sendMovement(emitData); | ||
} | ||
} | ||
|
||
export function remoteGameControls(gameSession) { | ||
let deltaZ = 0; | ||
|
||
if (gameSession.paused === true) { | ||
return; | ||
} | ||
|
||
let playerPaddle; | ||
if (globalState.invertedView) | ||
playerPaddle = gameSession.rightPaddle; | ||
else | ||
playerPaddle = gameSession.leftPaddle; | ||
// Capture input for the local player’s paddle | ||
|
||
if (globalState.invertedView) { | ||
if ((keys['s'] || keys['S']) && !playerPaddle.intersectsWall(gameSession.playingField.upperWall.boundingBox)) { | ||
deltaZ -= PADDLE_SPEED; | ||
} | ||
else if ((keys['w'] || keys['W']) && !playerPaddle.intersectsWall(gameSession.playingField.lowerWall.boundingBox)){ | ||
deltaZ += PADDLE_SPEED; | ||
} | ||
//deltaZ *= -1 | ||
} | ||
else { | ||
if ((keys['w'] || keys['W']) && !playerPaddle.intersectsWall(gameSession.playingField.upperWall.boundingBox)) { | ||
deltaZ -= PADDLE_SPEED; | ||
} | ||
else if ((keys['s'] || keys['S']) && !playerPaddle.intersectsWall(gameSession.playingField.lowerWall.boundingBox)){ | ||
deltaZ += PADDLE_SPEED; | ||
} | ||
} | ||
playerPaddle.move(deltaZ) | ||
if (deltaZ !== 0) { | ||
let emitData = { | ||
'type': 'move_paddle', | ||
'game_id': gameSession.gameId, | ||
'player_id': gameSession.localPlayerId, | ||
'delta_z': deltaZ | ||
}; | ||
gameSession.sendMovement(emitData); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.