File size: 14,619 Bytes
103e064 a396155 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alina's Academic Adventure</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
#gameCanvas {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
.character {
transition: all 0.3s ease;
}
.obstacle {
animation: float 3s infinite ease-in-out;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
</style>
</head>
<body class="bg-gradient-to-br from-purple-100 to-blue-100 min-h-screen flex flex-col items-center justify-center p-4">
<header class="text-center mb-8">
<h1 class="text-4xl font-bold text-purple-800 mb-2">Alina's Academic Adventure</h1>
<p class="text-purple-600">Help Alina the kitten reach her university!</p>
</header>
<div class="relative w-full max-w-2xl">
<canvas id="gameCanvas" width="800" height="500" class="w-full h-auto"></canvas>
<div id="startScreen" class="absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-70 rounded-lg">
<div class="bg-white p-8 rounded-lg text-center max-w-md">
<h2 class="text-2xl font-bold text-purple-800 mb-4">Ready for school?</h2>
<p class="text-gray-700 mb-6">Help Alina navigate through obstacles to reach her university. Use arrow keys to move!</p>
<button id="startButton" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-6 rounded-full transition-all transform hover:scale-105">
Start Journey
</button>
</div>
</div>
<div id="gameOverScreen" class="absolute inset-0 hidden flex-col items-center justify-center bg-black bg-opacity-70 rounded-lg">
<div class="bg-white p-8 rounded-lg text-center max-w-md">
<h2 id="resultText" class="text-2xl font-bold text-purple-800 mb-4">Oh no!</h2>
<p id="scoreText" class="text-gray-700 mb-6">You didn't make it to school today.</p>
<button id="restartButton" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-6 rounded-full transition-all transform hover:scale-105">
Try Again
</button>
</div>
</div>
</div>
<div class="mt-8 flex items-center gap-4">
<div class="bg-white p-4 rounded-lg shadow-md">
<h3 class="text-lg font-semibold text-purple-800 mb-2">Controls</h3>
<div class="flex gap-2">
<div class="bg-gray-100 p-2 rounded"><i data-feather="arrow-up"></i></div>
<div class="bg-gray-100 p-2 rounded"><i data-feather="arrow-down"></i></div>
<div class="bg-gray-100 p-2 rounded"><i data-feather="arrow-left"></i></div>
<div class="bg-gray-100 p-2 rounded"><i data-feather="arrow-right"></i></div>
</div>
</div>
<div class="bg-white p-4 rounded-lg shadow-md">
<h3 class="text-lg font-semibold text-purple-800 mb-2">Score</h3>
<p id="currentScore" class="text-2xl font-bold text-purple-600">0</p>
</div>
</div>
<footer class="mt-12 text-center text-purple-500">
<p>Made with ❤️ for Alina's academic journey</p>
</footer>
<script>
feather.replace();
// Game variables
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 resultText = document.getElementById('resultText');
const scoreText = document.getElementById('scoreText');
const currentScore = document.getElementById('currentScore');
let gameRunning = false;
let score = 0;
// Character properties
const character = {
x: 50,
y: canvas.height / 2,
width: 50,
height: 50,
speed: 5,
color: '#FF6B6B'
};
// University properties
const university = {
x: canvas.width - 100,
y: canvas.height / 2 - 25,
width: 80,
height: 100,
color: '#4ECDC4'
};
// Array of obstacles
let obstacles = [];
const obstacleTypes = ['homework', 'sleep', 'distractions'];
// Keyboard controls
const keys = {
ArrowUp: false,
ArrowDown: false,
ArrowLeft: false,
ArrowRight: false
};
// Event listeners
startButton.addEventListener('click', startGame);
restartButton.addEventListener('click', startGame);
document.addEventListener('keydown', (e) => {
if (keys.hasOwnProperty(e.key)) {
keys[e.key] = true;
}
});
document.addEventListener('keyup', (e) => {
if (keys.hasOwnProperty(e.key)) {
keys[e.key] = false;
}
});
// Start game function
function startGame() {
gameRunning = true;
score = 0;
currentScore.textContent = score;
character.x = 50;
character.y = canvas.height / 2;
obstacles = [];
startScreen.classList.add('hidden');
gameOverScreen.classList.add('hidden');
// Start game loop
requestAnimationFrame(gameLoop);
}
// Game loop
function gameLoop() {
if (!gameRunning) return;
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update character position
updateCharacter();
// Update obstacles
updateObstacles();
// Draw game elements
drawGame();
// Check for collisions or win condition
checkGameStatus();
// Continue game loop
requestAnimationFrame(gameLoop);
}
// Update character position based on keyboard input
function updateCharacter() {
if (keys.ArrowUp && character.y > 0) {
character.y -= character.speed;
}
if (keys.ArrowDown && character.y < canvas.height - character.height) {
character.y += character.speed;
}
if (keys.ArrowLeft && character.x > 0) {
character.x -= character.speed;
}
if (keys.ArrowRight && character.x < canvas.width - character.width) {
character.x += character.speed;
}
}
// Update obstacles
function updateObstacles() {
// Randomly add new obstacles
if (Math.random() < 0.02) {
const type = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
const size = Math.random() * 30 + 30;
obstacles.push({
x: canvas.width,
y: Math.random() * (canvas.height - size),
width: size,
height: size,
speed: Math.random() * 3 + 2,
type: type,
color: getObstacleColor(type)
});
}
// Move obstacles
obstacles.forEach(obstacle => {
obstacle.x -= obstacle.speed;
});
// Remove obstacles that are off screen
obstacles = obstacles.filter(obstacle => obstacle.x + obstacle.width > 0);
}
// Get obstacle color based on type
function getObstacleColor(type) {
switch(type) {
case 'homework': return '#FFD166';
case 'sleep': return '#06D6A0';
case 'distractions': return '#EF476F';
default: return '#118AB2';
}
}
// Draw game elements
function drawGame() {
// Draw university
ctx.fillStyle = university.color;
ctx.fillRect(university.x, university.y, university.width, university.height);
// Draw university details
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(university.x + 10, university.y + 20, 15, 60);
ctx.fillRect(university.x + 30, university.y + 10, 15, 70);
ctx.fillRect(university.x + 50, university.y + 30, 15, 50);
// Draw character (kitten)
ctx.fillStyle = character.color;
ctx.beginPath();
ctx.arc(character.x + character.width/2, character.y + character.height/2, character.width/2, 0, Math.PI * 2);
ctx.fill();
// Draw kitten face
ctx.fillStyle = '#FFFFFF';
ctx.beginPath();
ctx.arc(character.x + character.width/2 - 10, character.y + character.height/2 - 5, 5, 0, Math.PI * 2);
ctx.arc(character.x + character.width/2 + 10, character.y + character.height/2 - 5, 5, 0, Math.PI * 2);
ctx.fill();
// Draw kitten mouth
ctx.strokeStyle = '#FFFFFF';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(character.x + character.width/2, character.y + character.height/2 + 5, 8, 0, Math.PI);
ctx.stroke();
// Draw kitten ears
ctx.fillStyle = character.color;
ctx.beginPath();
ctx.moveTo(character.x + character.width/2 - 15, character.y + character.height/2 - 25);
ctx.lineTo(character.x + character.width/2 - 5, character.y + character.height/2 - 15);
ctx.lineTo(character.x + character.width/2 - 25, character.y + character.height/2 - 5);
ctx.fill();
ctx.beginPath();
ctx.moveTo(character.x + character.width/2 + 15, character.y + character.height/2 - 25);
ctx.lineTo(character.x + character.width/2 + 5, character.y + character.height/2 - 15);
ctx.lineTo(character.x + character.width/2 + 25, character.y + character.height/2 - 5);
ctx.fill();
// Draw obstacles
obstacles.forEach(obstacle => {
ctx.fillStyle = obstacle.color;
// Different shapes for different obstacles
if (obstacle.type === 'homework') {
// Draw stack of papers
ctx.fillRect(obstacle.x, obstacle.y, obstacle.width, obstacle.height/3);
ctx.fillRect(obstacle.x + 5, obstacle.y + obstacle.height/3, obstacle.width - 10, obstacle.height/3);
ctx.fillRect(obstacle.x + 10, obstacle.y + 2*obstacle.height/3, obstacle.width - 20, obstacle.height/3);
} else if (obstacle.type === 'sleep') {
// Draw pillow
ctx.beginPath();
ctx.ellipse(obstacle.x + obstacle.width/2, obstacle.y + obstacle.height/2,
obstacle.width/2, obstacle.height/2, 0, 0, Math.PI * 2);
ctx.fill();
// Draw Zzz
ctx.fillStyle = '#FFFFFF';
ctx.font = 'bold 16px Arial';
ctx.fillText('Zzz', obstacle.x + obstacle.width/2 - 10, obstacle.y + obstacle.height/2 + 5);
} else {
// Draw phone for distractions
ctx.fillRect(obstacle.x, obstacle.y, obstacle.width, obstacle.height);
ctx.fillStyle = '#000000';
ctx.fillRect(obstacle.x + 5, obstacle.y + 5, obstacle.width - 10, obstacle.height - 25);
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(obstacle.x + 10, obstacle.y + 10, obstacle.width - 20, obstacle.height - 30);
}
});
}
// Check game status (collisions or win)
function checkGameStatus() {
// Check for collision with obstacles
for (const obstacle of obstacles) {
if (
character.x < obstacle.x + obstacle.width &&
character.x + character.width > obstacle.x &&
character.y < obstacle.y + obstacle.height &&
character.y + character.height > obstacle.y
) {
gameOver(false);
return;
}
}
// Check if reached university
if (
character.x < university.x + university.width &&
character.x + character.width > university.x &&
character.y < university.y + university.height &&
character.y + character.height > university.y
) {
gameOver(true);
return;
}
// Increment score
score++;
currentScore.textContent = Math.floor(score / 10);
}
// Game over function
function gameOver(success) {
gameRunning = false;
if (success) {
resultText.textContent = "Congratulations!";
scoreText.textContent = `Alina made it to university with a score of ${Math.floor(score / 10)}!`;
} else {
resultText.textContent = "Oh no!";
scoreText.textContent = `Alina couldn't make it today. Your score: ${Math.floor(score / 10)}`;
}
gameOverScreen.classList.remove('hidden');
}
</script>
</body>
</html>
|