Here’s a one-shot HTML/JS/CSS “side-scroller” that you can save as index.html and open in your browser. It features:
• A neon-punk cityscape
• Destructible crates blocking 3 civilians you must rescue
• High-tech security turrets & patrolling robots with evolving AI
• 3 hero abilities (Dash, Hack, Turret-Deploy) + collectible upgrades
• A final boss at the core
• A built-in “console” to type commands like
– “Give the player a jetpack”
– “Add stealth mechanics at level 2”
– “Make the boss immune to electrical attacks”
—
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>CyberCity Rescue</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body { background:#0a0a0f; overflow:hidden; font-family:sans-serif; color:#eee; }
#gameCanvas { background: linear-gradient(#111, #020206); display:block; }
#hud {
position:absolute; top:10px; left:10px; z-index:10;
line-height:1.4;
}
#console {
position:absolute; bottom:10px; left:10px; z-index:10;
background:rgba(0,0,0,0.6); padding:8px; border-radius:4px;
}
#console input { width:200px; }
.btn { padding:4px 8px; background:#222; border:none; color:#eee; cursor:pointer; }
</style>
</head>
<body>
<canvas id="gameCanvas" width="800" height="400"></canvas>
<div id="hud">
<div>Health: <span id="hp">100</span></div>
<div>Rescued: <span id="rescued">0</span>/3</div>
<div>Boss HP: <span id="bossHp">—</span></div>
</div>
<div id="console">
Command: <input id="cmd"><button id="runCmd" class="btn">Run</button>
</div>
<script>
// —————————————————————————————————————————————
// SETTINGS & STATE
// —————————————————————————————————————————————
const canvas = document.getElementById('gameCanvas'),
ctx = canvas.getContext('2d');
const W = canvas.width, H = canvas.height;
let keys = {}, gameFrame=0, difficultyTimer=0;
// Player state
let player = {
x:50, y:H-60, w:32, h:48,
vx:0, vy:0, onGround:false,
hp:100,
abilities:{ dash:true, hack:true, turret:true },
cooldown:{ dash:0, hack:0, turret:0 },
upgrades:{ dashCd:-0.2, hackRange:+0, turretCount:+0 },
jetpack:false, stealth:false
};
// Level objects
let platforms = [], crates=[], civilians=[], enemies=[], bullets=[],
turrets=[], pickups=[], boss=null;
// HUD
const elHP = document.getElementById('hp'),
elRes = document.getElementById('rescued'),
elBoss= document.getElementById('bossHp');
// Initialize
init();
requestAnimationFrame(loop);
// —————————————————————————————————————————————
// INITIALIZATION
// —————————————————————————————————————————————
function init(){
// Platforms (ground + floating)
platforms = [
{x:0,y:H-20,w:W,h:20}, {x:200,y:300,w:200,h:10},
{x:500,y:260,w:180,h:10}, {x:720,y:340,w:80,h:10}
];
// Crates blocking civilians
crates = [
{x:350,y:H-60,w:40,h:40, hp:2},
{x:650,y:H-100,w:40,h:40, hp:2}
];
// Civilians hidden behind crates
civilians = [
{x:360,y:H-100,w:24,h:32, rescued:false},
{x:660,y:H-140,w:24,h:32, rescued:false},
{x:780,y:300,w:24,h:32, rescued:false}
];
// Basic patrolling robots
enemies = [];
for(let i=0;i<4;i++){
enemies.push({
x:120+i*150, y:H-60, w:32,h:32,
dir:Math.random()<0.5?-1:1,
speed:1, disabled:0
});
}
// Final boss
boss = { x:900, y:H-100, w:80,h:80, hp:200, immune:{ hack:false } };
elBoss.textContent = boss.hp;
bullets = []; turrets=[]; pickups=[];
gameFrame=0; difficultyTimer=0;
}
// —————————————————————————————————————————————
// GAME LOOP
// —————————————————————————————————————————————
function loop(){
update();
draw();
requestAnimationFrame(loop);
}
// —————————————————————————————————————————————
// UPDATE – frame-by-frame logic
// —————————————————————————————————————————————
function update(){
gameFrame++;
difficultyTimer++;
if(difficultyTimer>600){ // every 10s ramp up
enemies.forEach(e=>e.speed+=0.2);
difficultyTimer=0;
}
handleInput();
physics();
updateEnemies();
updateBullets();
updateTurrets();
checkCivilians();
updateBoss();
// HUD
elHP.textContent = player.hp;
elRes.textContent = civilians.filter(c=>c.rescued).length;
elBoss.textContent = boss.hp>0?boss.hp:'—';
}
// —————————————————————————————————————————————
// INPUT
// —————————————————————————————————————————————
window.addEventListener('keydown', e=> keys[e.key]=1);
window.addEventListener('keyup', e=> keys[e.key]=0);
function handleInput(){
// LEFT/RIGHT
if(keys['ArrowLeft']) player.vx = -2;
else if(keys['ArrowRight']) player.vx = 2;
else player.vx=0;
// JUMP
if((keys['z']||keys['Z']) && player.onGround){
player.vy = -5;
player.onGround=false;
}
// Jetpack
if(player.jetpack && (keys['z']||keys['Z'])){
player.vy -= 0.2; // fly
}
// DASH
if(keys['x']&& player.abilities.dash && player.cooldown.dash<=0){
player.vx *= 4; player.cooldown.dash = 60+player.upgrades.dashCd*60;
}
// HACK
if(keys['c']&& player.abilities.hack && player.cooldown.hack<=0){
enemies.forEach(e=>{
let dx=e.x-player.x, dy=e.y-player.y;
if(Math.hypot(dx,dy)<80+player.upgrades.hackRange){
if(!boss.immune.hack || e!==boss) e.disabled=120;
}
});
if(!boss.immune.hack){
let dx=boss.x-player.x, dy=boss.y-player.y;
if(Math.hypot(dx,dy)<100) boss.disabled=120;
}
player.cooldown.hack=180;
}
// DEPLOY TURRET
if(keys['v']&& player.abilities.turret && player.cooldown.turret<=0){
turrets.push({ x:player.x, y:player.y-20, fireRate:60 });
player.cooldown.turret=300;
}
// Cooldowns
for(let k in player.cooldown) if(player.cooldown[k]>0) player.cooldown[k]--;
}
// —————————————————————————————————————————————
// PHYSICS & COLLISIONS
// —————————————————————————————————————————————
function physics(){
// gravity
player.vy += 0.2;
player.y += player.vy;
player.x += player.vx;
// ground/platforms
player.onGround=false;
platforms.forEach(p=>{
if(checkRect(player,p)){
if(player.vy>0){
player.y = p.y - player.h;
player.vy=0; player.onGround=true;
}
}
});
// screen bounds
player.x = Math.max(0, Math.min(player.x, W-player.w));
player.y = Math.min(player.y, H-player.h);
// crate collisions and destruct
crates.forEach(c=>{
if(c.hp>0 && checkRect(player,c)){
// pushback
player.x -= player.vx*2;
}
});
}
// —————————————————————————————————————————————
// ENEMY AI
// —————————————————————————————————————————————
function updateEnemies(){
enemies.forEach(e=>{
if(e.disabled>0){ e.disabled--; return; }
// simple patrol
e.x += e.speed * e.dir;
// turn on edges
if(e.x<0||e.x>W-e.w) e.dir*=-1;
// pursue player if close
let dx=player.x-e.x, dy=player.y-e.y;
if(Math.hypot(dx,dy)<150){
e.dir = dx>0?1:-1;
e.x += e.speed*e.dir;
}
// collision damage
if(checkRect(player,e)){
damage(0.2);
}
});
}
// —————————————————————————————————————————————
// BULLETS & TURRETS
// —————————————————————————————————————————————
function updateBullets(){
bullets = bullets.filter(b=>{
b.x += b.vx; b.y += b.vy;
// hit enemy?
enemies.forEach((e,i)=>{
if(checkRect(b,e)){
enemies.splice(i,1);
spawnPickup(e.x,e.y);
b.dead=true;
}
});
// hit boss?
if(boss && checkRect(b,boss)){
boss.hp -=10; b.dead=true;
}
return !b.dead && b.x>0 && b.x<W;
});
}
function updateTurrets(){
turrets.forEach(t=>{
t.fireRate--;
if(t.fireRate<=0){
// shoot at nearest enemy/boss
let target = enemies.concat(boss).filter(x=>x).sort((a,b)=>
Math.hypot(a.x-player.x,a.y-player.y) - Math.hypot(b.x-player.x,b.y-player.y)
)[0];
if(target){
let dx=target.x-t.x, dy=target.y-t.y, m=Math.hypot(dx,dy);
bullets.push({
x:t.x,y:t.y,vx:dx/m*4,vy:dy/m*4,dead:false
});
}
t.fireRate=60;
}
});
}
// —————————————————————————————————————————————
// PICKUPS
// —————————————————————————————————————————————
function spawnPickup(x,y){
pickups.push({x,y, type:'health'});
}
function updatePickups(){
pickups.forEach((p,i)=>{
if(checkRect(player,{x:p.x,y:p.y,w:16,h:16})){
if(p.type=='health'){
player.hp = Math.min(100, player.hp+20);
}
pickups.splice(i,1);
}
});
}
// —————————————————————————————————————————————
// CIVILIAN RESCUE & CRATE DESTRUCTION
// —————————————————————————————————————————————
function checkCivilians(){
// crates break by repeated dash/hits
crates.forEach(c=>{
// if any bullet hits
bullets.forEach(b=>{
if(checkRect(b,c)){
c.hp--; b.dead=true;
}
});
if(c.hp<=0){
c.w=0; // vanish
}
});
civilians.forEach(c=>{
if(!c.rescued && checkRect(player,{x:c.x,y:c.y,w:c.w,h:c.h})){
if(!crates.find(r=>r.x< c.x+ c.w && r.x+ r.w>c.x)){
c.rescued=true;
}
}
});
}
// —————————————————————————————————————————————
// BOSS LOGIC
// —————————————————————————————————————————————
function updateBoss(){
if(!boss||boss.hp<=0)return;
if(boss.disabled>0){ boss.disabled--; return; }
// slowly move toward player
let dx=player.x-boss.x, dy=player.y-boss.y, d=Math.hypot(dx,dy);
boss.x += (dx/d)*0.5;
boss.y += (dy/d)*0.5;
// collide
if(checkRect(player,boss)){
damage(0.5);
}
// if all civilians rescued & boss near core => win
if(civilians.every(c=>c.rescued) && Math.hypot(boss.x-player.x,boss.y-player.y)<50){
alert("🌟 YOU WIN! 🌟"); init();
}
// lose if hp<=0
if(player.hp<=0) {
alert("💀 GAME OVER 💀"); init();
}
}
// —————————————————————————————————————————————
// DRAW
// —————————————————————————————————————————————
function draw(){
// clear
ctx.clearRect(0,0,W,H);
// background city (parallax stripes)
for(let i=0;i<5;i++){
ctx.fillStyle = `rgba(20,20,30,${0.1})`;
ctx.fillRect(0,i*80, W, 5);
}
// platforms
ctx.fillStyle='#444';
platforms.forEach(p=>ctx.fillRect(p.x,p.y,p.w,p.h));
// crates
crates.forEach(c=>{
if(c.hp>0){
ctx.fillStyle='#a52'; ctx.fillRect(c.x,c.y,c.w,c.h);
}
});
// civilians
civilians.forEach(c=>{
if(!c.rescued){
ctx.fillStyle='#0f0'; ctx.fillRect(c.x,c.y,c.w,c.h);
}
});
// player
ctx.fillStyle = player.stealth?'rgba(255,255,255,0.3)':'#0ff';
ctx.fillRect(player.x,player.y,player.w,player.h);
// enemies
enemies.forEach(e=>{
ctx.fillStyle=e.disabled?'#555':'#f44';
ctx.fillRect(e.x,e.y,e.w,e.h);
});
// boss
if(boss.hp>0){
ctx.fillStyle = boss.disabled?'#555':'#f0f';
ctx.fillRect(boss.x,boss.y,boss.w,boss.h);
}
// bullets
ctx.fillStyle='#ff0';
bullets.forEach(b=>ctx.fillRect(b.x,b.y,4,4));
// turrets
turrets.forEach(t=>{
ctx.fillStyle='#0f0';
ctx.fillRect(t.x-5,t.y-5,10,10);
});
// pickups
pickups.forEach(p=>{
ctx.fillStyle='#f0f'; ctx.fillRect(p.x,p.y,16,16);
});
}
// —————————————————————————————————————————————
// HELPERS
// —————————————————————————————————————————————
function checkRect(a,b){
return a.x < b.x+b.w && a.x+a.w > b.x &&
a.y < b.y+b.h && a.y+a.h > b.y;
}
function damage(d){ player.hp-=d; if(player.hp<0)player.hp=0; }
// —————————————————————————————————————————————
// IN-PROMPT COMMANDS
// —————————————————————————————————————————————
document.getElementById('runCmd').onclick = ()=>{
let cmd = document.getElementById('cmd').value.trim().toLowerCase();
let msg = '';
if(cmd.includes('jetpack')){
player.jetpack = true; msg='🚀 Jetpack granted!';
}
if(cmd.includes('stealth') && cmd.includes('level 2')){
player.stealth = true; msg+=' 🕵️♂️ Stealth unlocked at lvl2!';
}
if(cmd.includes('boss immune') && cmd.includes('electrical')){
boss.immune.hack = true; msg+=' ⚡ Boss immune to hacks!';
}
if(!msg) msg='❓ Unknown command';
alert(msg);
document.getElementById('cmd').value='';
};
</script>
</body>
</html>
How to Play
• Arrow keys = move
• Z = jump
• X = dash (cooldown shown by brief “freeze”)
• C = hack (disable nearby robots & boss, unless immune)
• V = deploy an automated turret
👉 Objective:
- Destroy crates (by shooting them with your dash-bullets) to free 3 civilians.
- Rescue them by touching them.
- Approach the boss and defeat it once all civilians are safe.
Along the way, robots patrol & evolve—every 10 seconds they speed up.
In-Prompt Tweaks
At the bottom console you can type commands such as:
• “Give the player a jetpack”
• “Add stealth mechanics at level 2”
• “Make the boss immune to electrical attacks”
These instantly modify your abilities, enemy immunities, or level-logic without touching the code. Enjoy experimenting with your own future of gameplay!