Spaces:
Running
Running
File size: 17,639 Bytes
dfafd03 | 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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dubai Flight Simulator</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
margin: 0;
overflow: hidden;
font-family: Arial, sans-serif;
}
#gameCanvas {
background: linear-gradient(to bottom, #87CEEB, #1E90FF);
display: block;
}
#startScreen, #gameOverScreen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.7);
color: white;
}
#gameOverScreen {
display: none;
}
.building {
position: absolute;
background: linear-gradient(to bottom, #FFD700, #FFA500);
border: 2px solid #333;
}
.plane {
position: absolute;
width: 50px;
height: 50px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23ffffff" d="M22,16.21V14l-8-5V3.5A1.5,1.5,0,0,0,12.5,2h0A1.5,1.5,0,0,0,11,3.5V9l-8,5v2.21L11,14.6V19l-2,1.5V22l3.5-1,3.5,1V20.5L14,19v-4.4Z"/></svg>');
background-size: contain;
transform: rotate(90deg);
}
.star {
position: absolute;
width: 20px;
height: 20px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23FFD700" d="M12,17.27L18.18,21l-1.64-7.03L22,9.24l-7.19-.61L12,2,9.19,8.63,2,9.24l5.46,4.73L5.82,21Z"/></svg>');
background-size: contain;
}
.cloud {
position: absolute;
background-color: white;
border-radius: 50%;
}
.burj-khalifa {
background: linear-gradient(to bottom, silver, #555);
border-left: 2px solid #333;
border-right: 2px solid #333;
}
</style>
</head>
<body class="bg-gray-900">
<canvas id="gameCanvas"></canvas>
<div id="startScreen" class="text-center p-4">
<h1 class="text-4xl font-bold mb-6 text-yellow-400">Dubai Flight Simulator</h1>
<p class="text-xl mb-8">Fly your plane between Dubai's skyscrapers and collect stars!</p>
<button id="startButton" class="bg-yellow-500 hover:bg-yellow-600 text-white font-bold py-3 px-6 rounded-full text-xl transition duration-300 transform hover:scale-105">
Start Flight
</button>
<div class="mt-8 text-sm">
<p>Controls: Use Arrow Keys or WASD to move</p>
<p>Avoid buildings and collect stars!</p>
</div>
</div>
<div id="gameOverScreen" class="text-center p-4">
<h1 class="text-4xl font-bold mb-4 text-red-500">Game Over!</h1>
<p class="text-2xl mb-2">Your Score: <span id="finalScore" class="text-yellow-400">0</span></p>
<p class="text-xl mb-8">Thanks for flying over Dubai!</p>
<button id="restartButton" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-3 px-6 rounded-full text-xl transition duration-300 transform hover:scale-105">
Fly Again
</button>
</div>
<div id="scoreDisplay" class="absolute top-4 left-4 bg-black bg-opacity-50 text-white p-3 rounded-lg hidden">
<div class="flex items-center">
<span class="text-yellow-400 mr-2">★</span>
<span id="score">0</span>
</div>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const startScreen = document.getElementById('startScreen');
const gameOverScreen = document.getElementById('gameOverScreen');
const startButton = document.getElementById('startButton');
const restartButton = document.getElementById('restartButton');
const scoreDisplay = document.getElementById('scoreDisplay');
const scoreElement = document.getElementById('score');
const finalScoreElement = document.getElementById('finalScore');
// Set canvas size
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Game variables
let plane = {
x: 100,
y: canvas.height / 2,
width: 50,
height: 50,
speed: 5
};
let buildings = [];
let stars = [];
let clouds = [];
let score = 0;
let gameSpeed = 2;
let gameRunning = false;
let animationId;
let keys = {};
// Event listeners
startButton.addEventListener('click', startGame);
restartButton.addEventListener('click', startGame);
window.addEventListener('keydown', (e) => {
keys[e.key] = true;
// Space to start game from start screen
if (e.key === ' ' && !gameRunning && startScreen.style.display !== 'none') {
startGame();
}
});
window.addEventListener('keyup', (e) => {
keys[e.key] = false;
});
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
if (gameRunning) {
plane.y = Math.min(plane.y, canvas.height - plane.height);
}
});
// Game functions
function startGame() {
startScreen.style.display = 'none';
gameOverScreen.style.display = 'none';
scoreDisplay.classList.remove('hidden');
// Reset game state
plane = {
x: 100,
y: canvas.height / 2,
width: 50,
height: 50,
speed: 5
};
buildings = [];
stars = [];
clouds = [];
score = 0;
scoreElement.textContent = score;
gameSpeed = 2;
gameRunning = true;
// Start game loop
gameLoop();
}
function gameLoop() {
if (!gameRunning) return;
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw sky gradient
const skyGradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
skyGradient.addColorStop(0, '#87CEEB');
skyGradient.addColorStop(1, '#1E90FF');
ctx.fillStyle = skyGradient;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw sun
ctx.beginPath();
ctx.arc(canvas.width - 100, 100, 60, 0, Math.PI * 2);
ctx.fillStyle = '#FFD700';
ctx.fill();
// Update and draw clouds
updateClouds();
drawClouds();
// Update and draw buildings
updateBuildings();
drawBuildings();
// Update and draw stars
updateStars();
drawStars();
// Update and draw plane
updatePlane();
drawPlane();
// Check for collisions
checkCollisions();
// Increase difficulty over time
gameSpeed += 0.001;
// Continue game loop
animationId = requestAnimationFrame(gameLoop);
}
function updatePlane() {
// Move plane based on key presses
if (keys['ArrowUp'] || keys['w']) {
plane.y -= plane.speed;
}
if (keys['ArrowDown'] || keys['s']) {
plane.y += plane.speed;
}
if (keys['ArrowLeft'] || keys['a']) {
plane.x -= plane.speed;
}
if (keys['ArrowRight'] || keys['d']) {
plane.x += plane.speed;
}
// Keep plane within canvas bounds
plane.x = Math.max(0, Math.min(plane.x, canvas.width - plane.width));
plane.y = Math.max(0, Math.min(plane.y, canvas.height - plane.height));
}
function drawPlane() {
ctx.save();
ctx.translate(plane.x + plane.width / 2, plane.y + plane.height / 2);
ctx.rotate(Math.PI / 2);
ctx.drawImage(
createPlaneImage(),
-plane.width / 2,
-plane.height / 2,
plane.width,
plane.height
);
ctx.restore();
}
function createPlaneImage() {
const img = new Image();
img.src = 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23ffffff" d="M22,16.21V14l-8-5V3.5A1.5,1.5,0,0,0,12.5,2h0A1.5,1.5,0,0,0,11,3.5V9l-8,5v2.21L11,14.6V19l-2,1.5V22l3.5-1,3.5,1V20.5L14,19v-4.4Z"/></svg>';
return img;
}
function updateBuildings() {
// Add new buildings
if (Math.random() < 0.02) {
const isBurjKhalifa = Math.random() < 0.1; // 10% chance for Burj Khalifa
const width = isBurjKhalifa ? 30 : 50 + Math.random() * 70;
const height = isBurjKhalifa ? 300 + Math.random() * 100 : 100 + Math.random() * 200;
buildings.push({
x: canvas.width,
y: canvas.height - height,
width: width,
height: height,
speed: gameSpeed,
isBurjKhalifa: isBurjKhalifa
});
}
// Move buildings
for (let i = buildings.length - 1; i >= 0; i--) {
buildings[i].x -= buildings[i].speed;
// Remove buildings that are off screen
if (buildings[i].x + buildings[i].width < 0) {
buildings.splice(i, 1);
}
}
}
function drawBuildings() {
buildings.forEach(building => {
if (building.isBurjKhalifa) {
// Draw Burj Khalifa
ctx.fillStyle = '#555';
ctx.fillRect(building.x, building.y, building.width, building.height);
// Add windows
ctx.fillStyle = '#87CEEB';
const windowWidth = 4;
const windowHeight = 8;
const windowSpacing = 10;
for (let y = building.y + 10; y < building.y + building.height - 10; y += windowSpacing) {
for (let x = building.x + 5; x < building.x + building.width - 5; x += windowSpacing) {
if (Math.random() > 0.3) { // 70% chance to draw a window
ctx.fillRect(x, y, windowWidth, windowHeight);
}
}
}
// Add spire
ctx.beginPath();
ctx.moveTo(building.x + building.width / 2, building.y);
ctx.lineTo(building.x + building.width / 2 - 10, building.y - 50);
ctx.lineTo(building.x + building.width / 2 + 10, building.y - 50);
ctx.closePath();
ctx.fillStyle = '#333';
ctx.fill();
} else {
// Draw regular building
const gradient = ctx.createLinearGradient(0, building.y, 0, building.y + building.height);
gradient.addColorStop(0, '#FFD700');
gradient.addColorStop(1, '#FFA500');
ctx.fillStyle = gradient;
ctx.fillRect(building.x, building.y, building.width, building.height);
// Add windows
ctx.fillStyle = '#333';
const windowWidth = 8;
const windowHeight = 12;
const windowSpacing = 15;
for (let y = building.y + 10; y < building.y + building.height - 10; y += windowSpacing) {
for (let x = building.x + 10; x < building.x + building.width - 10; x += windowSpacing) {
ctx.fillRect(x, y, windowWidth, windowHeight);
}
}
}
});
}
function updateStars() {
// Add new stars
if (Math.random() < 0.03) {
stars.push({
x: canvas.width,
y: 50 + Math.random() * (canvas.height - 150),
width: 20,
height: 20,
speed: gameSpeed
});
}
// Move stars
for (let i = stars.length - 1; i >= 0; i--) {
stars[i].x -= stars[i].speed;
// Remove stars that are off screen
if (stars[i].x + stars[i].width < 0) {
stars.splice(i, 1);
}
}
}
function drawStars() {
stars.forEach(star => {
ctx.save();
ctx.translate(star.x + star.width / 2, star.y + star.height / 2);
ctx.rotate(Date.now() / 200); // Make star rotate
ctx.drawImage(
createStarImage(),
-star.width / 2,
-star.height / 2,
star.width,
star.height
);
ctx.restore();
});
}
function createStarImage() {
const img = new Image();
img.src = 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23FFD700" d="M12,17.27L18.18,21l-1.64-7.03L22,9.24l-7.19-.61L12,2,9.19,8.63,2,9.24l5.46,4.73L5.82,21Z"/></svg>';
return img;
}
function updateClouds() {
// Add new clouds
if (Math.random() < 0.01) {
const size = 30 + Math.random() * 50;
clouds.push({
x: canvas.width,
y: 50 + Math.random() * (canvas.height / 2),
width: size,
height: size / 2,
speed: gameSpeed / 2
});
}
// Move clouds
for (let i = clouds.length - 1; i >= 0; i--) {
clouds[i].x -= clouds[i].speed;
// Remove clouds that are off screen
if (clouds[i].x + clouds[i].width < 0) {
clouds.splice(i, 1);
}
}
}
function drawClouds() {
clouds.forEach(cloud => {
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
// Draw cloud as overlapping circles
ctx.beginPath();
ctx.arc(cloud.x, cloud.y, cloud.width / 2, 0, Math.PI * 2);
ctx.arc(cloud.x + cloud.width / 3, cloud.y - cloud.height / 3, cloud.width / 3, 0, Math.PI * 2);
ctx.arc(cloud.x + cloud.width / 2, cloud.y, cloud.width / 3, 0, Math.PI * 2);
ctx.arc(cloud.x + cloud.width / 3, cloud.y + cloud.height / 3, cloud.width / 4, 0, Math.PI * 2);
ctx.fill();
});
}
function checkCollisions() {
// Check building collisions
for (let i = 0; i < buildings.length; i++) {
const building = buildings[i];
if (
plane.x < building.x + building.width &&
plane.x + plane.width > building.x &&
plane.y < building.y + building.height &&
plane.y + plane.height > building.y
) {
gameOver();
return;
}
}
// Check star collisions
for (let i = stars.length - 1; i >= 0; i--) {
const star = stars[i];
if (
plane.x < star.x + star.width &&
plane.x + plane.width > star.x &&
plane.y < star.y + star.height &&
plane.y + plane.height > star.y
) {
// Collect star
stars.splice(i, 1);
score += 10;
scoreElement.textContent = score;
}
}
}
function gameOver() {
gameRunning = false;
cancelAnimationFrame(animationId);
finalScoreElement.textContent = score;
gameOverScreen.style.display = 'flex';
}
// Preload images
createPlaneImage();
createStarImage();
</script>
</html> |