(Body Snatcher) Pass 4
This commit is contained in:
1 parent
00f4c34da0
commit
a219ad17d5
36 files changed
+7693
No files matched your search
@@ -0,0 +1,715 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Body Snatcher</title>
|
||||
<style>
|
||||
*{box-sizing:border-box}
|
||||
html,body{margin:0;padding:0;height:100%;background:#05060a;overflow:hidden;font-family:"Trebuchet MS","Segoe UI",sans-serif}
|
||||
#wrap{display:flex;align-items:center;justify-content:center;height:100%;width:100%}
|
||||
#c{background:#05060a;border-radius:6px;box-shadow:0 0 60px rgba(60,90,170,0.22) inset,0 12px 60px rgba(0,0,0,0.85);cursor:default}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrap"><canvas id="c" width="800" height="576"></canvas></div>
|
||||
<script>
|
||||
(function(){
|
||||
'use strict';
|
||||
/* ===== Body Snatcher — Phase 1: engine, grid, ghost, fog, HUD, title, bestiary ===== */
|
||||
var COLS=25, ROWS=18, TILE=32, VIEW=6.5;
|
||||
var TURN_MS=600, MOVE_MS=85, TICK_SEC=0.6;
|
||||
|
||||
/* ---- enemy data (drives bestiary + spawn; AI arrives in later phases) ---- */
|
||||
var ENEMIES = {
|
||||
brute: {name:'Brute', color:'#c0392b', hp:8, damage:3, speed:2, essence:3,
|
||||
enemy:'Slow A* chase. 2-dmg melee every 2 turns.',
|
||||
kit:'HP 8, DMG 3, slow heavy hitter.'},
|
||||
skitterer: {name:'Skitterer', color:'#e67e22', hp:2, damage:1, speed:2, essence:1,
|
||||
enemy:'Swarm-flanks. Weak 1-dmg melee, moves every 2 turns.',
|
||||
kit:'HP 2, DMG 1, fast rapid hits.'},
|
||||
sentinel: {name:'Sentinel', color:'#9b59b6', hp:4, damage:1, speed:2, essence:3,
|
||||
enemy:'Keeps range. 3-shot burst then overheats 3 turns.',
|
||||
kit:'HP 4, fires facing, burst/overheat, no melee.'},
|
||||
shielder: {name:'Shielder', color:'#3498db', hp:5, damage:2, speed:2, essence:4,
|
||||
enemy:'Slow chase. Frontal shield blocks that facing.',
|
||||
kit:'HP 5, shield active, Q/E to face threats.'},
|
||||
bomber: {name:'Bomber', color:'#7d1f1f', hp:3, damage:4, speed:1, essence:2,
|
||||
enemy:'Chases. Explodes 3x3 (3 dmg) adjacent or on death.',
|
||||
kit:'HP 3, SPACE detonates 3x3 (4 dmg), suicide.'},
|
||||
healer: {name:'Healer', color:'#27ae60', hp:3, damage:1, speed:2, essence:5,
|
||||
enemy:'Heals nearby foes +1/turn. Flees the player.',
|
||||
kit:'HP 3, SPACE AoE heal self +2, allies +1.'},
|
||||
phaser: {name:'Phaser', color:'#1abc9c', hp:4, damage:2, speed:1, essence:4,
|
||||
enemy:'Teleports toward you every 3 turns, hits, fades.',
|
||||
kit:'HP 4, SPACE blink 5 tiles through walls, 2-turn cd.'},
|
||||
turret: {name:'Turret', color:'#7f8c8d', hp:4, damage:1, speed:0, essence:5,
|
||||
enemy:'Stationary 360-degree 3-shot burst, then overheats 3 turns.',
|
||||
kit:'HP 4, rooted, SPACE fire facing, Q/E rotate.'},
|
||||
charger: {name:'Charger', color:'#f1c40f', hp:5, damage:3, speed:1, essence:4,
|
||||
enemy:'Telegraphs 1 turn, charges straight (3 dmg), stuns on wall.',
|
||||
kit:'HP 5, SPACE dash 4 tiles, 2 dmg per foe hit.'},
|
||||
siren: {name:'Siren', color:'#e84393', hp:3, damage:1, speed:3, essence:3,
|
||||
enemy:'Pulls you 1 tile/turn within 5. Weak melee.',
|
||||
kit:'HP 3, SPACE pull all foes within 4 one tile.'},
|
||||
mimic: {name:'Mimic', color:'#b9772e', hp:4, damage:2, speed:1, essence:4,
|
||||
enemy:'Disguised chest. Bursts 2-dmg cross when adjacent.',
|
||||
kit:"HP 4, foes won't aggro disguised, SPACE 2-dmg cross."},
|
||||
leech: {name:'Leech', color:'#6c3483', hp:4, damage:1, speed:2, essence:4,
|
||||
enemy:'Slow chase. Drains 1 HP and heals self.',
|
||||
kit:'HP 4, each hit 1 dmg + heal self 1.'}
|
||||
};
|
||||
|
||||
/* ---- dungeon: hand-authored connected rooms for phase 1 ---- */
|
||||
function buildDungeon(){
|
||||
var g=[]; for(var y=0;y<ROWS;y++){var r=[];for(var x=0;x<COLS;x++)r.push(1);g.push(r);}
|
||||
function carve(x1,y1,x2,y2){for(var y=y1;y<=y2;y++)for(var x=x1;x<=x2;x++) if(y>0&&y<ROWS-1&&x>0&&x<COLS-1)g[y][x]=0;}
|
||||
function hcorr(x1,x2,y){var a=Math.min(x1,x2),b=Math.max(x1,x2);for(var x=a;x<=b;x++) if(y>0&&y<ROWS-1&&x>0&&x<COLS-1)g[y][x]=0;}
|
||||
function vcorr(y1,y2,x){var a=Math.min(y1,y2),b=Math.max(y1,y2);for(var y=a;y<=b;y++) if(y>0&&y<ROWS-1&&x>0&&x<COLS-1)g[y][x]=0;}
|
||||
carve(2,2,7,5); carve(11,2,16,6); carve(19,2,23,6);
|
||||
carve(2,9,6,13); carve(10,10,15,14); carve(19,9,23,15);
|
||||
hcorr(7,11,3); hcorr(16,19,4); vcorr(5,9,4);
|
||||
hcorr(6,10,12); hcorr(15,19,12); vcorr(6,10,13);
|
||||
g[3][22]=3; // exit stairs in far room
|
||||
g[3][9]=2; g[4][18]=2; g[12][8]=2; // doors (flavour, walkable)
|
||||
return g;
|
||||
}
|
||||
var SPAWN={x:4,y:3};
|
||||
function rebuildExplored(){var e=[];for(var y=0;y<ROWS;y++){var r=[];for(var x=0;x<COLS;x++)r.push(false);e.push(r);}return e;}
|
||||
function isSolid(t){ return t===1; }
|
||||
function ghostCap(){ return (GAME.upgrades && GAME.upgrades.ghostT1) ? 20 : 15; }
|
||||
|
||||
function placePlayer(){
|
||||
GAME.player={x:SPAWN.x,y:SPAWN.y,rx:SPAWN.x,ry:SPAWN.y,ghost:true,timer:ghostCap(),
|
||||
host:null,facing:{x:0,y:1},fromX:SPAWN.x,fromY:SPAWN.y,moveT:1};
|
||||
}
|
||||
function updateFog(){
|
||||
var p=GAME.player; if(!p||!GAME.explored) return;
|
||||
for(var y=0;y<ROWS;y++)for(var x=0;x<COLS;x++){
|
||||
if(Math.hypot(x-p.x,y-p.y)<=VIEW) GAME.explored[y][x]=true;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================ GAME API ================================= */
|
||||
var GAME={
|
||||
state:'title', grid:null, explored:null, player:null,
|
||||
enemies:[], projectiles:[], upgrades:{}, achievements:{}, log:[],
|
||||
floor:1, essence:0, showLegend:false, choices:[],
|
||||
|
||||
start:function(){
|
||||
this.state='title'; this.grid=buildDungeon(); this.explored=rebuildExplored();
|
||||
this.enemies=[]; this.projectiles=[]; this.upgrades={}; this.achievements={}; this.log=[];
|
||||
this.floor=1; this.essence=0; this.showLegend=false; this._possessedTypes={};
|
||||
placePlayer(); updateFog();
|
||||
return this.state;
|
||||
},
|
||||
newRun:function(){
|
||||
this.grid=buildDungeon(); this.explored=rebuildExplored();
|
||||
this.enemies=[]; this.projectiles=[]; this.floor=1; this.showLegend=false; this._possessedTypes={};
|
||||
placePlayer(); populateFloor(); this.state='playing'; updateFog(); achCheck();
|
||||
return this.state;
|
||||
},
|
||||
setFloor:function(n){
|
||||
this.floor=n||1; this.grid=buildDungeon(); this.explored=rebuildExplored();
|
||||
this.enemies=[]; this.projectiles=[]; this.showLegend=false;
|
||||
placePlayer(); this.state='playing'; updateFog();
|
||||
return this.state;
|
||||
},
|
||||
spawn:function(type,x,y){
|
||||
var d=ENEMIES[type]; if(!d) return null;
|
||||
if(x==null){x=SPAWN.x;} if(y==null){y=SPAWN.y;}
|
||||
var e={type:type,name:d.name,color:d.color,hp:d.hp,maxHp:d.hp,damage:d.damage,
|
||||
speed:d.speed,essence:d.essence,x:x,y:y,rx:x,ry:y,facing:{x:0,y:1},
|
||||
aggroed:false,overheatLeft:0,shotsFired:0,burst:0,burstCount:0,moveCd:0,lockout:0,pacified:0,hitFlash:0,
|
||||
fromX:x,fromY:y,moveT:1};
|
||||
this.enemies.push(e); return e;
|
||||
},
|
||||
input:function(key){
|
||||
if(key==='' ) key='Space';
|
||||
if(key==='l'||key==='L'){ if(this.state==='title'||this.state==='paused'){ this.showLegend=!this.showLegend; } return; }
|
||||
if(this.showLegend){ if(key==='Escape'){ this.showLegend=false; } return; }
|
||||
if(key==='Enter'){
|
||||
if(this.state==='title'){ this.newRun(); }
|
||||
else if(this.state==='won'||this.state==='lost'){ this.start(); }
|
||||
return;
|
||||
}
|
||||
if(key==='Escape'){
|
||||
if(this.state==='playing'||this.state==='possessed'){ this.state='paused'; }
|
||||
else if(this.state==='paused'){ this.state='playing'; }
|
||||
return;
|
||||
}
|
||||
if(this.state!=='playing'&&this.state!=='possessed') return;
|
||||
var dir=keyDir(key);
|
||||
if(dir){ tryMove(dir.dx,dir.dy); return; }
|
||||
if(key===' '||key==='Space'){ if(this.state==='playing'){ tryPossess(); } else if(this.state==='possessed'){ hostAttack(); } return; }
|
||||
if(key==='x'||key==='X'){ if(this.state==='possessed'){ abandonHost(); } return; }
|
||||
if(key==='q'||key==='Q'){ rotate(-1); return; }
|
||||
if(key==='e'||key==='E'){ rotate(1); return; }
|
||||
},
|
||||
tick:function(n){
|
||||
n=n||1;
|
||||
for(var i=0;i<n;i++){
|
||||
var st=this.state;
|
||||
if(st==='playing'){
|
||||
if(this.player.possessing){ completePossession(this.player.possessing); this.player.possessing=null; }
|
||||
else { this.player.timer-=TICK_SEC; if(this.player.timer<=0){ this.player.timer=0; this.state='lost'; return this.state; } }
|
||||
}
|
||||
if(this.state==='playing'||this.state==='possessed'){
|
||||
achCheck();
|
||||
if(this.state==='possessed'&&this.player.host&&(this.player.host.overheatLeft||0)>0) this.player.host.overheatLeft--;
|
||||
advanceEnemies();
|
||||
advanceProjectiles();
|
||||
}
|
||||
}
|
||||
return this.state;
|
||||
},
|
||||
save:function(){
|
||||
try{
|
||||
var p=this.player;
|
||||
localStorage.setItem('bodysnatcher_save', JSON.stringify({
|
||||
floor:this.floor, essence:this.essence, upgrades:this.upgrades, state:this.state,
|
||||
grid:this.grid, player:{x:p.x,y:p.y,timer:p.timer,ghost:p.ghost,facing:p.facing}
|
||||
}));
|
||||
}catch(e){}
|
||||
return true;
|
||||
},
|
||||
load:function(){
|
||||
try{
|
||||
var raw=localStorage.getItem('bodysnatcher_save'); if(!raw) return false;
|
||||
var d=JSON.parse(raw);
|
||||
this.floor=d.floor||1; this.essence=d.essence||0; this.upgrades=d.upgrades||{};
|
||||
this.grid = d.grid ? d.grid : buildDungeon();
|
||||
this.explored=rebuildExplored();
|
||||
var dp=d.player||{};
|
||||
var px=dp.x!=null?dp.x:SPAWN.x, py=dp.y!=null?dp.y:SPAWN.y;
|
||||
this.player={x:px,y:py,rx:px,ry:py,ghost:true,timer:dp.timer!=null?dp.timer:ghostCap(),
|
||||
host:null,facing:dp.facing||{x:0,y:1},fromX:px,fromY:py,moveT:1};
|
||||
this.enemies=[]; this.projectiles=[];
|
||||
this.state = (d.state==='playing'||d.state==='possessed') ? d.state : 'playing';
|
||||
updateFog();
|
||||
}catch(e){}
|
||||
return true;
|
||||
},
|
||||
addEssence:function(n){ addEssence(n); return this.essence; },
|
||||
playSound:function(t){ sfx(t); }
|
||||
};
|
||||
|
||||
function keyDir(k){
|
||||
if(k==='ArrowUp'||k==='w'||k==='W') return {dx:0,dy:-1};
|
||||
if(k==='ArrowDown'||k==='s'||k==='S') return {dx:0,dy:1};
|
||||
if(k==='ArrowLeft'||k==='a'||k==='A') return {dx:-1,dy:0};
|
||||
if(k==='ArrowRight'||k==='d'||k==='D') return {dx:1,dy:0};
|
||||
return null;
|
||||
}
|
||||
function tryMove(dx,dy){
|
||||
var p=GAME.player; p.facing={x:dx,y:dy};
|
||||
var nx=p.x+dx, ny=p.y+dy;
|
||||
if(nx<0||ny<0||nx>=COLS||ny>=ROWS) return;
|
||||
if(isSolid(GAME.grid[ny][nx])) return;
|
||||
p.fromX=p.x; p.fromY=p.y; p.x=nx; p.y=ny; p.moveT=0; if(p.host){ p.host.x=nx; p.host.y=ny; p.host.fromX=p.fromX; p.host.fromY=p.fromY; p.host.moveT=0; }
|
||||
updateFog();
|
||||
}
|
||||
function rotate(s){ var f=GAME.player.facing; if(s>0){var nx=-f.y,ny=f.x;f.x=nx;f.y=ny;}else{var a=f.y,b=-f.x;f.x=a;f.y=b;} }
|
||||
|
||||
/* ===== Phase 2: possession, enemy AI, pathfinding, combat, audio ===== */
|
||||
var AGGRO=6, GHOST_HIT_PENALTY=1.0;
|
||||
var audioCtx=null;
|
||||
function ensureAudio(){ if(audioCtx) return audioCtx; try{ var AC=window.AudioContext||window.webkitAudioContext; if(AC) audioCtx=new AC(); }catch(e){ audioCtx=null; } return audioCtx; }
|
||||
function sfx(type){
|
||||
try{
|
||||
var ac=ensureAudio(); if(!ac) return;
|
||||
var now=ac.currentTime||0, o=ac.createOscillator(), g=ac.createGain();
|
||||
o.connect(g); g.connect(ac.destination);
|
||||
var f=440,d=0.08,w='square',v=0.05;
|
||||
if(type==='hit'){f=170;d=0.07;v=0.07;}
|
||||
else if(type==='possess'){f=520;d=0.18;w='sine';v=0.07;}
|
||||
else if(type==='eject'){f=260;d=0.16;w='sawtooth';v=0.06;}
|
||||
else if(type==='shot'){f=700;d=0.05;v=0.05;}
|
||||
else if(type==='death'){f=110;d=0.22;w='sawtooth';v=0.08;}
|
||||
else if(type==='pickup'){f=880;d=0.06;w='triangle';v=0.06;}
|
||||
else if(type==='blip'){f=300;d=0.03;v=0.03;}
|
||||
o.type=w; try{o.frequency.setValueAtTime(f,now);}catch(e){}
|
||||
try{g.gain.setValueAtTime(v,now); g.gain.exponentialRampToValueAtTime(0.0001,now+d);}catch(e){}
|
||||
try{o.start(now); o.stop(now+d);}catch(e){}
|
||||
}catch(e){}
|
||||
}
|
||||
function unlockAch(n){ if(!GAME.achievements[n]){ GAME.achievements[n]=true; sfx('pickup'); } }
|
||||
function achCheck(){ if(GAME.essence>=30) unlockAch('Essence Hoarder'); if(GAME.floor>=7) unlockAch('Deep Diver'); }
|
||||
|
||||
function lineOfSight(x0,y0,x1,y1){
|
||||
var dx=Math.abs(x1-x0), dy=Math.abs(y1-y0), sx=x0<x1?1:-1, sy=y0<y1?1:-1;
|
||||
var err=dx-dy, cx=x0, cy=y0;
|
||||
while(!(cx===x1&&cy===y1)){
|
||||
var e2=2*err;
|
||||
if(e2>-dy){err-=dy;cx+=sx;}
|
||||
if(e2<dx){err+=dx;cy+=sy;}
|
||||
if(cx===x1&&cy===y1) break;
|
||||
if(cx<0||cy<0||cx>=COLS||cy>=ROWS) return false;
|
||||
if(isSolid(GAME.grid[cy][cx])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function bfsFirstStep(sx,sy,tx,ty){
|
||||
if(sx===tx&&sy===ty) return null;
|
||||
var W=COLS,H=ROWS,y;
|
||||
var seen=[],prevX=[],prevY=[];
|
||||
for(y=0;y<H;y++){ seen.push(new Array(W).fill(false)); prevX.push(new Array(W).fill(-1)); prevY.push(new Array(W).fill(-1)); }
|
||||
var qx=[sx],qy=[sy]; seen[sy][sx]=true; var found=false;
|
||||
while(qx.length){
|
||||
var cx=qx.shift(),cy=qy.shift();
|
||||
if(cx===tx&&cy===ty){found=true;break;}
|
||||
var nbs=[[1,0],[-1,0],[0,1],[0,-1]];
|
||||
for(var k=0;k<4;k++){
|
||||
var nx=cx+nbs[k][0],ny=cy+nbs[k][1];
|
||||
if(nx<0||ny<0||nx>=W||ny>=H) continue;
|
||||
if(seen[ny][nx]) continue;
|
||||
if(isSolid(GAME.grid[ny][nx])) continue;
|
||||
seen[ny][nx]=true; prevX[ny][nx]=cx; prevY[ny][nx]=cy; qx.push(nx); qy.push(ny);
|
||||
}
|
||||
}
|
||||
if(!found) return null;
|
||||
var px2=tx, py2=ty;
|
||||
while(!(prevX[py2][px2]===sx&&prevY[py2][px2]===sy)){
|
||||
var pa=prevX[py2][px2], pb=prevY[py2][px2];
|
||||
if(pa<0) return null;
|
||||
if(pa===sx&&pb===sy) break;
|
||||
px2=pa; py2=pb;
|
||||
}
|
||||
return {x:px2,y:py2};
|
||||
}
|
||||
function enemyAt(x,y){ for(var i=0;i<GAME.enemies.length;i++){var e=GAME.enemies[i]; if(e.x===x&&e.y===y) return e;} return null; }
|
||||
function addEssence(n){ GAME.essence+=n; achCheck(); }
|
||||
function dropEssence(e){ var d=ENEMIES[e.type]; if(d) addEssence(d.essence); sfx('pickup'); }
|
||||
|
||||
function damageEnemy(e,n){
|
||||
if(!e||e===GAME.player.host) return;
|
||||
e.hp-=n; e.hitFlash=1; sfx('hit');
|
||||
if(e.hp<=0){ e.hp=0; dropEssence(e); var i=GAME.enemies.indexOf(e); if(i>=0) GAME.enemies.splice(i,1); }
|
||||
}
|
||||
function damagePlayer(n){
|
||||
var p=GAME.player;
|
||||
if(p.ghost){ p.timer-=GHOST_HIT_PENALTY; sfx('hit'); if(p.timer<=0){ p.timer=0; GAME.state='lost'; } }
|
||||
else if(p.host){ p.host.hp-=n; p.host.hitFlash=1; sfx('hit'); if(p.host.hp<=0){ p.host.hp=0; ejectOnDeath(); } }
|
||||
}
|
||||
function moveEnemyTo(e,x,y){ e.fromX=e.x; e.fromY=e.y; e.x=x; e.y=y; e.moveT=0; }
|
||||
|
||||
function tryPossess(){
|
||||
var p=GAME.player; if(!p.ghost) return;
|
||||
var range=(GAME.upgrades&&GAME.upgrades.ghostT2)?2:1;
|
||||
for(var dy=-range;dy<=range;dy++) for(var dx=-range;dx<=range;dx++){
|
||||
if(dx===0&&dy===0) continue;
|
||||
if(Math.abs(dx)+Math.abs(dy)>range) continue;
|
||||
var e=enemyAt(p.x+dx,p.y+dy);
|
||||
if(e&&e!==p.host&&(e.lockout||0)<=0){ p.possessing=e; sfx('possess'); return; }
|
||||
}
|
||||
}
|
||||
function completePossession(e){
|
||||
var p=GAME.player;
|
||||
p.host=e; p.ghost=false; p.possessing=null;
|
||||
e.aggroed=false; e.pacified=0;
|
||||
p.x=e.x; p.y=e.y; p.fromX=e.x; p.fromY=e.y; p.rx=e.x; p.ry=e.y; p.moveT=1;
|
||||
GAME.state='possessed'; updateFog();
|
||||
if(!GAME._possessedTypes) GAME._possessedTypes={};
|
||||
GAME._possessedTypes[e.type]=1;
|
||||
var cnt=0; for(var kk in GAME._possessedTypes) cnt++;
|
||||
unlockAch('First Possession');
|
||||
if(cnt>=5) unlockAch('Body Hopper');
|
||||
sfx('possess');
|
||||
}
|
||||
function abandonHost(){
|
||||
var p=GAME.player; if(!p.host) return;
|
||||
var h=p.host; h.pacified=2; h.lockout=2; h.aggroed=false;
|
||||
p.host=null; p.ghost=true; p.possessing=null;
|
||||
GAME.state='playing'; sfx('eject');
|
||||
}
|
||||
function ejectOnDeath(){
|
||||
var p=GAME.player;
|
||||
if(p.host){ var idx=GAME.enemies.indexOf(p.host); if(idx>=0) GAME.enemies.splice(idx,1); p.host=null; }
|
||||
p.ghost=true; p.timer=ghostCap(); p.possessing=null;
|
||||
GAME.state='playing'; sfx('eject');
|
||||
}
|
||||
function hostAttack(){
|
||||
var p=GAME.player; if(!p.host) return; var h=p.host;
|
||||
if(h.type==='sentinel'){
|
||||
if((h.overheatLeft||0)>0){ sfx('blip'); return; }
|
||||
GAME.projectiles.push({x:p.x,y:p.y,rx:p.rx,ry:p.ry,vx:p.facing.x,vy:p.facing.y,damage:h.damage,from:'player',life:14});
|
||||
h.burstCount=(h.burstCount||0)+1; h.shotsFired=(h.shotsFired||0)+1;
|
||||
if(h.burstCount>=3){ h.burstCount=0; h.overheatLeft=3; }
|
||||
sfx('shot');
|
||||
} else {
|
||||
var en=enemyAt(p.x+p.facing.x,p.y+p.facing.y);
|
||||
if(en&&en!==h){ damageEnemy(en,h.damage); }
|
||||
sfx('hit');
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- enemy AI: calm baseline, aggro+LOS gated, no friendly fire ---- */
|
||||
function advanceEnemies(){
|
||||
var p=GAME.player;
|
||||
for(var i=0;i<GAME.enemies.length;i++){
|
||||
var e=GAME.enemies[i];
|
||||
if(e===p.host) continue;
|
||||
if(e.hitFlash>0) e.hitFlash=Math.max(0,e.hitFlash-0.25);
|
||||
if(e.pacified>0){ e.pacified--; if(e.lockout>0) e.lockout--; continue; }
|
||||
if(e.lockout>0) e.lockout--;
|
||||
var dist=Math.abs(e.x-p.x)+Math.abs(e.y-p.y);
|
||||
var los=lineOfSight(e.x,e.y,p.x,p.y);
|
||||
if(!e.aggroed){ if(dist<=AGGRO&&los) e.aggroed=true; }
|
||||
if(e.moveCd>0) e.moveCd--;
|
||||
if(e.type==='sentinel') sentinelAI(e,p,dist);
|
||||
else meleeChase(e,p,dist);
|
||||
}
|
||||
}
|
||||
function meleeChase(e,p,dist){
|
||||
if(!e.aggroed) return;
|
||||
if(e.moveCd>0) return;
|
||||
if(dist<=1){ damagePlayer(e.damage); e.moveCd=e.speed; return; }
|
||||
if(e.speed>0){
|
||||
var step=bfsFirstStep(e.x,e.y,p.x,p.y);
|
||||
if(step&&!(step.x===p.x&&step.y===p.y)&&!enemyAt(step.x,step.y)){ moveEnemyTo(e,step.x,step.y); }
|
||||
e.moveCd=e.speed;
|
||||
}
|
||||
}
|
||||
function sentinelAI(e,p,dist){
|
||||
if(!e.aggroed) return;
|
||||
if(e.overheatLeft>0){ e.overheatLeft--; return; }
|
||||
var dx=Math.sign(p.x-e.x), dy=Math.sign(p.y-e.y);
|
||||
if(dx===0&&dy===0) dx=1;
|
||||
GAME.projectiles.push({x:e.x,y:e.y,rx:(e.rx!=null?e.rx:e.x),ry:(e.ry!=null?e.ry:e.y),vx:dx,vy:dy,damage:e.damage,from:'enemy',life:14});
|
||||
e.burstCount=(e.burstCount||0)+1; e.shotsFired=(e.shotsFired||0)+1;
|
||||
if(e.burstCount>=3){ e.burstCount=0; e.overheatLeft=3; }
|
||||
sfx('shot');
|
||||
}
|
||||
function advanceProjectiles(){
|
||||
var p=GAME.player;
|
||||
for(var i=GAME.projectiles.length-1;i>=0;i--){
|
||||
var pr=GAME.projectiles[i];
|
||||
pr.x+=pr.vx; pr.y+=pr.vy; pr.life--; pr.rx=pr.x; pr.ry=pr.y;
|
||||
if(pr.x<0||pr.y<0||pr.x>=COLS||pr.y>=ROWS||isSolid(GAME.grid[pr.y][pr.x])){ GAME.projectiles.splice(i,1); continue; }
|
||||
if(pr.from==='player'){ var en=enemyAt(pr.x,pr.y); if(en&&en!==p.host){ damageEnemy(en,pr.damage); GAME.projectiles.splice(i,1); continue; } }
|
||||
else { if(pr.x===p.x&&pr.y===p.y){ damagePlayer(pr.damage); GAME.projectiles.splice(i,1); continue; } }
|
||||
if(pr.life<=0) GAME.projectiles.splice(i,1);
|
||||
}
|
||||
}
|
||||
function populateFloor(){
|
||||
var pts=[['brute',14,4],['brute',12,12],['skitterer',4,12],['sentinel',20,5]];
|
||||
for(var i=0;i<pts.length;i++){ var t=pts[i]; if(t[1]>=0&&t[1]<COLS&&t[2]>=0&&t[2]<ROWS&&!isSolid(GAME.grid[t[2]][t[1]])) GAME.spawn(t[0],t[1],t[2]); }
|
||||
}
|
||||
|
||||
/* ============================ RENDERING ================================ */
|
||||
function smoothstep(e0,e1,x){ var t=Math.max(0,Math.min(1,(x-e0)/(e1-e0))); return t*t*(3-2*t); }
|
||||
function ease(t){ t=Math.max(0,Math.min(1,t)); return 1-(1-t)*(1-t); }
|
||||
function panel(x,y,w,h){
|
||||
ctx.fillStyle='rgba(10,14,26,0.88)'; ctx.fillRect(x,y,w,h);
|
||||
ctx.lineWidth=2; ctx.strokeStyle='rgba(130,160,220,0.55)'; ctx.strokeRect(x+1,y+1,w-2,h-2);
|
||||
ctx.lineWidth=1; ctx.strokeStyle='rgba(80,110,170,0.25)'; ctx.strokeRect(x+5,y+5,w-10,h-10);
|
||||
}
|
||||
|
||||
function drawFloor(px,py,x,y){
|
||||
var g=ctx.createLinearGradient(px,py,px+TILE,py+TILE);
|
||||
g.addColorStop(0,'#26222e'); g.addColorStop(0.5,'#1c1923'); g.addColorStop(1,'#15131b');
|
||||
ctx.fillStyle=g; ctx.fillRect(px,py,TILE,TILE);
|
||||
ctx.strokeStyle='rgba(0,0,0,0.4)'; ctx.lineWidth=1; ctx.strokeRect(px+0.5,py+0.5,TILE-1,TILE-1);
|
||||
ctx.strokeStyle='rgba(255,240,210,0.04)'; ctx.strokeRect(px+1.5,py+1.5,TILE-3,TILE-3);
|
||||
ctx.strokeStyle='rgba(0,0,0,0.16)';
|
||||
ctx.beginPath(); ctx.moveTo(px+TILE/2,py+4); ctx.lineTo(px+TILE/2,py+TILE-4);
|
||||
ctx.moveTo(px+4,py+TILE/2); ctx.lineTo(px+TILE-4,py+TILE/2); ctx.stroke();
|
||||
}
|
||||
function drawWall(px,py,x,y){
|
||||
var g=ctx.createLinearGradient(px,py,px,py+TILE);
|
||||
g.addColorStop(0,'#4c4759'); g.addColorStop(0.18,'#3c3747'); g.addColorStop(1,'#201d2a');
|
||||
ctx.fillStyle=g; ctx.fillRect(px,py,TILE,TILE);
|
||||
ctx.fillStyle='rgba(190,180,210,0.18)'; ctx.fillRect(px,py,TILE,3);
|
||||
ctx.fillStyle='rgba(0,0,0,0.5)'; ctx.fillRect(px,py+TILE-4,TILE,4);
|
||||
ctx.fillStyle='rgba(255,255,255,0.05)'; ctx.fillRect(px,py,2,TILE);
|
||||
ctx.fillStyle='rgba(0,0,0,0.28)'; ctx.fillRect(px+TILE-2,py,2,TILE);
|
||||
ctx.strokeStyle='rgba(0,0,0,0.45)'; ctx.lineWidth=1; ctx.strokeRect(px+0.5,py+0.5,TILE-1,TILE-1);
|
||||
var s=(x*37+y*53)%3;
|
||||
ctx.beginPath();
|
||||
if(s===0){ ctx.moveTo(px+8,py+6); ctx.lineTo(px+14,py+16); ctx.lineTo(px+12,py+26); }
|
||||
else if(s===1){ ctx.moveTo(px+23,py+6); ctx.lineTo(px+18,py+21); }
|
||||
else { ctx.moveTo(px+6,py+23); ctx.lineTo(px+21,py+25); }
|
||||
ctx.strokeStyle='rgba(0,0,0,0.3)'; ctx.stroke();
|
||||
}
|
||||
function drawExit(px,py){
|
||||
var cx=px+TILE/2, cy=py+TILE/2, pulse=0.5+0.5*Math.sin(time*0.004);
|
||||
var rg=ctx.createRadialGradient(cx,cy,2,cx,cy,TILE);
|
||||
rg.addColorStop(0,'rgba(130,235,255,'+(0.55+0.3*pulse)+')');
|
||||
rg.addColorStop(0.5,'rgba(60,150,225,'+(0.25+0.15*pulse)+')');
|
||||
rg.addColorStop(1,'rgba(20,40,90,0)');
|
||||
ctx.fillStyle=rg; ctx.fillRect(px-TILE,py-TILE,TILE*3,TILE*3);
|
||||
ctx.fillStyle='#0c1424'; ctx.fillRect(px+4,py+4,TILE-8,TILE-8);
|
||||
for(var i=0;i<4;i++){ ctx.fillStyle='rgba(150,215,255,'+(0.3+0.1*i)+')'; ctx.fillRect(px+6+i*2,py+8+i*4,TILE-12-i*4,3); }
|
||||
ctx.strokeStyle='rgba(185,240,255,'+(0.6+0.3*pulse)+')'; ctx.lineWidth=1.5;
|
||||
ctx.strokeRect(px+10,py+10,TILE-20,TILE-20);
|
||||
ctx.beginPath(); ctx.moveTo(px+12,cy); ctx.lineTo(px+TILE-12,cy);
|
||||
ctx.moveTo(cx,py+12); ctx.lineTo(cx,py+TILE-12); ctx.stroke();
|
||||
}
|
||||
function drawDoor(px,py){
|
||||
drawFloor(px,py,0,0);
|
||||
ctx.fillStyle='#5a3a22'; ctx.fillRect(px+6,py+8,4,TILE-16); ctx.fillRect(px+TILE-10,py+8,4,TILE-16);
|
||||
ctx.fillStyle='#7a5230'; ctx.fillRect(px+10,py+9,TILE-20,TILE-18);
|
||||
ctx.fillStyle='#3a2414'; ctx.fillRect(px+TILE/2-1,py+9,2,TILE-18);
|
||||
ctx.fillStyle='#d9b048'; ctx.beginPath(); ctx.arc(px+TILE/2+4,py+TILE/2,1.6,0,Math.PI*2); ctx.fill();
|
||||
}
|
||||
|
||||
function drawDungeon(){
|
||||
var p=GAME.player;
|
||||
for(var y=0;y<ROWS;y++) for(var x=0;x<COLS;x++){
|
||||
if(!GAME.explored[y][x]) continue;
|
||||
var d=Math.hypot(x-p.x,y-p.y), visible=d<=VIEW;
|
||||
var t=GAME.grid[y][x], px=x*TILE, py=y*TILE;
|
||||
if(t===1) drawWall(px,py,x,y);
|
||||
else if(t===3) drawExit(px,py);
|
||||
else if(t===2) drawDoor(px,py);
|
||||
else drawFloor(px,py,x,y);
|
||||
if(visible){
|
||||
var edge=smoothstep(VIEW-1.8,VIEW,d);
|
||||
if(edge>0){ ctx.fillStyle='rgba(2,3,8,'+(edge*0.55)+')'; ctx.fillRect(px,py,TILE,TILE); }
|
||||
} else {
|
||||
ctx.fillStyle='rgba(18,26,46,0.62)'; ctx.fillRect(px,py,TILE,TILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
function drawEnemy(e){
|
||||
var px=e.rx*TILE+TILE/2, py=e.ry*TILE+TILE/2, bob=Math.sin(time*0.005+e.x)*1.2;
|
||||
ctx.fillStyle='rgba(0,0,0,0.32)'; ctx.beginPath(); ctx.ellipse(px,py+12,10,4,0,0,Math.PI*2); ctx.fill();
|
||||
var bg=ctx.createRadialGradient(px,py+bob-3,2,px,py+bob,13);
|
||||
bg.addColorStop(0,shade(e.color,1.25)); bg.addColorStop(0.6,e.color); bg.addColorStop(1,shade(e.color,0.5));
|
||||
ctx.fillStyle=bg; ctx.beginPath(); ctx.arc(px,py+bob,11,0,Math.PI*2); ctx.fill();
|
||||
ctx.fillStyle='rgba(255,255,255,0.18)'; ctx.beginPath(); ctx.arc(px-3,py+bob-4,3.5,0,Math.PI*2); ctx.fill();
|
||||
ctx.fillStyle='#0c1018'; ctx.beginPath(); ctx.arc(px-3.5,py+bob-1,1.5,0,Math.PI*2); ctx.arc(px+3.5,py+bob-1,1.5,0,Math.PI*2); ctx.fill();
|
||||
}
|
||||
function drawEnemies(){ for(var i=0;i<GAME.enemies.length;i++){ if(GAME.enemies[i]===GAME.player.host) continue; drawEnemy(GAME.enemies[i]); } }
|
||||
function drawProjectiles(){ for(var i=0;i<GAME.projectiles.length;i++){ var p=GAME.projectiles[i]; ctx.fillStyle='#ffd36b'; ctx.beginPath(); ctx.arc(p.rx*TILE+TILE/2,p.ry*TILE+TILE/2,3,0,Math.PI*2); ctx.fill(); } }
|
||||
|
||||
function drawPlayer(){
|
||||
var p=GAME.player; if(!p) return;
|
||||
if(!p.ghost&&p.host){ var h=p.host; h.rx=p.rx; h.ry=p.ry; var hx=p.rx*TILE+TILE/2, hy=p.ry*TILE+TILE/2; var au=ctx.createRadialGradient(hx,hy,4,hx,hy,26); au.addColorStop(0,'rgba(150,220,255,0.42)'); au.addColorStop(1,'rgba(120,200,255,0)'); ctx.fillStyle=au; ctx.fillRect(hx-28,hy-28,56,56); drawEnemy(h); return; }
|
||||
ctx.fillStyle='rgba(0,0,0,0.3)'; ctx.beginPath(); ctx.ellipse(px,py+12,10,4,0,0,Math.PI*2); ctx.fill();
|
||||
var ag=ctx.createRadialGradient(px,py+bob,2,px,py+bob,22);
|
||||
ag.addColorStop(0,'rgba(180,230,255,0.38)'); ag.addColorStop(1,'rgba(120,200,255,0)');
|
||||
ctx.fillStyle=ag; ctx.fillRect(px-24,py+bob-24,48,48);
|
||||
ctx.save(); ctx.globalAlpha=0.88;
|
||||
var bg=ctx.createRadialGradient(px,py+bob-2,2,px,py+bob,13);
|
||||
bg.addColorStop(0,'rgba(238,247,255,0.96)'); bg.addColorStop(0.6,'rgba(172,212,246,0.6)'); bg.addColorStop(1,'rgba(120,170,230,0.04)');
|
||||
ctx.fillStyle=bg;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(px-9,py+bob-2);
|
||||
ctx.quadraticCurveTo(px-11,py+bob-14,px,py+bob-15);
|
||||
ctx.quadraticCurveTo(px+11,py+bob-14,px+9,py+bob-2);
|
||||
ctx.quadraticCurveTo(px+7,py+bob+9,px+3,py+bob+5);
|
||||
ctx.quadraticCurveTo(px,py+bob+13,px-3,py+bob+5);
|
||||
ctx.quadraticCurveTo(px-7,py+bob+9,px-9,py+bob-2);
|
||||
ctx.closePath(); ctx.fill();
|
||||
ctx.restore();
|
||||
var fx=p.facing.x, fy=p.facing.y;
|
||||
ctx.fillStyle='#cfeeff';
|
||||
ctx.beginPath(); ctx.arc(px-3.6,py+bob-6,1.9,0,Math.PI*2); ctx.arc(px+3.6,py+bob-6,1.9,0,Math.PI*2); ctx.fill();
|
||||
ctx.fillStyle='#16242f';
|
||||
ctx.beginPath(); ctx.arc(px-3.6+fx*1.2,py+bob-6+fy*1.2,0.95,0,Math.PI*2); ctx.arc(px+3.6+fx*1.2,py+bob-6+fy*1.2,0.95,0,Math.PI*2); ctx.fill();
|
||||
}
|
||||
function drawLighting(){
|
||||
var W=canvas.width,H=canvas.height, p=GAME.player;
|
||||
var cx=p.rx*TILE+TILE/2, cy=p.ry*TILE+TILE/2;
|
||||
var tg=ctx.createRadialGradient(cx,cy,40,cx,cy,380);
|
||||
tg.addColorStop(0,'rgba(255,200,120,0.10)'); tg.addColorStop(1,'rgba(255,180,90,0)');
|
||||
ctx.fillStyle=tg; ctx.fillRect(0,0,W,H);
|
||||
var vg=ctx.createRadialGradient(W/2,H/2,H*0.32,W/2,H/2,H*0.82);
|
||||
vg.addColorStop(0,'rgba(0,0,0,0)'); vg.addColorStop(1,'rgba(0,0,0,0.62)');
|
||||
ctx.fillStyle=vg; ctx.fillRect(0,0,W,H);
|
||||
}
|
||||
function drawHUD(){
|
||||
var W=canvas.width, p=GAME.player;
|
||||
ctx.textBaseline='middle'; ctx.textAlign='left';
|
||||
ctx.fillStyle='rgba(8,10,18,0.85)'; ctx.fillRect(0,0,W,34);
|
||||
ctx.fillStyle='rgba(120,150,210,0.5)'; ctx.fillRect(0,34,W,2);
|
||||
ctx.font='bold 12px "Trebuchet MS",sans-serif';
|
||||
ctx.fillStyle='#8294b0'; ctx.fillText('BODY',12,17);
|
||||
ctx.fillStyle = p.ghost?'#6f7e96':'#e74c3c';
|
||||
ctx.fillText(p.ghost?'N/A (Ghost)':('HP '+Math.max(0,Math.ceil(p.host&&p.host.hp))+'/'+(p.host&&p.host.maxHp)),50,17);
|
||||
ctx.fillStyle='#8294b0'; ctx.fillText('TIMER',150,17);
|
||||
var low=p.timer<=5;
|
||||
ctx.fillStyle=low?'#e67e22':'#7fd8ff'; ctx.font='bold 15px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText(p.timer.toFixed(1)+'s',198,17);
|
||||
ctx.font='bold 12px "Trebuchet MS",sans-serif';
|
||||
ctx.fillStyle='#8294b0'; ctx.fillText('ESSENCE',272,17);
|
||||
ctx.fillStyle='#f1c40f'; ctx.fillText(String(GAME.essence),340,17);
|
||||
ctx.fillStyle='#8294b0'; ctx.fillText('FLOOR',390,17);
|
||||
ctx.fillStyle='#bcaefs'; ctx.fillText(GAME.floor+'/10',432,17);
|
||||
var act=p.ghost?'Possess':(p.host&&p.host.type==='sentinel'?'Fire burst':(p.host&&p.host.type==='skitterer'?'Rapid strike':'Heavy swing'));
|
||||
ctx.fillStyle='#8fe0b0'; ctx.fillText(p.ghost?'SPACE: '+act:'SPACE: '+act,498,17);
|
||||
if(!p.ghost){ ctx.fillStyle='#e2c04a'; ctx.fillText('X: Abandon',610,17); }
|
||||
ctx.fillStyle='#6c7a93'; ctx.font='10px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText('Q/E face X abandon ESC pause L bestiary',640,17);
|
||||
}
|
||||
|
||||
function drawTitleGhost(cx,cy){
|
||||
var bob=Math.sin(time*0.004)*3;
|
||||
var ag=ctx.createRadialGradient(cx,cy+bob,4,cx,cy+bob,60);
|
||||
ag.addColorStop(0,'rgba(180,230,255,0.35)'); ag.addColorStop(1,'rgba(120,200,255,0)');
|
||||
ctx.fillStyle=ag; ctx.fillRect(cx-70,cy+bob-70,140,140);
|
||||
ctx.save(); ctx.globalAlpha=0.92;
|
||||
var bg=ctx.createRadialGradient(cx,cy+bob-4,3,cx,cy+bob,34);
|
||||
bg.addColorStop(0,'rgba(240,248,255,0.97)'); bg.addColorStop(0.6,'rgba(170,212,246,0.6)'); bg.addColorStop(1,'rgba(120,170,230,0.03)');
|
||||
ctx.fillStyle=bg;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cx-24,cy+bob-4);
|
||||
ctx.quadraticCurveTo(cx-30,cy+bob-38,cx,cy+bob-40);
|
||||
ctx.quadraticCurveTo(cx+30,cy+bob-38,cx+24,cy+bob-4);
|
||||
ctx.quadraticCurveTo(cx+18,cy+bob+22,cx+8,cy+bob+12);
|
||||
ctx.quadraticCurveTo(cx,cy+bob+32,cx-8,cy+bob+12);
|
||||
ctx.quadraticCurveTo(cx-18,cy+bob+22,cx-24,cy+bob-4);
|
||||
ctx.closePath(); ctx.fill();
|
||||
ctx.restore();
|
||||
ctx.fillStyle='#dff4ff';
|
||||
ctx.beginPath(); ctx.arc(cx-9,cy+bob-14,5,0,Math.PI*2); ctx.arc(cx+9,cy+bob-14,5,0,Math.PI*2); ctx.fill();
|
||||
ctx.fillStyle='#16242f';
|
||||
ctx.beginPath(); ctx.arc(cx-9,cy+bob-13,2.4,0,Math.PI*2); ctx.arc(cx+9,cy+bob-13,2.4,0,Math.PI*2); ctx.fill();
|
||||
}
|
||||
function drawTitle(){
|
||||
var W=canvas.width,H=canvas.height;
|
||||
var bg=ctx.createLinearGradient(0,0,0,H); bg.addColorStop(0,'#0a0c16'); bg.addColorStop(1,'#15131f');
|
||||
ctx.fillStyle=bg; ctx.fillRect(0,0,W,H);
|
||||
var ag=ctx.createRadialGradient(W/2,H*0.30,20,W/2,H*0.30,380);
|
||||
ag.addColorStop(0,'rgba(120,170,240,0.18)'); ag.addColorStop(1,'rgba(0,0,0,0)');
|
||||
ctx.fillStyle=ag; ctx.fillRect(0,0,W,H);
|
||||
ctx.textAlign='center'; ctx.textBaseline='alphabetic';
|
||||
ctx.font='bold 52px "Trebuchet MS",sans-serif'; ctx.fillStyle='#d2e2ff';
|
||||
ctx.fillText('BODY SNATCHER', W/2, 104);
|
||||
ctx.font='italic 15px "Trebuchet MS",sans-serif'; ctx.fillStyle='#7fa8d8';
|
||||
ctx.fillText('Possess. Survive. Descend.', W/2, 130);
|
||||
drawTitleGhost(W/2,182);
|
||||
var pw=440, ph=204, px=(W-pw)/2, py=238;
|
||||
panel(px,py,pw,ph);
|
||||
ctx.textAlign='left'; ctx.textBaseline='middle';
|
||||
var rows=[
|
||||
['WASD / Arrows','Move (hold to keep moving)'],
|
||||
['SPACE','Possess (ghost) / Attack (host)'],
|
||||
['Q / E','Rotate facing for Shielder / Turret'],
|
||||
['X','Abandon host, eject as ghost'],
|
||||
['ENTER','Start run / confirm choice'],
|
||||
['ESC','Pause / resume']
|
||||
];
|
||||
for(var i=0;i<rows.length;i++){
|
||||
var ry=py+38+i*24;
|
||||
ctx.fillStyle='#f5d97a'; ctx.font='bold 13px "Trebuchet MS",sans-serif'; ctx.fillText(rows[i][0], px+24, ry);
|
||||
ctx.fillStyle='#9fb2cc'; ctx.font='13px "Trebuchet MS",sans-serif'; ctx.fillText(rows[i][1], px+150, ry);
|
||||
}
|
||||
ctx.textAlign='center';
|
||||
ctx.fillStyle='#8fe0b0'; ctx.font='13px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText('Press L for the Enemy Bestiary', W/2, py+ph+24);
|
||||
var pulse=0.5+0.5*Math.sin(time*0.005);
|
||||
ctx.fillStyle='rgba(185,222,255,'+(0.6+0.4*pulse)+')'; ctx.font='bold 16px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText('Press ENTER to begin', W/2, py+ph+52);
|
||||
}
|
||||
function drawLegend(){
|
||||
var W=canvas.width,H=canvas.height;
|
||||
ctx.fillStyle='rgba(4,6,12,0.94)'; ctx.fillRect(0,0,W,H);
|
||||
ctx.textAlign='center'; ctx.textBaseline='alphabetic';
|
||||
ctx.fillStyle='#d2e2ff'; ctx.font='bold 26px "Trebuchet MS",sans-serif'; ctx.fillText('ENEMY BESTIARY', W/2, 38);
|
||||
ctx.fillStyle='#7fa8d8'; ctx.font='12px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText('How each foe behaves, and what you gain by possessing it', W/2, 58);
|
||||
var keys=Object.keys(ENEMIES), colW=W/2, rowH=50;
|
||||
ctx.textAlign='left'; ctx.textBaseline='top';
|
||||
for(var i=0;i<keys.length;i++){
|
||||
var col=i%2, row=Math.floor(i/2);
|
||||
var ex=24+col*colW, ey=76+row*rowH, e=ENEMIES[keys[i]];
|
||||
ctx.fillStyle=e.color; ctx.fillRect(ex,ey,14,14);
|
||||
ctx.strokeStyle='rgba(255,255,255,0.25)'; ctx.lineWidth=1; ctx.strokeRect(ex+0.5,ey+0.5,13,13);
|
||||
ctx.fillStyle='#f5d97a'; ctx.font='bold 13px "Trebuchet MS",sans-serif'; ctx.fillText(e.name, ex+22, ey-1);
|
||||
ctx.fillStyle='#d99b9b'; ctx.font='11px "Trebuchet MS",sans-serif'; ctx.fillText('Enemy: '+e.enemy, ex+22, ey+15);
|
||||
ctx.fillStyle='#a6e0a4'; ctx.fillText('Host: '+e.kit, ex+22, ey+29);
|
||||
}
|
||||
ctx.textAlign='center'; ctx.fillStyle='#8fb0d8'; ctx.font='12px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText('Press L or ESC to return', W/2, H-18);
|
||||
}
|
||||
function drawPause(){
|
||||
var W=canvas.width,H=canvas.height;
|
||||
ctx.fillStyle='rgba(4,6,12,0.8)'; ctx.fillRect(0,0,W,H);
|
||||
ctx.textAlign='center'; ctx.textBaseline='alphabetic';
|
||||
ctx.fillStyle='#d2e2ff'; ctx.font='bold 36px "Trebuchet MS",sans-serif'; ctx.fillText('PAUSED', W/2, H/2-26);
|
||||
ctx.fillStyle='#9fb2cc'; ctx.font='14px "Trebuchet MS",sans-serif'; ctx.fillText('ESC: Resume L: Bestiary', W/2, H/2+8);
|
||||
ctx.fillStyle='#7fa8d8'; ctx.font='12px "Trebuchet MS",sans-serif';
|
||||
ctx.fillText('WASD/Arrows move SPACE act Q/E face X abandon', W/2, H/2+32);
|
||||
}
|
||||
function drawEnd(title,color,sub){
|
||||
var W=canvas.width,H=canvas.height;
|
||||
ctx.fillStyle='rgba(4,6,12,0.92)'; ctx.fillRect(0,0,W,H);
|
||||
ctx.textAlign='center'; ctx.textBaseline='alphabetic';
|
||||
ctx.fillStyle=color; ctx.font='bold 42px "Trebuchet MS",sans-serif'; ctx.fillText(title, W/2, H/2-6);
|
||||
ctx.fillStyle='#9fb2cc'; ctx.font='15px "Trebuchet MS",sans-serif'; ctx.fillText(sub, W/2, H/2+30);
|
||||
ctx.fillStyle='#7fa8d8'; ctx.font='13px "Trebuchet MS",sans-serif'; ctx.fillText('Press ENTER', W/2, H/2+58);
|
||||
}
|
||||
|
||||
function render(){
|
||||
if(!ctx) return;
|
||||
var W=canvas.width,H=canvas.height;
|
||||
ctx.fillStyle='#05060a'; ctx.fillRect(0,0,W,H);
|
||||
if(GAME.state==='title'){
|
||||
if(GAME.showLegend) drawLegend(); else drawTitle();
|
||||
return;
|
||||
}
|
||||
drawDungeon(); drawEnemies(); drawPlayer(); drawProjectiles(); drawLighting(); drawHUD();
|
||||
if(GAME.showLegend){ drawLegend(); return; }
|
||||
if(GAME.state==='paused') drawPause();
|
||||
else if(GAME.state==='won') drawEnd('YOU ESCAPED','#8fe0b0','Floor '+GAME.floor+' cleared.');
|
||||
else if(GAME.state==='lost') drawEnd('YOUR SOUL FADES','#e74c3c','The dungeon keeps your ghost.');
|
||||
}
|
||||
|
||||
/* ---- color helper (hex lighten/darken) ---- */
|
||||
function shade(hex,f){
|
||||
var c=hex.replace('#',''); if(c.length===3) c=c[0]+c[0]+c[1]+c[1]+c[2]+c[2];
|
||||
var r=parseInt(c.substr(0,2),16), g=parseInt(c.substr(2,2),16), b=parseInt(c.substr(4,2),16);
|
||||
r=Math.max(0,Math.min(255,Math.round(r*f))); g=Math.max(0,Math.min(255,Math.round(g*f))); b=Math.max(0,Math.min(255,Math.round(b*f)));
|
||||
return 'rgb('+r+','+g+','+b+')';
|
||||
}
|
||||
|
||||
/* ============================ LOOP / BOOT ============================== */
|
||||
var time=0, last=0, lastTurn=0, held={};
|
||||
function processHeld(){
|
||||
var order=['ArrowUp','ArrowDown','ArrowLeft','ArrowRight','w','a','s','d'];
|
||||
for(var i=0;i<order.length;i++){ if(held[order[i]]){ GAME.input(order[i]); break; } }
|
||||
}
|
||||
function frame(ts){
|
||||
if(typeof ts==='number'){ time=ts; var p=GAME.player;
|
||||
if(p){ p.moveT=Math.min(1,(p.moveT||1)+(ts-last)/MOVE_MS); var e=ease(p.moveT);
|
||||
p.rx=p.fromX+(p.x-p.fromX)*e; p.ry=p.fromY+(p.y-p.fromY)*e;
|
||||
if(p.moveT>=1){ p.rx=p.x; p.ry=p.y; p.fromX=p.x; p.fromY=p.y; } }
|
||||
var dt=(ts-last)/MOVE_MS;
|
||||
for(var ei=0;ei<GAME.enemies.length;ei++){ var en=GAME.enemies[ei]; en.moveT=Math.min(1,(en.moveT||1)+dt); var ee=ease(en.moveT); en.rx=en.fromX+(en.x-en.fromX)*ee; en.ry=en.fromY+(en.y-en.fromY)*ee; if(en.moveT>=1){ en.rx=en.x; en.ry=en.y; en.fromX=en.x; en.fromY=en.y; } }
|
||||
for(var pi=0;pi<GAME.projectiles.length;pi++){ var pr=GAME.projectiles[pi]; pr.rx=pr.x; pr.ry=pr.y; }
|
||||
if(GAME.state==='playing'||GAME.state==='possessed'){
|
||||
if(ts-lastTurn>=TURN_MS){ lastTurn=ts; processHeld(); GAME.tick(1); }
|
||||
}
|
||||
}
|
||||
last=ts;
|
||||
try{ render(); }catch(e){}
|
||||
try{ requestAnimationFrame(frame); }catch(e){}
|
||||
}
|
||||
|
||||
var canvas=null, ctx=null;
|
||||
try{
|
||||
canvas=document.getElementById('c');
|
||||
if(!canvas && document.createElement){ canvas=document.createElement('canvas'); canvas.width=800; canvas.height=576; }
|
||||
if(canvas && canvas.getContext){ ctx=canvas.getContext('2d'); }
|
||||
}catch(e){ ctx=null; }
|
||||
|
||||
window.GAME=GAME;
|
||||
GAME.start();
|
||||
try{ requestAnimationFrame(frame); }catch(e){}
|
||||
|
||||
try{
|
||||
if(window && window.addEventListener){
|
||||
window.addEventListener('keydown',function(ev){
|
||||
var k=ev.key; if(k==null) return;
|
||||
held[k]=true; GAME.input(k);
|
||||
if(k===' '||k==='ArrowUp'||k==='ArrowDown'||k==='ArrowLeft'||k==='ArrowRight') ev.preventDefault();
|
||||
});
|
||||
window.addEventListener('keyup',function(ev){ held[ev.key]=false; });
|
||||
}
|
||||
}catch(e){}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user