<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Princess: A Single Life</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
background: #202b27;
color: white;
font-family: monospace;
display: flex;
flex-direction: column;
align-items: center;
padding: 12px;
}
h2 { color: #f4d99a; margin: 8px; }
#game-container {
width: min(100%, 800px);
border: 5px solid #76563b;
background: #18251d;
position: relative;
}
canvas {
width: 100%;
display: block;
image-rendering: pixelated;
}
#hud {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px;
padding: 10px;
background: #473a32;
font-size: 12px;
}
#message {
min-height: 43px;
padding: 12px;
background: #302a27;
color: #ffe8b7;
font-size: 13px;
text-align: center;
}
.controls {
margin-top: 12px;
text-align: center;
color: #ddd;
font-size: 12px;
line-height: 2;
}
button {
background: #826344;
color: white;
border: 2px solid #c6a477;
border-radius: 5px;
padding: 9px 15px;
margin: 3px;
font-family: monospace;
}
button:active { background: #ad8a5b; }
</style>
</head>
<body>
<h2>Princess: A Single Life</h2>
<div id="game-container">
<div id="hud">
<span>👑 Arabella</span>
<span id="date">Spring 1</span>
<span id="clock">8:00 AM</span>
<span>♡ <span id="hearts">0</span></span>
</div>
<canvas id="game" width="480" height="300"></canvas>
<div id="message">Welcome to Aveloria! Explore the kingdom.</div>
</div>
<div class="controls">
<b>Movement:</b> WASD / Arrow keys<br>
<b>Interact:</b> E <b>Next day:</b> N<br>
<button onclick="moveTouch(0,-1)">▲</button><br>
<button onclick="moveTouch(-1,0)">◀</button>
<button onclick="moveTouch(0,1)">▼</button>
<button onclick="moveTouch(1,0)">▶</button>
<button onclick="interact()">Interact</button>
</div>
<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const TILE = 16;
const WORLD_W = 60;
const WORLD_H = 38;
let keys = {};
let day = 1;
let hour = 8;
let hearts = 0;
let message = "Welcome to Aveloria! Explore the kingdom.";
let lastTime = 0;
let animationTime = 0;
const player = {
x: 15 * TILE,
y: 18 * TILE,
speed: 75,
direction: "down",
moving: false
};
const npcs = [
{
name: "Nicholas",
x: 20 * TILE,
y: 17 * TILE,
color: "#365a9a",
hair: "#493022",
dialogue: [
"Good morning, Princess Arabella!",
"It's a beautiful day in Aveloria.",
"Would you like to walk around the gardens?",
"I hope we can spend more time together."
],
index: 0,
timer: 0
},
{
name: "Charlotte",
x: 25 * TILE,
y: 23 * TILE,
color: "#a65c9c",
hair: "#d7a36a",
dialogue: [
"Arabella! Lovely to see you.",
"Have you visited the town today?",
"There are some beautiful dresses in the shops!"
],
index: 0,
timer: 0
},
{
name: "Royal Guard",
x: 11 * TILE,
y: 14 * TILE,
color: "#536c52",
hair: "#382a24",
dialogue: [
"Good morning, Your Highness.",
"The palace gardens are safe today."
],
index: 0,
timer: 0
}
];
function tile(x, y) {
// Grass background
ctx.fillStyle = ((x + y) % 3 === 0) ? "#78a95e" : "#83b766";
ctx.fillRect(x*TILE, y*TILE, TILE, TILE);
// Tiny grass details
if ((x*7 + y*13) % 9 === 0) {
ctx.fillStyle = "#628f50";
ctx.fillRect(x*TILE+4, y*TILE+10, 2, 2);
}
// Flowers
if ((x*11+y*5)%47===0) {
ctx.fillStyle = "#f5d7ed";
ctx.fillRect(x*TILE+5,y*TILE+5,3,3);
ctx.fillStyle = "#f6d66b";
ctx.fillRect(x*TILE+6,y*TILE+6,2,2);
}
}
function drawPath(x,y,w,h) {
ctx.fillStyle="#c5ad80";
ctx.fillRect(x*TILE,y*TILE,w*TILE,h*TILE);
ctx.fillStyle="#d7c39b";
for(let i=0;i<w*TILE;i+=12)
for(let j=0;j<h*TILE;j+=12)
ctx.fillRect(x*TILE+i,y*TILE+j,7,6);
}
function drawTree(x,y) {
// Tree shadow
ctx.fillStyle="#527a42";
ctx.fillRect(x*TILE+1,y*TILE+12,15,4);
// Trunk
ctx.fillStyle="#80502e";
ctx.fillRect(x*TILE+6,y*TILE+8,5,9);
// Leaves
ctx.fillStyle="#315e39";
ctx.fillRect(x*TILE+1,y*TILE+1,15,10);
ctx.fillStyle="#47874a";
ctx.fillRect(x*TILE+3,y*TILE,10,9);
ctx.fillStyle="#67a657";
ctx.fillRect(x*TILE+5,y*TILE+2,4,4);
}
function drawBuilding(x,y,w,h,name,color) {
// Shadow
ctx.fillStyle="#496044";
ctx.fillRect(x*TILE+4,y*TILE+5,w*TILE,h*TILE);
// Building walls
ctx.fillStyle=color;
ctx.fillRect(x*TILE,y*TILE,w*TILE,h*TILE);
// Roof
ctx.fillStyle="#69434b";
ctx.fillRect(x*TILE-3,y*TILE-5,w*TILE+6,10);
ctx.fillStyle="#98606a";
ctx.fillRect(x*TILE,y*TILE-5,w*TILE,3);
// Windows
ctx.fillStyle="#9ed4dd";
ctx.fillRect(x*TILE+10,y*TILE+15,9,12);
ctx.fillRect(x*TILE+(w-1)*TILE-19,y*TILE+15,9,12);
// Door
ctx.fillStyle="#573c2b";
ctx.fillRect(x*TILE+(w*TILE)/2-5,y*TILE+h*TILE-16,10,16);
// Label
ctx.fillStyle="white";
ctx.font="9px monospace";
ctx.textAlign="center";
ctx.fillText(name,x*TILE+w*TILE/2,y*TILE-9);
}
function drawWorld() {
for(let y=0;y<WORLD_H;y++)
for(let x=0;x<WORLD_W;x++)
tile(x,y);
// Paths
drawPath(5,18,48,3);
drawPath(15,8,3,20);
drawPath(34,17,3,15);
drawPath(42,10,3,20);
// Pond
ctx.fillStyle="#4c9db5";
ctx.fillRect(37*TILE,7*TILE,7*TILE,5*TILE);
ctx.fillStyle="#78c5d1";
ctx.fillRect(38*TILE,8*TILE,4*TILE,1);
ctx.fillRect(40*TILE,10*TILE,2*TILE,1);
// Palace
drawBuilding(7,5,11,6,"ROYAL PALACE","#d9c4a2");
// Town shop
drawBuilding(39,14,7,5,"BOUTIQUE","#d3a1a2");
// Café
drawBuilding(48,14,7,5,"CAFE","#d5b18a");
// Trees
for(let y=2;y<35;y+=3) {
drawTree(2,y);
drawTree(55,y);
}
for(let x=22;x<35;x+=3) {
drawTree(x,5);
drawTree(x,30);
}
// Garden fountain
ctx.fillStyle="#c6c6c6";
ctx.fillRect(24*TILE,13*TILE,4*TILE,4*TILE);
ctx.fillStyle="#61b9ca";
ctx.fillRect(25*TILE,14*TILE,2*TILE,2*TILE);
ctx.fillStyle="#d5d5d5";
ctx.fillRect(26*TILE,12*TILE,1,2);
// Garden flowers
for(let i=0;i<10;i++) {
ctx.fillStyle=i%2===0?"#edb4d0":"#f5df8b";
ctx.fillRect((22+i)*TILE,19*TILE,4,4);
}
}
function drawCharacter(x,y,color,hair,direction,moving,phase) {
const walk = moving ? Math.sin(phase*12)*2 : 0;
const leg = moving ? Math.sin(phase*12)*2 : 0;
// Shadow
ctx.fillStyle="rgba(30,40,25,0.35)";
ctx.fillRect(x+3,y+13,11,3);
// Legs animation
ctx.fillStyle="#483a36";
ctx.fillRect(x+5,y+10+leg,3,5);
ctx.fillRect(x+9,y+10-leg,3,5);
// Dress/body
ctx.fillStyle=color;
ctx.fillRect(x+3,y+5+walk,10,8);
ctx.fillRect(x+1,y+9+walk,14,4);
// Hair
ctx.fillStyle=hair;
ctx.fillRect(x+3,y,10,5);
ctx.fillRect(x+2,y+2,3,5);
ctx.fillRect(x+11,y+2,3,5);
// Face
ctx.fillStyle="#f0c49c";
ctx.fillRect(x+4,y+2,8,5);
// Eyes
ctx.fillStyle="#382d28";
if(direction==="left") {
ctx.fillRect(x+4,y+4,1,1);
} else if(direction==="right") {
ctx.fillRect(x+10,y+4,1,1);
} else if(direction==="up") {
ctx.fillStyle=hair;
ctx.fillRect(x+3,y+1,10,5);
} else {
ctx.fillRect(x+5,y+4,1,1);
ctx.fillRect(x+10,y+4,1,1);
}
// Princess crown
if(color==="#bd7097") {
ctx.fillStyle="#f3d46c";
ctx.fillRect(x+5,y-3,6,3);
ctx.fillRect(x+4,y-2,2,2);
ctx.fillRect(x+10,y-2,2,2);
}
}
function collides(x,y) {
// World boundaries
if(x<0 || y<0 || x>WORLD_W*TILE-14 || y>WORLD_H*TILE-16)
return true;
// Building collision
const buildings=[
[7,5,11,6],
[39,14,7,5],
[48,14,7,5]
];
for(const b of buildings) {
const bx=b[0]*TILE, by=b[1]*TILE;
const bw=b[2]*TILE, bh=b[3]*TILE;
if(x+14>bx && x<bx+bw && y+15>by && y<by+bh)
return true;
}
// Trees
for(let ty=2;ty<35;ty+=3) {
for(const tx of [2,55]) {
if(x+12>tx*TILE+1 && x<tx*TILE+15 &&
y+14>ty*TILE && y<ty*TILE+12)
return true;
}
}
return false;
}
function update(dt) {
let dx=0,dy=0;
if(keys["ArrowUp"]||keys["w"]) {dy=-1;player.direction="up";}
if(keys["ArrowDown"]||keys["s"]) {dy=1;player.direction="down";}
if(keys["ArrowLeft"]||keys["a"]) {dx=-1;player.direction="left";}
if(keys["ArrowRight"]||keys["d"]) {dx=1;player.direction="right";}
player.moving=dx!==0||dy!==0;
if(dx!==0&&dy!==0) {
dx*=0.707; dy*=0.707;
}
const nx=player.x+dx*player.speed*dt;
const ny=player.y+dy*player.speed*dt;
if(!collides(nx,player.y)) player.x=nx;
if(!collides(player.x,ny)) player.y=ny;
if(player.moving) {
animationTime+=dt;
}
// NPC movement
npcs.forEach((npc,i)=>{
npc.timer+=dt;
if(npc.timer>3+i*1.5) {
npc.timer=0;
const directions=[
[1,0],[-1,0],[0,1],[0,-1],[0,0]
];
const d=directions[Math.floor(Math.random()*directions.length)];
const nx=npc.x+d[0]*TILE;
const ny=npc.y+d[1]*TILE;
if(!collides(nx,ny)) {
npc.x=nx;
npc.y=ny;
}
}
});
// Time
hour+=dt/45;
if(hour>=20) {
hour=8;
day++;
message="A new day begins in Aveloria!";
}
const h=Math.floor(hour);
const mins=Math.floor((hour-h)*60);
document.getElementById("clock").textContent=
`${h>12?h-12:h}:${String(mins).padStart(2,"0")} ${h>=12?"PM":"AM"}`;
document.getElementById("date").textContent="Spring "+day;
}
function interact() {
let closest=null;
let distance=Infinity;
for(const npc of npcs) {
const d=Math.hypot(player.x-npc.x,player.y-npc.y);
if(d<35 && d<distance) {
closest=npc;
distance=d;
}
}
if(closest) {
message=closest.name+": "+closest.dialogue[closest.index];
closest.index=(closest.index+1)%closest.dialogue.length;
if(closest.name==="Nicholas") {
hearts=Math.min(10,hearts+1);
document.getElementById("hearts").textContent=hearts;
}
} else {
message="You look around. Aveloria is beautiful today.";
}
document.getElementById("message").textContent=message;
}
function moveTouch(dx,dy) {
if(dx<0) player.direction="left";
if(dx>0) player.direction="right";
if(dy<0) player.direction="up";
if(dy>0) player.direction="down";
const nx=player.x+dx*TILE;
const ny=player.y+dy*TILE;
if(!collides(nx,ny)) {
player.x=nx;
player.y=ny;
animationTime+=0.3;
}
}
function render() {
ctx.clearRect(0,0,canvas.width,canvas.height);
const cameraX=Math.max(0,Math.min(
player.x-canvas.width/2,
WORLD_W*TILE-canvas.width
));
const cameraY=Math.max(0,Math.min(
player.y-canvas.height/2,
WORLD_H*TILE-canvas.height
));
ctx.save();
ctx.translate(-Math.floor(cameraX),-Math.floor(cameraY));
drawWorld();
// Draw NPCs
npcs.forEach(npc=>{
drawCharacter(npc.x,npc.y,npc.color,npc.hair,
"down",false,0);
ctx.fillStyle="white";
ctx.font="8px monospace";
ctx.textAlign="center";
ctx.fillText(npc.name,npc.x+8,npc.y-5);
});
// Draw player
drawCharacter(
player.x,player.y,
"#bd7097","#70422f",
player.direction,player.moving,animationTime
);
ctx.restore();
// Interaction hint
const nearby=npcs.some(n=>Math.hypot(
player.x-n.x,player.y-n.y
)<35);
if(nearby) {
ctx.fillStyle="rgba(35,30,25,0.85)";
ctx.fillRect(175,265,130,22);
ctx.fillStyle="white";
ctx.font="10px monospace";
ctx.textAlign="center";
ctx.fillText("Press E to talk",240,279);
}
}
function loop(timestamp) {
const dt=Math.min((timestamp-lastTime)/1000||0,0.05);
lastTime=timestamp;
update(dt);
render();
requestAnimationFrame(loop);
}
document.addEventListener("keydown",e=>{
const key=e.key.toLowerCase();
if(["arrowup","arrowdown","arrowleft","arrowright"," "].includes(key))
e.preventDefault();
keys[key]=true;
if(key==="e") interact();
if(key==="n") {
day++;
hour=8;
message="You wake up to a brand new day!";
document.getElementById("message").textContent=message;
}
});
document.addEventListener("keyup",e=>{
keys[e.key.toLowerCase()]=false;
});
document.getElementById("message").textContent=message;
requestAnimationFrame(loop);
</script>
</body>
</html>