|
|
|
<div class="game" x-data="{ nomination: '' }" x-init="selectEnemy()"> |
|
<div class="prose"> |
|
<p>You are a ninja and have to fight enemies to get to a data facility to clone a creature so every species is not extinct anymore. Good luck!</p> |
|
</div> |
|
<div class="game-canvas" x-bind:style="getCanvasStyle()" width="800" height="600"> |
|
<canvas id="game-canvas"></canvas> |
|
</div> |
|
<div class="options"> |
|
<button class="btn-primary" x-on:click="addEnemy()">Add Enemy</button> |
|
<button class="btn-primary" x-on:click="updateEnemy()">Update Enemy</button> |
|
<button class="btn-primary" x-on:click="removeEnemy()">Remove Enemy</button> |
|
<button class="btn-primary" x-on:click="selectEnemy()">Select Enemy</button> |
|
<button class="btn-primary" x-on:click="cloneCreature()">Clone Creature</button> |
|
</div> |
|
</div> |
|
|
|
|
|
const canvas = document.getElementById("game-canvas"); |
|
const renderer = new THREE.WebGLRenderer({ canvas }); |
|
|
|
|
|
const camera = new THREE.PerspectiveCamera(75, canvas.width / canvas.height, 0.1, 1000); |
|
camera.position.z = 1000; |
|
|
|
|
|
const controls = new THREE.OrbitControls(camera, canvas); |
|
controls.target.set(0, 0, 0); |
|
controls.update(); |
|
|
|
|
|
const scene = new THREE.Scene(); |
|
|
|
|
|
const render = function () { |
|
requestAnimationFrame(render); |
|
renderer.render(scene, camera); |
|
}; |
|
requestAnimationFrame(render); |
|
|
|
|
|
const enemies = []; |
|
|
|
|
|
function addEnemy() { |
|
enemies.push(new THREE.Mesh(new THREE.SphereGeometry(10, 10, 32), new THREE.MeshBasicMaterial())); |
|
enemies[enemies.length - 1].position.set(0, 0, 0); |
|
enemies[enemies.length - 1].Friendly = false; |
|
scene.add(enemies[enemies.length - 1]); |
|
} |
|
|
|
|
|
function updateEnemy() { |
|
const enemySelection = enemies[selectEnemy()]; |
|
enemySelection.position.set(Math.random() * 1000 - 500, Math.random() * 1000 - 500, Math.random() * 1000 - 500); |
|
} |
|
|
|
|
|
function removeEnemy() { |
|
const enemySelection = enemies[selectEnemy()]; |
|
scene.remove(enemySelection); |
|
enemies.splice(enemies.indexOf(enemySelection), 1); |
|
} |
|
|
|
|
|
function selectEnemy() { |
|
x-on:change="enemies[selectEnemy()] !== '' ? enemySelection = enemies[selectEnemy()] : enemySelection = null" |
|
return enemySelection; |
|
} |
|
|
|
|
|
function cloneCreature() { |
|
if (selectEnemy() !== null) { |
|
scene.add(enemies[selectEnemy()]); |
|
} |
|
} |