Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -309,25 +309,42 @@ CODE_SYSTEM = (
|
|
| 309 |
"You are an expert HTML5 game developer. "
|
| 310 |
"Write a complete, working, single-file HTML5 game using canvas and vanilla JavaScript. "
|
| 311 |
"CRITICAL RULES - follow every one exactly: "
|
| 312 |
-
"1. SPRITES: Declare these at the very top of the script
|
| 313 |
" const playerImg = new Image(); playerImg.src = 'sprite_player.png'; "
|
| 314 |
" const bgImg = new Image(); bgImg.src = 'sprite_background.png'; "
|
| 315 |
" const enemyImg = new Image(); enemyImg.src = 'sprite_enemy.png'; "
|
| 316 |
" const keys = new Set(); "
|
| 317 |
-
"2. IMAGE LOADING: After declaring sprites
|
| 318 |
" function loadImg(img) { return new Promise(r => { img.onload = r; }); } "
|
| 319 |
" Promise.all([loadImg(playerImg), loadImg(bgImg), loadImg(enemyImg)]).then(startGame); "
|
| 320 |
-
"3. startGame function
|
|
|
|
| 321 |
" window.addEventListener('keydown', e => keys.add(e.key)); "
|
| 322 |
" window.addEventListener('keyup', e => keys.delete(e.key)); "
|
|
|
|
| 323 |
" requestAnimationFrame(gameLoop); } "
|
| 324 |
-
"4. Define gameLoop() and
|
| 325 |
-
"5.
|
| 326 |
-
"
|
| 327 |
-
"
|
| 328 |
-
"
|
| 329 |
-
"
|
| 330 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
"Output ONLY the raw HTML - no markdown fences, no explanation, nothing else."
|
| 332 |
)
|
| 333 |
|
|
|
|
| 309 |
"You are an expert HTML5 game developer. "
|
| 310 |
"Write a complete, working, single-file HTML5 game using canvas and vanilla JavaScript. "
|
| 311 |
"CRITICAL RULES - follow every one exactly: "
|
| 312 |
+
"1. SPRITES: Declare these at the very top of the script BEFORE anything else: "
|
| 313 |
" const playerImg = new Image(); playerImg.src = 'sprite_player.png'; "
|
| 314 |
" const bgImg = new Image(); bgImg.src = 'sprite_background.png'; "
|
| 315 |
" const enemyImg = new Image(); enemyImg.src = 'sprite_enemy.png'; "
|
| 316 |
" const keys = new Set(); "
|
| 317 |
+
"2. IMAGE LOADING: After declaring sprites use Promise.all to start the game: "
|
| 318 |
" function loadImg(img) { return new Promise(r => { img.onload = r; }); } "
|
| 319 |
" Promise.all([loadImg(playerImg), loadImg(bgImg), loadImg(enemyImg)]).then(startGame); "
|
| 320 |
+
"3. startGame function sets up listeners and calls gameLoop: "
|
| 321 |
+
" function startGame() { "
|
| 322 |
" window.addEventListener('keydown', e => keys.add(e.key)); "
|
| 323 |
" window.addEventListener('keyup', e => keys.delete(e.key)); "
|
| 324 |
+
" canvas.addEventListener('click', onShoot); "
|
| 325 |
" requestAnimationFrame(gameLoop); } "
|
| 326 |
+
"4. Define gameLoop() and ALL game logic functions at TOP LEVEL - NOT inside startGame or Promise.then. "
|
| 327 |
+
"5. MOVEMENT RULES DEPEND ON GAME TYPE: "
|
| 328 |
+
" FOR TOP-DOWN SHOOTER: NO gravity, NO velY += 0.5, NO grounded variable. "
|
| 329 |
+
" Player moves in ALL 4 directions with WASD: "
|
| 330 |
+
" if (keys.has('w') || keys.has('ArrowUp')) player.y -= speed; "
|
| 331 |
+
" if (keys.has('s') || keys.has('ArrowDown')) player.y += speed; "
|
| 332 |
+
" if (keys.has('a') || keys.has('ArrowLeft')) player.x -= speed; "
|
| 333 |
+
" if (keys.has('d') || keys.has('ArrowRight')) player.x += speed; "
|
| 334 |
+
" FOR TOP-DOWN SHOOTER: Enemies move TOWARD the player each frame: "
|
| 335 |
+
" const dx = player.x - enemy.x; const dy = player.y - enemy.y; "
|
| 336 |
+
" const dist = Math.sqrt(dx*dx + dy*dy); "
|
| 337 |
+
" enemy.x += (dx/dist) * enemy.speed; enemy.y += (dy/dist) * enemy.speed; "
|
| 338 |
+
" FOR TOP-DOWN SHOOTER: Left click shoots a bullet toward the mouse position: "
|
| 339 |
+
" function onShoot(e) { const rect = canvas.getBoundingClientRect(); "
|
| 340 |
+
" const mx = e.clientX - rect.left; const my = e.clientY - rect.top; "
|
| 341 |
+
" const dx = mx - player.x; const dy = my - player.y; "
|
| 342 |
+
" const dist = Math.sqrt(dx*dx+dy*dy); "
|
| 343 |
+
" bullets.push({x: player.x, y: player.y, vx: dx/dist*10, vy: dy/dist*10}); } "
|
| 344 |
+
" FOR PLATFORMER: use gravity velY += 0.5, grounded checks, jump with ArrowUp. "
|
| 345 |
+
"6. Draw background FIRST each frame: ctx.drawImage(bgImg, 0, 0, canvas.width, canvas.height). "
|
| 346 |
+
"7. Draw player/enemies with ctx.drawImage(playerImg, x, y, w, h). "
|
| 347 |
+
"8. Always keep player inside canvas boundaries. "
|
| 348 |
"Output ONLY the raw HTML - no markdown fences, no explanation, nothing else."
|
| 349 |
)
|
| 350 |
|