Spaces:
Running
Running
File size: 11,993 Bytes
4285d52 8ca76ff 4285d52 20221a5 4285d52 ae28d94 4285d52 ae28d94 4285d52 20221a5 4285d52 28aecbf 4285d52 20221a5 4285d52 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
<!DOCTYPE html>
<html>
<head>
<title>Stickman Javelin Battle</title>
<style>
body {
margin: 0;
overflow: hidden;
background: linear-gradient(to bottom, #87CEEB, #E0F6FF);
font-family: Arial, sans-serif;
}
#gameCanvas {
border: 2px solid #333;
cursor: crosshair;
}
#menu {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
background: rgba(255, 255, 255, 0.9);
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
.btn {
padding: 10px 20px;
font-size: 18px;
background: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
.health-bar {
position: absolute;
width: 200px;
height: 20px;
background: #333;
border-radius: 10px;
overflow: hidden;
}
.health-bar-fill {
height: 100%;
background: linear-gradient(90deg, #ff0000, #ff4444);
transition: width 0.3s ease;
}
#player1Health {
top: 20px;
left: 20px;
}
#player2Health {
top: 20px;
right: 20px;
}
.player-label {
position: absolute;
color: white;
font-size: 14px;
font-weight: bold;
text-shadow: 1px 1px 2px black;
}
#powerIndicator {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
width: 200px;
height: 10px;
background: rgba(0, 0, 0, 0.5);
border-radius: 5px;
}
#powerBar {
width: 0%;
height: 100%;
background: #ffff00;
border-radius: 5px;
transition: width 0.1s ease;
}
#turnIndicator {
position: absolute;
top: 50px;
left: 50%;
transform: translateX(-50%);
color: white;
font-size: 20px;
text-shadow: 1px 1px 2px black;
}
</style>
</head>
<body>
<canvas id="gameCanvas"></canvas>
<div id="menu">
<h1>Stickman Javelin Battle</h1>
<button class="btn" onclick="startGame()">Start Game</button>
</div>
<div id="player1Health" class="health-bar">
<div id="player1HealthFill" class="health-bar-fill" style="width: 100%"></div>
<span class="player-label">Player 1: 100</span>
</div>
<div id="player2Health" class="health-bar">
<div id="player2HealthFill" class="health-bar-fill" style="width: 100%"></div>
<span class="player-label">Player 2: 100</span>
</div>
<div id="turnIndicator"></div>
<div id="powerIndicator">
<div id="powerBar"></div>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const menu = document.getElementById('menu');
const turnIndicator = document.getElementById('turnIndicator');
const player1HealthFill = document.getElementById('player1HealthFill');
const player2HealthFill = document.getElementById('player2HealthFill');
const powerBar = document.getElementById('powerBar');
let gameActive = false;
let currentPlayer = 1;
let isMouseDown = false;
let powerLevel = 0;
let aimAngle = 0;
const player1 = {
x: 100,
y: 575,
height: 60,
width: 20,
color: '#FF6B6B',
health: 100
};
const player2 = {
x: 700,
y: 575,
height: 60,
width: 20,
color: '#4ECDC4',
health: 100
};
const javelin = {
x: 0,
y: 0,
angle: 0,
power: 0,
throwing: false,
velocity: { x: 0, y: 0 }
};
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
function startGame() {
menu.style.display = 'none';
gameActive = true;
currentPlayer = 1;
player1.health = 100;
player2.health = 100;
updateHealthBars();
updateTurnIndicator();
gameLoop();
}
function updateTurnIndicator() {
turnIndicator.textContent = `Player ${currentPlayer}'s Turn`;
}
function updateHealthBars() {
player1HealthFill.style.width = `${player1.health}%`;
player2HealthFill.style.width = `${player2.health}%`;
document.querySelector('#player1Health .player-label').textContent = `Player 1: ${player1.health}`;
document.querySelector('#player2Health .player-label').textContent = `Player 2: ${player2.health}`;
}
function drawAimLine(x, y, angle, power) {
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + Math.cos(angle) * power * 10, y + Math.sin(angle) * power * 10);
ctx.strokeStyle = '#ff0000';
ctx.setLineDash([5, 5]);
ctx.stroke();
ctx.setLineDash([]);
}
function drawStickman(x, y, color) {
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.beginPath();
// Head (hitbox area)
ctx.arc(x + 10, y - 40, 10, 0, Math.PI * 2);
// Body (hitbox area)
ctx.moveTo(x + 10, y - 30);
ctx.lineTo(x + 10, y);
// Arms (hitbox areas)
ctx.moveTo(x + 10, y - 20);
ctx.lineTo(x - 5, y - 10);
ctx.moveTo(x + 10, y - 20);
ctx.lineTo(x + 25, y - 10);
// Legs (hitbox areas)
ctx.moveTo(x + 10, y);
ctx.lineTo(x, y + 20);
ctx.moveTo(x + 10, y);
ctx.lineTo(x + 20, y + 20);
ctx.stroke();
}
function drawJavelin(x, y, angle) {
ctx.save();
ctx.translate(x, y);
ctx.rotate(angle);
ctx.fillStyle = '#8B4513';
ctx.fillRect(-25, -2, 50, 4);
ctx.restore();
}
function handleMouseDown(e) {
if (!javelin.throwing && gameActive) {
isMouseDown = true;
powerLevel = 0;
}
}
function handleMouseMove(e) {
if (isMouseDown) {
const rect = canvas.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
const playerX = currentPlayer === 1 ? player1.x : player2.x;
const playerY = currentPlayer === 1 ? player1.y - 20 : player2.y - 20;
const dx = mouseX - playerX;
const dy = mouseY - playerY;
aimAngle = Math.atan2(dy, dx);
}
}
function handleMouseUp(e) {
if (isMouseDown && !javelin.throwing && gameActive) {
const playerX = currentPlayer === 1 ? player1.x : player2.x;
const playerY = currentPlayer === 1 ? player1.y - 20 : player2.y - 20;
javelin.x = playerX;
javelin.y = playerY;
javelin.angle = aimAngle;
javelin.power = powerLevel;
javelin.velocity.x = Math.cos(aimAngle) * powerLevel;
javelin.velocity.y = Math.sin(aimAngle) * powerLevel;
javelin.throwing = true;
}
isMouseDown = false;
powerLevel = 0;
powerBar.style.width = '0%';
}
function checkHit(x, y, targetX, targetY) {
const headHitbox = { x: targetX + 10, y: targetY - 40, radius: 10 };
const bodyHitbox = {
x: targetX + 10,
y: targetY - 15,
width: 4,
height: 30
};
// Check head hit (20 damage)
const dx = x - headHitbox.x;
const dy = y - headHitbox.y;
if (Math.sqrt(dx * dx + dy * dy) < headHitbox.radius) {
return 20;
}
// Check body hit (10 damage)
if (x >= targetX && x <= targetX + 20 &&
y >= targetY - 30 && y <= targetY + 20) {
return 10;
}
return 0;
}
function updateJavelin() {
if (javelin.throwing) {
javelin.x += javelin.velocity.x;
javelin.y += javelin.velocity.y;
javelin.velocity.y += 0.5; // Gravity
const target = currentPlayer === 1 ? player2 : player1;
const damage = checkHit(javelin.x, javelin.y, target.x, target.y);
if (damage > 0) {
target.health = Math.max(0, target.health - damage);
updateHealthBars();
resetJavelin();
checkGameOver();
}
// Check if javelin is out of bounds
if (javelin.x < 0 || javelin.x > canvas.width ||
javelin.y > canvas.height) {
resetJavelin();
}
}
}
function resetJavelin() {
javelin.throwing = false;
currentPlayer = currentPlayer === 1 ? 2 : 1;
updateTurnIndicator();
}
function checkGameOver() {
if (player1.health <= 0 || player2.health <= 0) {
endGame();
}
}
function endGame() {
gameActive = false;
menu.style.display = 'block';
const winner = player1.health <= 0 ? 2 : 1;
menu.innerHTML = `
<h1>Game Over!</h1>
<h2>Player ${winner} Wins!</h2>
<button class="btn" onclick="startGame()">Play Again</button>
`;
}
function gameLoop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw ground
ctx.fillStyle = '#90EE90';
ctx.fillRect(0, canvas.height - 50, canvas.width, 50);
drawStickman(player1.x, player1.y, player1.color);
drawStickman(player2.x, player2.y, player2.color);
if (isMouseDown && !javelin.throwing) {
const playerX = currentPlayer === 1 ? player1.x : player2.x;
const playerY = currentPlayer === 1 ? player1.y - 20 : player2.y - 20;
powerLevel = Math.min(powerLevel + 0.5, 20);
powerBar.style.width = `${(powerLevel / 20) * 100}%`;
drawAimLine(playerX, playerY, aimAngle, powerLevel);
}
if (javelin.throwing) {
drawJavelin(javelin.x, javelin.y, javelin.angle);
updateJavelin();
}
if (gameActive) {
requestAnimationFrame(gameLoop);
}
}
window.addEventListener('resize', resizeCanvas);
canvas.addEventListener('mousedown', handleMouseDown);
canvas.addEventListener('mousemove', handleMouseMove);
canvas.addEventListener('mouseup', handleMouseUp);
resizeCanvas();
</script>
</body>
</html> |