Spaces:
Sleeping
Sleeping
Delete templates
Browse files- templates/snake_game.html +0 -251
templates/snake_game.html
DELETED
|
@@ -1,251 +0,0 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html>
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<title>Myco's Forest</title>
|
| 6 |
-
|
| 7 |
-
<style>
|
| 8 |
-
body {
|
| 9 |
-
margin: 0;
|
| 10 |
-
background: radial-gradient(circle at top, #0f2a14, #050a05);
|
| 11 |
-
font-family: Arial, sans-serif;
|
| 12 |
-
overflow: hidden;
|
| 13 |
-
color: #d9f99d;
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
/* Title */
|
| 17 |
-
#title {
|
| 18 |
-
text-align: center;
|
| 19 |
-
font-size: 38px;
|
| 20 |
-
margin-top: 12px;
|
| 21 |
-
color: #a3e635;
|
| 22 |
-
text-shadow: 0 0 20px #84cc16;
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
/* Canvas glow */
|
| 26 |
-
canvas {
|
| 27 |
-
display: block;
|
| 28 |
-
margin: 10px auto;
|
| 29 |
-
background: #06130a;
|
| 30 |
-
border-radius: 12px;
|
| 31 |
-
border: 2px solid #4d7c0f;
|
| 32 |
-
box-shadow: 0 0 40px rgba(163,230,53,0.2);
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
/* HUD */
|
| 36 |
-
#hud {
|
| 37 |
-
text-align: center;
|
| 38 |
-
font-size: 14px;
|
| 39 |
-
opacity: 0.9;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/* Overlay screens */
|
| 43 |
-
.screen {
|
| 44 |
-
position: absolute;
|
| 45 |
-
top:0; left:0;
|
| 46 |
-
width:100%;
|
| 47 |
-
height:100%;
|
| 48 |
-
display:flex;
|
| 49 |
-
align-items:center;
|
| 50 |
-
justify-content:center;
|
| 51 |
-
flex-direction:column;
|
| 52 |
-
background: rgba(0,0,0,0.65);
|
| 53 |
-
backdrop-filter: blur(6px);
|
| 54 |
-
display:none;
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
.screen h1 {
|
| 58 |
-
font-size: 48px;
|
| 59 |
-
color: #a3e635;
|
| 60 |
-
text-shadow: 0 0 30px #84cc16;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
button {
|
| 64 |
-
padding: 10px 18px;
|
| 65 |
-
border: none;
|
| 66 |
-
background: #4d7c0f;
|
| 67 |
-
color: white;
|
| 68 |
-
border-radius: 8px;
|
| 69 |
-
cursor: pointer;
|
| 70 |
-
margin-top: 10px;
|
| 71 |
-
}
|
| 72 |
-
button:hover {
|
| 73 |
-
transform: scale(1.05);
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
/* Floating spores background */
|
| 77 |
-
.spore {
|
| 78 |
-
position: absolute;
|
| 79 |
-
width: 6px;
|
| 80 |
-
height: 6px;
|
| 81 |
-
background: #a3e635;
|
| 82 |
-
border-radius: 50%;
|
| 83 |
-
opacity: 0.4;
|
| 84 |
-
animation: float 10s linear infinite;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
@keyframes float {
|
| 88 |
-
from { transform: translateY(100vh); }
|
| 89 |
-
to { transform: translateY(-10vh); }
|
| 90 |
-
}
|
| 91 |
-
</style>
|
| 92 |
-
</head>
|
| 93 |
-
|
| 94 |
-
<body>
|
| 95 |
-
|
| 96 |
-
<div id="title">🍄 Myco’s Forest</div>
|
| 97 |
-
|
| 98 |
-
<canvas id="game" width="400" height="400"></canvas>
|
| 99 |
-
|
| 100 |
-
<div id="hud">Score: <span id="score">0</span></div>
|
| 101 |
-
|
| 102 |
-
<!-- START SCREEN -->
|
| 103 |
-
<div class="screen" id="startScreen" style="display:flex;">
|
| 104 |
-
<h1>Myco Awakens</h1>
|
| 105 |
-
<p>Guide the forest spirit through glowing mushrooms</p>
|
| 106 |
-
<button onclick="startGame()">Enter Forest</button>
|
| 107 |
-
</div>
|
| 108 |
-
|
| 109 |
-
<!-- WIN SCREEN -->
|
| 110 |
-
<div class="screen" id="winScreen">
|
| 111 |
-
<h1>You Transcended 🌿</h1>
|
| 112 |
-
<p>Myco evolved with the forest</p>
|
| 113 |
-
<button onclick="restart()">Play Again</button>
|
| 114 |
-
</div>
|
| 115 |
-
|
| 116 |
-
<!-- GAME OVER -->
|
| 117 |
-
<div class="screen" id="gameOver">
|
| 118 |
-
<h1>Lost in the Dark 🌑</h1>
|
| 119 |
-
<p>Score: <span id="finalScore"></span></p>
|
| 120 |
-
<button onclick="restart()">Try Again</button>
|
| 121 |
-
</div>
|
| 122 |
-
|
| 123 |
-
<script>
|
| 124 |
-
const canvas = document.getElementById("game");
|
| 125 |
-
const ctx = canvas.getContext("2d");
|
| 126 |
-
|
| 127 |
-
const GRID = 20;
|
| 128 |
-
const SIZE = 400;
|
| 129 |
-
|
| 130 |
-
let snake, dir, food, score;
|
| 131 |
-
let tick = 120;
|
| 132 |
-
let running = false;
|
| 133 |
-
|
| 134 |
-
function reset() {
|
| 135 |
-
snake = [{x:200,y:200}];
|
| 136 |
-
dir = {x:1,y:0};
|
| 137 |
-
food = spawnFood();
|
| 138 |
-
score = 0;
|
| 139 |
-
updateHUD();
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
function spawnFood() {
|
| 143 |
-
return {
|
| 144 |
-
x: Math.floor(Math.random()*20)*20,
|
| 145 |
-
y: Math.floor(Math.random()*20)*20
|
| 146 |
-
};
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
function updateHUD(){
|
| 150 |
-
document.getElementById("score").innerText = score;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
function draw() {
|
| 154 |
-
ctx.clearRect(0,0,SIZE,SIZE);
|
| 155 |
-
|
| 156 |
-
// glow background grid
|
| 157 |
-
ctx.fillStyle = "#071a0c";
|
| 158 |
-
ctx.fillRect(0,0,SIZE,SIZE);
|
| 159 |
-
|
| 160 |
-
// mushroom
|
| 161 |
-
ctx.fillStyle = "#ef4444";
|
| 162 |
-
ctx.beginPath();
|
| 163 |
-
ctx.arc(food.x+10,food.y+10,8,0,Math.PI*2);
|
| 164 |
-
ctx.fill();
|
| 165 |
-
|
| 166 |
-
// snake glow
|
| 167 |
-
snake.forEach((s,i)=>{
|
| 168 |
-
ctx.fillStyle = i===0 ? "#a3e635" : "#4d7c0f";
|
| 169 |
-
ctx.shadowColor = "#84cc16";
|
| 170 |
-
ctx.shadowBlur = 10;
|
| 171 |
-
ctx.fillRect(s.x+2,s.y+2,16,16);
|
| 172 |
-
});
|
| 173 |
-
|
| 174 |
-
ctx.shadowBlur = 0;
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
function step() {
|
| 178 |
-
let head = {
|
| 179 |
-
x: snake[0].x + dir.x*GRID,
|
| 180 |
-
y: snake[0].y + dir.y*GRID
|
| 181 |
-
};
|
| 182 |
-
|
| 183 |
-
if(head.x<0||head.y<0||head.x>=SIZE||head.y>=SIZE){
|
| 184 |
-
end(false);
|
| 185 |
-
return;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
if(snake.some(s=>s.x===head.x&&s.y===head.y)){
|
| 189 |
-
end(false);
|
| 190 |
-
return;
|
| 191 |
-
}
|
| 192 |
-
|
| 193 |
-
snake.unshift(head);
|
| 194 |
-
|
| 195 |
-
if(head.x===food.x&&head.y===food.y){
|
| 196 |
-
score++;
|
| 197 |
-
food = spawnFood();
|
| 198 |
-
updateHUD();
|
| 199 |
-
|
| 200 |
-
// WIN CONDITION (hackathon polish moment)
|
| 201 |
-
if(score >= 10){
|
| 202 |
-
end(true);
|
| 203 |
-
return;
|
| 204 |
-
}
|
| 205 |
-
} else {
|
| 206 |
-
snake.pop();
|
| 207 |
-
}
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
function loop(){
|
| 211 |
-
if(!running) return;
|
| 212 |
-
|
| 213 |
-
setTimeout(()=>{
|
| 214 |
-
step();
|
| 215 |
-
draw();
|
| 216 |
-
requestAnimationFrame(loop);
|
| 217 |
-
}, tick);
|
| 218 |
-
}
|
| 219 |
-
|
| 220 |
-
function startGame(){
|
| 221 |
-
document.getElementById("startScreen").style.display="none";
|
| 222 |
-
reset();
|
| 223 |
-
running = true;
|
| 224 |
-
loop();
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
function end(win){
|
| 228 |
-
running = false;
|
| 229 |
-
|
| 230 |
-
if(win){
|
| 231 |
-
document.getElementById("winScreen").style.display="flex";
|
| 232 |
-
} else {
|
| 233 |
-
document.getElementById("finalScore").innerText = score;
|
| 234 |
-
document.getElementById("gameOver").style.display="flex";
|
| 235 |
-
}
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
function restart(){
|
| 239 |
-
location.reload();
|
| 240 |
-
}
|
| 241 |
-
|
| 242 |
-
document.addEventListener("keydown", e=>{
|
| 243 |
-
if(e.key==="ArrowUp"&&dir.y===0)dir={x:0,y:-1};
|
| 244 |
-
if(e.key==="ArrowDown"&&dir.y===0)dir={x:0,y:1};
|
| 245 |
-
if(e.key==="ArrowLeft"&&dir.x===0)dir={x:-1,y:0};
|
| 246 |
-
if(e.key==="ArrowRight"&&dir.x===0)dir={x:1,y:0};
|
| 247 |
-
});
|
| 248 |
-
</script>
|
| 249 |
-
|
| 250 |
-
</body>
|
| 251 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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