see more...
<script src="epic.js"></script>
<script>
const display = new Display();
display.perform(); // requestAnimationFrame, dual canvas, accurate deltaTime
display.start(800, 600);
display.backgroundColor("#0a0a10");
display.camera.worldWidth = 3000;
display.camera.worldHeight = 2000;
display.clearMargin = [3000, 2000]; // match world size
// ββ FAKE CANVAS β static world (two layers) ββββββββββββββββββββββ
display.tile = [
new Component(64, 64, "#1a3a1a", 0, 0), // 1 = grass
new Component(64, 64, "#2244aa", 0, 0), // 2 = water
new Component(64, 64, "#555555", 0, 0), // 3 = stone
new Component(64, 64, "#228B22", 0, 0), // 4 = tree decoration
];
display.map = [
[1,1,1,2,2,1,1,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,2,2,1,1,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
];
display.tileMap();
display.tileFace.show(0); // layer 0 = ground
// Layer 1 β decoration trees on top
display.tileFace.addMap([
[0,4,0,0,0,4,0,0,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[4,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,4,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
]);
display.tileFace.show(1); // layer 1 = decorations composited on top
// ββ DISPLAY CANVAS β dynamic objects βββββββββββββββββββββββββββββ
const player = new Component(36, 36, "cyan", 400, 200, "rect");
display.add(player);
const ps = new ParticleSystem(display);
const hud = new Tctxt("14px","Arial","white",12,20,
"left",false,"alphabetic","rgba(0,0,0,0.6)",8,4);
hud.setText("WASD to explore");
display.add(hud);
const SPEED = 260;
function update(dt) {
ps.update();
player.speedX = 0; player.speedY = 0;
if (display.keys[87]) player.speedY = -SPEED * dt;
if (display.keys[83]) player.speedY = SPEED * dt;
if (display.keys[65]) player.speedX = -SPEED * dt;
if (display.keys[68]) player.speedX = SPEED * dt;
// Particle trail
move.particles.sparkle(ps, player.x + 18, player.y + 18);
// Camera + sync
display.camera.follow(player, true);
fake.camera.x = display.camera.x;
fake.camera.y = display.camera.y;
// HUD
hud.setText("X:" + Math.floor(player.x) + " Y:" + Math.floor(player.y));
hud.fixed();
}
</script>
β
WASD moves through a 3000Γ2000 two-layer tiled world. Sparkle trail follows the player. HUD shows live coordinates. Camera clamps to world bounds. All static content cached in fake canvas.