Add 3 files
Browse files- app.js +76 -0
- index.html +1 -19
- style.css +49 -17
app.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Use AlpineJS to create the game component
|
| 2 |
+
<div class="game" x-data="{ nomination: '' }" x-init="selectEnemy()">
|
| 3 |
+
<div class="prose">
|
| 4 |
+
<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>
|
| 5 |
+
</div>
|
| 6 |
+
<div class="game-canvas" x-bind:style="getCanvasStyle()" width="800" height="600">
|
| 7 |
+
<canvas id="game-canvas"></canvas>
|
| 8 |
+
</div>
|
| 9 |
+
<div class="options">
|
| 10 |
+
<button class="btn-primary" x-on:click="addEnemy()">Add Enemy</button>
|
| 11 |
+
<button class="btn-primary" x-on:click="updateEnemy()">Update Enemy</button>
|
| 12 |
+
<button class="btn-primary" x-on:click="removeEnemy()">Remove Enemy</button>
|
| 13 |
+
<button class="btn-primary" x-on:click="selectEnemy()">Select Enemy</button>
|
| 14 |
+
<button class="btn-primary" x-on:click="cloneCreature()">Clone Creature</button>
|
| 15 |
+
</div>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
// Initialize the game canvas with Three.js
|
| 19 |
+
const canvas = document.getElementById("game-canvas");
|
| 20 |
+
const renderer = new THREE.WebGLRenderer({ canvas });
|
| 21 |
+
|
| 22 |
+
// Set up the camera
|
| 23 |
+
const camera = new THREE.PerspectiveCamera(75, canvas.width / canvas.height, 0.1, 1000);
|
| 24 |
+
camera.position.z = 1000;
|
| 25 |
+
|
| 26 |
+
// Set up the controls
|
| 27 |
+
const controls = new THREE.OrbitControls(camera, canvas);
|
| 28 |
+
controls.target.set(0, 0, 0);
|
| 29 |
+
controls.update();
|
| 30 |
+
|
| 31 |
+
// Set up the scene
|
| 32 |
+
const scene = new THREE.Scene();
|
| 33 |
+
|
| 34 |
+
// Set up the render function
|
| 35 |
+
const render = function () {
|
| 36 |
+
requestAnimationFrame(render);
|
| 37 |
+
renderer.render(scene, camera);
|
| 38 |
+
};
|
| 39 |
+
requestAnimationFrame(render);
|
| 40 |
+
|
| 41 |
+
// Set up the enemies
|
| 42 |
+
const enemies = [];
|
| 43 |
+
|
| 44 |
+
// Add an enemy
|
| 45 |
+
function addEnemy() {
|
| 46 |
+
enemies.push(new THREE.Mesh(new THREE.SphereGeometry(10, 10, 32), new THREE.MeshBasicMaterial()));
|
| 47 |
+
enemies[enemies.length - 1].position.set(0, 0, 0);
|
| 48 |
+
enemies[enemies.length - 1].Friendly = false;
|
| 49 |
+
scene.add(enemies[enemies.length - 1]);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// Update an enemy's position
|
| 53 |
+
function updateEnemy() {
|
| 54 |
+
const enemySelection = enemies[selectEnemy()];
|
| 55 |
+
enemySelection.position.set(Math.random() * 1000 - 500, Math.random() * 1000 - 500, Math.random() * 1000 - 500);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// Remove an enemy
|
| 59 |
+
function removeEnemy() {
|
| 60 |
+
const enemySelection = enemies[selectEnemy()];
|
| 61 |
+
scene.remove(enemySelection);
|
| 62 |
+
enemies.splice(enemies.indexOf(enemySelection), 1);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// Select an enemy
|
| 66 |
+
function selectEnemy() {
|
| 67 |
+
x-on:change="enemies[selectEnemy()] !== '' ? enemySelection = enemies[selectEnemy()] : enemySelection = null"
|
| 68 |
+
return enemySelection;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Clone a creature
|
| 72 |
+
function cloneCreature() {
|
| 73 |
+
if (selectEnemy() !== null) {
|
| 74 |
+
scene.add(enemies[selectEnemy()]);
|
| 75 |
+
}
|
| 76 |
+
}
|
index.html
CHANGED
|
@@ -1,19 +1 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="utf-8" />
|
| 5 |
-
<meta name="viewport" content="width=device-width" />
|
| 6 |
-
<title>My static Space</title>
|
| 7 |
-
<link rel="stylesheet" href="style.css" />
|
| 8 |
-
</head>
|
| 9 |
-
<body>
|
| 10 |
-
<div class="card">
|
| 11 |
-
<h1>Welcome to your static Space!</h1>
|
| 12 |
-
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
|
| 13 |
-
<p>
|
| 14 |
-
Also don't forget to check the
|
| 15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
| 16 |
-
</p>
|
| 17 |
-
</div>
|
| 18 |
-
</body>
|
| 19 |
-
</html>
|
|
|
|
| 1 |
+
<html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Ninja Clone</title></head><body><h1>Ninja Clone</h1><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 id="game-canvas" width="800" height="600"></canvas></div><script type="module" src="app.js"></script></body></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
style.css
CHANGED
|
@@ -1,28 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
h1 {
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
-
.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url('https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css');
|
| 2 |
+
@import url('https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio');
|
| 3 |
+
|
| 4 |
body {
|
| 5 |
+
font-family: Arial, sans-serif;
|
| 6 |
+
height: 100vh;
|
| 7 |
+
margin: 0;
|
| 8 |
+
padding: 0;
|
| 9 |
+
display: flex;
|
| 10 |
+
justify-content: center;
|
| 11 |
+
align-items: center;
|
| 12 |
+
background-color: #f5f5f5;
|
| 13 |
+
color: #333;
|
| 14 |
}
|
| 15 |
|
| 16 |
h1 {
|
| 17 |
+
font-size: 48px;
|
| 18 |
+
text-align: center;
|
| 19 |
+
font-weight: bold;
|
| 20 |
+
margin-bottom: 20px;
|
| 21 |
}
|
| 22 |
|
| 23 |
+
.game {
|
| 24 |
+
position: relative;
|
| 25 |
+
display: flex;
|
| 26 |
+
flex-direction: column;
|
| 27 |
+
justify-content: center;
|
| 28 |
+
align-items: center;
|
| 29 |
+
padding: 20px;
|
| 30 |
+
margin: 20px;
|
| 31 |
+
width: 400px;
|
| 32 |
+
height: 400px;
|
| 33 |
+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
|
| 34 |
+
background-color: #fff;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
.game-canvas {
|
| 38 |
+
position: absolute;
|
| 39 |
+
top: 50%;
|
| 40 |
+
left: 50%;
|
| 41 |
+
transform: translate(-50%, -50%);
|
| 42 |
+
width: 400px;
|
| 43 |
+
height: 400px;
|
| 44 |
}
|
| 45 |
|
| 46 |
+
button {
|
| 47 |
+
padding: 10px 20px;
|
| 48 |
+
font-size: 16px;
|
| 49 |
+
cursor: pointer;
|
| 50 |
+
border: none;
|
| 51 |
+
background-color: #4CAF50;
|
| 52 |
+
color: #fff;
|
| 53 |
+
text-align: center;
|
| 54 |
+
outline: none;
|
| 55 |
+
transition: .4s ease-in-out;
|
| 56 |
}
|
| 57 |
+
|
| 58 |
+
button:hover {
|
| 59 |
+
background-color: #45a049;
|
| 60 |
+
}
|