File size: 14,070 Bytes
28917a7 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mario-like Platform Game</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Custom styles for the game */
#game-container {
position: relative;
width: 800px;
height: 500px;
background: linear-gradient(to bottom, #87CEEB 50%, #228B22 50%);
overflow: hidden;
border: 4px solid #333;
border-radius: 8px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}
#player {
position: absolute;
width: 50px;
height: 50px;
background-color: #FF0000;
border-radius: 50%;
border: 2px solid #000;
z-index: 10;
transition: transform 0.1s;
}
.platform {
position: absolute;
background-color: #8B4513;
border: 2px solid #5D2906;
border-radius: 5px;
z-index: 5;
}
.coin {
position: absolute;
width: 20px;
height: 20px;
background-color: #FFD700;
border-radius: 50%;
border: 2px solid #DAA520;
z-index: 8;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotateY(0deg); }
100% { transform: rotateY(360deg); }
}
.cloud {
position: absolute;
background-color: white;
border-radius: 50%;
opacity: 0.8;
}
#score-display {
position: absolute;
top: 10px;
right: 10px;
background-color: rgba(255, 255, 255, 0.7);
padding: 5px 10px;
border-radius: 5px;
font-weight: bold;
z-index: 20;
}
#game-over {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: white;
font-size: 24px;
z-index: 30;
display: none;
}
</style>
</head>
<body class="bg-gray-100 flex flex-col items-center justify-center min-h-screen">
<h1 class="text-4xl font-bold mb-4 text-red-600">Super Adventure Game</h1>
<div id="game-container" class="relative">
<div id="score-display">Score: <span id="score">0</span></div>
<div id="player"></div>
<div id="game-over">
<h2 class="text-3xl font-bold mb-4">Game Over!</h2>
<p class="mb-6">Final Score: <span id="final-score">0</span></p>
<button id="restart-btn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded">
Play Again
</button>
</div>
</div>
<div class="mt-6 flex space-x-4">
<button id="left-btn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded">
← Left
</button>
<button id="right-btn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded">
Right →
</button>
<button id="jump-btn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded">
Jump ↑
</button>
</div>
<p class="mt-4 text-gray-600">Use buttons or arrow keys to move and jump</p>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Game elements
const gameContainer = document.getElementById('game-container');
const player = document.getElementById('player');
const scoreDisplay = document.getElementById('score');
const finalScoreDisplay = document.getElementById('final-score');
const gameOverScreen = document.getElementById('game-over');
const restartBtn = document.getElementById('restart-btn');
// Control buttons
const leftBtn = document.getElementById('left-btn');
const rightBtn = document.getElementById('right-btn');
const jumpBtn = document.getElementById('jump-btn');
// Game state
let score = 0;
let isJumping = false;
let isGameOver = false;
let playerX = 100;
let playerY = 400;
let velocityY = 0;
let gravity = 0.5;
let moveSpeed = 5;
let jumpForce = -12;
let platforms = [];
let coins = [];
let clouds = [];
// Initialize game
initGame();
function initGame() {
// Reset game state
score = 0;
isJumping = false;
isGameOver = false;
playerX = 100;
playerY = 400;
velocityY = 0;
scoreDisplay.textContent = score;
gameOverScreen.style.display = 'none';
// Clear existing elements
document.querySelectorAll('.platform').forEach(el => el.remove());
document.querySelectorAll('.coin').forEach(el => el.remove());
document.querySelectorAll('.cloud').forEach(el => el.remove());
platforms = [];
coins = [];
clouds = [];
// Create ground platform
createPlatform(0, 450, 800, 50);
// Create some platforms
createPlatform(100, 350, 150, 20);
createPlatform(300, 300, 150, 20);
createPlatform(500, 250, 150, 20);
createPlatform(200, 200, 150, 20);
createPlatform(400, 150, 150, 20);
createPlatform(600, 100, 150, 20);
// Create some coins
createCoin(150, 320);
createCoin(350, 270);
createCoin(550, 220);
createCoin(250, 170);
createCoin(450, 120);
createCoin(650, 70);
// Create some clouds
createCloud(100, 50, 60, 30);
createCloud(300, 30, 80, 40);
createCloud(500, 60, 70, 35);
createCloud(700, 40, 90, 45);
// Position player
updatePlayerPosition();
// Start game loop
requestAnimationFrame(gameLoop);
}
function createPlatform(x, y, width, height) {
const platform = document.createElement('div');
platform.className = 'platform';
platform.style.left = `${x}px`;
platform.style.top = `${y}px`;
platform.style.width = `${width}px`;
platform.style.height = `${height}px`;
gameContainer.appendChild(platform);
platforms.push({
x, y, width, height, element: platform
});
}
function createCoin(x, y) {
const coin = document.createElement('div');
coin.className = 'coin';
coin.style.left = `${x}px`;
coin.style.top = `${y}px`;
gameContainer.appendChild(coin);
coins.push({
x, y, collected: false, element: coin
});
}
function createCloud(x, y, width, height) {
const cloud = document.createElement('div');
cloud.className = 'cloud';
cloud.style.left = `${x}px`;
cloud.style.top = `${y}px`;
cloud.style.width = `${width}px`;
cloud.style.height = `${height}px`;
gameContainer.appendChild(cloud);
clouds.push({
x, y, width, height, element: cloud
});
}
function updatePlayerPosition() {
player.style.left = `${playerX}px`;
player.style.top = `${playerY}px`;
}
function checkCollision() {
// Check if player is on a platform
let onPlatform = false;
for (const platform of platforms) {
if (
playerX + 50 > platform.x &&
playerX < platform.x + platform.width &&
playerY + 50 >= platform.y &&
playerY + 50 <= platform.y + 20 && // Only check top part of platform
velocityY >= 0
) {
onPlatform = true;
playerY = platform.y - 50;
velocityY = 0;
isJumping = false;
}
}
// Apply gravity if not on platform
if (!onPlatform) {
velocityY += gravity;
isJumping = true;
}
// Check coin collection
for (const coin of coins) {
if (!coin.collected &&
playerX + 50 > coin.x &&
playerX < coin.x + 20 &&
playerY + 50 > coin.y &&
playerY < coin.y + 20) {
coin.collected = true;
coin.element.style.display = 'none';
score += 10;
scoreDisplay.textContent = score;
}
}
// Check if player fell off the screen
if (playerY > gameContainer.clientHeight) {
gameOver();
}
}
function gameLoop() {
if (isGameOver) return;
// Apply velocity
playerY += velocityY;
// Update player position
updatePlayerPosition();
// Check collisions
checkCollision();
// Move clouds for parallax effect
for (const cloud of clouds) {
cloud.x -= 0.2;
if (cloud.x + cloud.width < 0) {
cloud.x = gameContainer.clientWidth;
}
cloud.element.style.left = `${cloud.x}px`;
}
requestAnimationFrame(gameLoop);
}
function gameOver() {
isGameOver = true;
finalScoreDisplay.textContent = score;
gameOverScreen.style.display = 'flex';
}
// Event listeners for buttons
leftBtn.addEventListener('mousedown', () => {
if (!isGameOver) playerX -= moveSpeed;
if (playerX < 0) playerX = 0;
updatePlayerPosition();
});
rightBtn.addEventListener('mousedown', () => {
if (!isGameOver) playerX += moveSpeed;
if (playerX > gameContainer.clientWidth - 50) playerX = gameContainer.clientWidth - 50;
updatePlayerPosition();
});
jumpBtn.addEventListener('click', () => {
if (!isJumping && !isGameOver) {
velocityY = jumpForce;
isJumping = true;
}
});
// Keyboard controls
document.addEventListener('keydown', (e) => {
if (isGameOver) return;
switch (e.key) {
case 'ArrowLeft':
playerX -= moveSpeed;
if (playerX < 0) playerX = 0;
break;
case 'ArrowRight':
playerX += moveSpeed;
if (playerX > gameContainer.clientWidth - 50) playerX = gameContainer.clientWidth - 50;
break;
case 'ArrowUp':
case ' ':
if (!isJumping) {
velocityY = jumpForce;
isJumping = true;
}
break;
}
updatePlayerPosition();
});
// Restart game
restartBtn.addEventListener('click', initGame);
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Dhdb/ball-demo" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |