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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Methcraft - WoW meets Meth</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
margin: 0;
|
| 10 |
+
overflow: hidden;
|
| 11 |
+
background-color: #1a1a1a;
|
| 12 |
+
font-family: 'Arial', sans-serif;
|
| 13 |
+
}
|
| 14 |
+
#gameCanvas {
|
| 15 |
+
display: block;
|
| 16 |
+
background-color: #333;
|
| 17 |
+
}
|
| 18 |
+
#ui {
|
| 19 |
+
position: absolute;
|
| 20 |
+
top: 10px;
|
| 21 |
+
left: 10px;
|
| 22 |
+
color: white;
|
| 23 |
+
font-size: 20px;
|
| 24 |
+
}
|
| 25 |
+
#startScreen {
|
| 26 |
+
position: absolute;
|
| 27 |
+
width: 100%;
|
| 28 |
+
height: 100%;
|
| 29 |
+
background-color: rgba(0,0,0,0.7);
|
| 30 |
+
display: flex;
|
| 31 |
+
flex-direction: column;
|
| 32 |
+
justify-content: center;
|
| 33 |
+
align-items: center;
|
| 34 |
+
color: white;
|
| 35 |
+
}
|
| 36 |
+
button {
|
| 37 |
+
padding: 15px 30px;
|
| 38 |
+
font-size: 20px;
|
| 39 |
+
background-color: #4a2b0f;
|
| 40 |
+
color: #f1c40f;
|
| 41 |
+
border: none;
|
| 42 |
+
border-radius: 5px;
|
| 43 |
+
cursor: pointer;
|
| 44 |
+
margin-top: 20px;
|
| 45 |
+
}
|
| 46 |
+
</style>
|
| 47 |
+
</head>
|
| 48 |
+
<body>
|
| 49 |
+
<canvas id="gameCanvas"></canvas>
|
| 50 |
+
<div id="ui">
|
| 51 |
+
<div>Health: <span id="health">100</span></div>
|
| 52 |
+
<div>Mana: <span id="mana">100</span></div>
|
| 53 |
+
<div>Score: <span id="score">0</span></div>
|
| 54 |
+
</div>
|
| 55 |
+
<div id="startScreen">
|
| 56 |
+
<h1>METHCRAFT</h1>
|
| 57 |
+
<p>A twisted mix of WoW and meth addicts</p>
|
| 58 |
+
<button id="startButton">Start Game</button>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
<script>
|
| 62 |
+
const canvas = document.getElementById('gameCanvas');
|
| 63 |
+
const ctx = canvas.getContext('2d');
|
| 64 |
+
const startScreen = document.getElementById('startScreen');
|
| 65 |
+
const startButton = document.getElementById('startButton');
|
| 66 |
+
|
| 67 |
+
// Set canvas size
|
| 68 |
+
canvas.width = window.innerWidth;
|
| 69 |
+
canvas.height = window.innerHeight;
|
| 70 |
+
|
| 71 |
+
// Game variables
|
| 72 |
+
let player = {
|
| 73 |
+
x: canvas.width/2,
|
| 74 |
+
y: canvas.height/2,
|
| 75 |
+
size: 30,
|
| 76 |
+
speed: 5,
|
| 77 |
+
health: 100,
|
| 78 |
+
mana: 100,
|
| 79 |
+
color: '#f1c40f'
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
let enemies = [];
|
| 83 |
+
let score = 0;
|
| 84 |
+
let gameRunning = false;
|
| 85 |
+
|
| 86 |
+
// Start game
|
| 87 |
+
startButton.addEventListener('click', () => {
|
| 88 |
+
startScreen.style.display = 'none';
|
| 89 |
+
gameRunning = true;
|
| 90 |
+
spawnEnemies();
|
| 91 |
+
gameLoop();
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
// Enemy spawning
|
| 95 |
+
function spawnEnemies() {
|
| 96 |
+
setInterval(() => {
|
| 97 |
+
const size = Math.random() * 30 + 20;
|
| 98 |
+
enemies.push({
|
| 99 |
+
x: Math.random() > 0.5 ? 0 : canvas.width,
|
| 100 |
+
y: Math.random() * canvas.height,
|
| 101 |
+
size: size,
|
| 102 |
+
speed: Math.random() * 3 + 1,
|
| 103 |
+
color: `hsl(${Math.random() * 360}, 70%, 50%)`,
|
| 104 |
+
health: size
|
| 105 |
+
});
|
| 106 |
+
}, 1000);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// Game loop
|
| 110 |
+
function gameLoop() {
|
| 111 |
+
if (!gameRunning) return;
|
| 112 |
+
|
| 113 |
+
// Clear canvas
|
| 114 |
+
ctx.fillStyle = '#333';
|
| 115 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 116 |
+
|
| 117 |
+
// Draw player
|
| 118 |
+
ctx.fillStyle = player.color;
|
| 119 |
+
ctx.beginPath();
|
| 120 |
+
ctx.arc(player.x, player.y, player.size, 0, Math.PI * 2);
|
| 121 |
+
ctx.fill();
|
| 122 |
+
|
| 123 |
+
// Draw enemies
|
| 124 |
+
enemies.forEach((enemy, index) => {
|
| 125 |
+
// Move enemy toward player
|
| 126 |
+
const angle = Math.atan2(player.y - enemy.y, player.x - enemy.x);
|
| 127 |
+
enemy.x += Math.cos(angle) * enemy.speed;
|
| 128 |
+
enemy.y += Math.sin(angle) * enemy.speed;
|
| 129 |
+
|
| 130 |
+
// Draw enemy
|
| 131 |
+
ctx.fillStyle = enemy.color;
|
| 132 |
+
ctx.beginPath();
|
| 133 |
+
ctx.arc(enemy.x, enemy.y, enemy.size, 0, Math.PI * 2);
|
| 134 |
+
ctx.fill();
|
| 135 |
+
|
| 136 |
+
// Collision detection
|
| 137 |
+
const dist = Math.hypot(player.x - enemy.x, player.y - enemy.y);
|
| 138 |
+
if (dist < player.size + enemy.size) {
|
| 139 |
+
player.health -= 5;
|
| 140 |
+
enemy.health -= 10;
|
| 141 |
+
document.getElementById('health').textContent = player.health;
|
| 142 |
+
|
| 143 |
+
if (enemy.health <= 0) {
|
| 144 |
+
enemies.splice(index, 1);
|
| 145 |
+
score += 10;
|
| 146 |
+
document.getElementById('score').textContent = score;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if (player.health <= 0) {
|
| 150 |
+
gameOver();
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
requestAnimationFrame(gameLoop);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
// Game over
|
| 159 |
+
function gameOver() {
|
| 160 |
+
gameRunning = false;
|
| 161 |
+
startScreen.style.display = 'flex';
|
| 162 |
+
startScreen.innerHTML = `
|
| 163 |
+
<h1>GAME OVER</h1>
|
| 164 |
+
<p>Your score: ${score}</p>
|
| 165 |
+
<button id="restartButton">Play Again</button>
|
| 166 |
+
`;
|
| 167 |
+
document.getElementById('restartButton').addEventListener('click', () => {
|
| 168 |
+
player.health = 100;
|
| 169 |
+
player.mana = 100;
|
| 170 |
+
score = 0;
|
| 171 |
+
enemies = [];
|
| 172 |
+
document.getElementById('health').textContent = player.health;
|
| 173 |
+
document.getElementById('mana').textContent = player.mana;
|
| 174 |
+
document.getElementById('score').textContent = score;
|
| 175 |
+
startScreen.style.display = 'none';
|
| 176 |
+
gameRunning = true;
|
| 177 |
+
spawnEnemies();
|
| 178 |
+
gameLoop();
|
| 179 |
+
});
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// Player movement
|
| 183 |
+
window.addEventListener('keydown', (e) => {
|
| 184 |
+
if (!gameRunning) return;
|
| 185 |
+
|
| 186 |
+
switch(e.key) {
|
| 187 |
+
case 'w': player.y -= player.speed; break;
|
| 188 |
+
case 's': player.y += player.speed; break;
|
| 189 |
+
case 'a': player.x -= player.speed; break;
|
| 190 |
+
case 'd': player.x += player.speed; break;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// Boundary check
|
| 194 |
+
player.x = Math.max(player.size, Math.min(canvas.width - player.size, player.x));
|
| 195 |
+
player.y = Math.max(player.size, Math.min(canvas.height - player.size, player.y));
|
| 196 |
+
});
|
| 197 |
+
</script>
|
| 198 |
+
</body>
|
| 199 |
+
</html>
|
index.html
CHANGED
|
@@ -8,12 +8,26 @@
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="card">
|
| 11 |
-
<h1>Welcome to
|
| 12 |
-
<p>
|
| 13 |
<p>
|
| 14 |
-
|
| 15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
| 16 |
</p>
|
| 17 |
</div>
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="card">
|
| 11 |
+
<h1>Welcome to Methcraft!</h1>
|
| 12 |
+
<p>A twisted 2D game that crosses World of Warcraft with meth addicts.</p>
|
| 13 |
<p>
|
| 14 |
+
<a href="game.html" class="play-button">Play Now</a>
|
|
|
|
| 15 |
</p>
|
| 16 |
</div>
|
| 17 |
+
<style>
|
| 18 |
+
.play-button {
|
| 19 |
+
display: inline-block;
|
| 20 |
+
padding: 10px 20px;
|
| 21 |
+
background-color: #4a2b0f;
|
| 22 |
+
color: #f1c40f;
|
| 23 |
+
text-decoration: none;
|
| 24 |
+
border-radius: 5px;
|
| 25 |
+
font-weight: bold;
|
| 26 |
+
margin-top: 20px;
|
| 27 |
+
}
|
| 28 |
+
.play-button:hover {
|
| 29 |
+
background-color: #5a3b1f;
|
| 30 |
+
}
|
| 31 |
+
</style>
|
| 32 |
+
</body>
|
| 33 |
</html>
|