<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Princess: A Single Life</title>
<style>
*{box-sizing:border-box}
body{
margin:0;background:#252d29;color:white;
font-family:monospace;text-align:center;padding:12px
}
h2{color:#f5d99c;margin:8px}
#gamebox{
max-width:850px;margin:auto;
border:5px solid #79583e;background:#493c31;
box-shadow:0 5px 20px #111
}
#hud{
display:flex;justify-content:space-around;
flex-wrap:wrap;padding:11px;gap:8px;
background:#514034;font-size:12px
}
canvas{
display:block;width:100%;height:auto;
image-rendering:pixelated;background:#83b765
}
#message{
background:#302a27;color:#ffe8b7;
padding:12px;min-height:45px;font-size:12px
}
.controls{margin:12px auto;line-height:2}
button{
background:#806143;color:white;border:2px solid #c5a477;
border-radius:5px;padding:10px 16px;
font-family:monospace;margin:3px;touch-action:none
}
button:active{background:#bd9664}
</style>
</head>
<body>
<h2>👑 Princess: A Single Life</h2>
<div id="gamebox">
<div id="hud">
<span>👑 Arabella</span>
<span id="date">Spring 1</span>
<span id="time">8:00 AM</span>
<span>♡ <span id="hearts">0</span></span>
</div>
<canvas id="game" width="640" height="400"></canvas>
<div id="message">Welcome home, Princess Arabella.</div>
</div>
<div class="controls">
<div><button data-key="ArrowUp">▲</button></div>
<button data-key="ArrowLeft">◀</button>
<button data-key="ArrowDown">▼</button>
<button data-key="ArrowRight">▶</button>
<div>
<button onclick="interact()">E — Interact</button>
<button onclick="nextDay()">Next Day</button>
</div>
<small>WASD / Arrow keys to move · E to interact</small>
</div>
<script>
const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");
ctx.imageSmoothingEnabled=false;
const S=16;
const W=65,H=45;
const player={
x:18*S,y:21*S,dir:"down",
moving:false,frame:0,step:0,speed:95
};
let keys={};
let day=1,clock=8,hearts=0;
let last=0,worldTime=0;
let camera={x:0,y:0};
let message="Welcome home, Princess Arabella.";
const npcs=[
{name:"Nicholas",x:25*S,y:20*S,
color:"#486caa",hair:"#493024",dir:"down",
frame:0,step:0,timer:0,
lines:["Good morning, Arabella!",
"The gardens look lovely today.",
"Would you like to go for a walk?",
"I was hoping to see you today."]},
{name:"Charlotte",x:31*S,y:25*S,
color:"#a65c9b",hair:"#d6a56e",dir:"down",
frame:0,step:0,timer:0,
lines:["Arabella! How lovely to see you.",
"Have you visited the town?",
"I heard there is a new boutique!"]},
{name:"Guard",x:13*S,y:16*S,
color:"#526e52",hair:"#39291f",dir:"down",
frame:0,step:0,timer:0,
lines:["Good morning, Your Highness.",
"Everything is peaceful today."]}
];
// Deterministic decoration
function random(x,y,n=1){
let v=Math.sin(x*127.1+y*311.7+n*74.7)*43758.5453;
return v-Math.floor(v);
}
function rect(x,y,w,h,c){
ctx.fillStyle=c;
ctx.fillRect(Math.floor(x),Math.floor(y),w,h);
}
// Grass tiles
function grass(tx,ty){
let x=tx*S,y=ty*S;
let r=random(tx,ty);
rect(x,y,16,16,r>.5?"#80b45e":"#84b965");
// Subtle grass blades
for(let i=0;i<4;i++){
let px=x+Math.floor(random(tx,ty,i+2)*15);
let py=y+Math.floor(random(tx,ty,i+8)*15);
rect(px,py,1,2,random(tx,ty,i+15)>.5?"#679b50":"#9acb72");
}
// Tiny flowers
if(random(tx,ty,30)>.88){
let fx=x+5+Math.floor(random(tx,ty,31)*7);
let fy=y+4+Math.floor(random(tx,ty,32)*8);
rect(fx,fy,3,3,random(tx,ty,33)>.5?"#f2d8ed":"#f8e49a");
rect(fx+1,fy+1,1,1,"#e9a84c");
}
}
// Textured stone pavement
function pathTile(tx,ty){
let x=tx*S,y=ty*S;
rect(x,y,16,16,"#bba985");
rect(x+1,y+1,6,6,"#d3c09b");
rect(x+8,y+1,7,6,"#c5b18c");
rect(x+1,y+8,7,7,"#c9b58f");
rect(x+9,y+8,6,7,"#b5a17d");
rect(x+7,y,1,16,"#a99777");
rect(x,y+7,16,1,"#a99777");
rect(x+2,y+3,2,1,"#e1d1ae");
rect(x+10,y+10,2,1,"#a18d6d");
}
// Water
function waterTile(tx,ty){
let x=tx*S,y=ty*S;
rect(x,y,16,16,"#478eac");
rect(x+2,y+3,7,2,"#72bad0");
rect(x+9,y+10,5,2,"#63abc5");
rect(x+3,y+12,3,1,"#9bd1d9");
if(Math.sin(worldTime*2+tx+ty)>0.6)
rect(x+5,y+6,5,1,"#a4dce0");
}
// Trees
function tree(tx,ty){
let x=tx*S,y=ty*S;
// Shadow
rect(x+2,y+13,13,4,"#547849");
// Trunk
rect(x+6,y+7,5,10,"#765032");
rect(x+7,y+8,2,7,"#a16c42");
// Layered leaves
rect(x+2,y+2,12,11,"#315d39");
rect(x+1,y+4,14,7,"#386d3e");
rect(x+4,y,9,10,"#447f46");
rect(x+5,y+2,6,6,"#5a984f");
rect(x+3,y+5,3,3,"#70ad5d");
rect(x+10,y+3,3,3,"#70ad5d");
rect(x+5,y+1,3,2,"#83bd69");
}
// Building
function building(tx,ty,tw,th,name,wall,roof){
let x=tx*S,y=ty*S,w=tw*S,h=th*S;
// Shadow
rect(x+5,y+7,w,h,"#536047");
// Wall
rect(x,y,w,h,wall);
// Wall details
for(let i=0;i<tw;i+=2){
rect(x+i*S,y+10,1,h-10,"#ffffff18");
}
// Roof
rect(x-5,y-8,w+10,15,roof);
rect(x-3,y-5,w+6,3,"#ffffff22");
rect(x,y+4,w,3,"#594039");
// Roof tiles
for(let i=0;i<tw;i++){
rect(x+i*S,y-5,1,8,"#00000020");
}
// Windows
for(let wx of [x+12,x+w-25]){
rect(wx,y+24,12,15,"#664c3c");
rect(wx+2,y+26,8,11,"#8dc8d4");
rect(wx+5,y+26,2,11,"#d8e7d8");
rect(wx+2,y+31,8,1,"#d8e7d8");
}
// Door
rect(x+w/2-7,y+h-25,14,25,"#69452f");
rect(x+w/2-5,y+h-23,10,22,"#895b3c");
rect(x+w/2+3,y+h-13,2,2,"#e4c477");
// Sign
rect(x+w/2-20,y-17,40,9,"#755037");
ctx.fillStyle="#fff0ce";
ctx.font="6px monospace";
ctx.textAlign="center";
ctx.fillText(name,x+w/2,y-10);
}
// World map
function terrain(tx,ty){
let isPath=
(ty>=20&&ty<=22&&tx>=5&&tx<=58)||
(tx>=17&&tx<=19&&ty>=8&&ty<=34)||
(tx>=34&&tx<=36&&ty>=13&&ty<=34)||
(tx>=47&&tx<=49&&ty>=12&&ty<=34);
let isWater=tx>=39&&tx<=44&&ty>=6&&ty<=11;
if(isWater)waterTile(tx,ty);
else if(isPath)pathTile(tx,ty);
else grass(tx,ty);
}
function drawWorld(){
for(let y=0;y<H;y++)
for(let x=0;x<W;x++)
terrain(x,y);
// Pond
for(let y=6;y<=11;y++)
for(let x=39;x<=44;x++)
waterTile(x,y);
// Buildings
building(7,5,11,7,"PALACE","#d9c6a7","#744c58");
building(41,14,7,5,"BOUTIQUE","#d9b2a7","#985b65");
building(50,14,7,5,"CAFE","#d6b58c","#81594b");
// Fountain
rect(25*S,14*S,4*S,4*S,"#c9c3ac");
rect(25*S+3,14*S+3,3*S,3*S,"#478eac");
rect(25*S+10,14*S+3,3*S,3*S,"#478eac");
rect(25*S+3,14*S+10,3*S,3*S,"#478eac");
rect(25*S+10,14*S+10,3*S,3*S,"#478eac");
rect(26*S+5,13*S,6,16,"#e5e0cf");
rect(26*S+7,12*S,2,5,"#a5d8df");
// Trees around the world
for(let y=2;y<40;y+=3){
tree(2,y);
tree(61,y);
}
for(let x=23;x<38;x+=3){
tree(x,4);
tree(x,35);
}
for(let x=5;x<16;x+=3)tree(x,13);
for(let x=52;x<60;x+=3)tree(x,28);
// Flower beds
for(let i=0;i<12;i++){
let x=(21+i)*S,y=19*S;
rect(x,y,4,4,i%2?"#eeb9dc":"#f5db87");
rect(x+1,y+1,2,2,"#fff0c5");
}
}
// Pixel character with directional walking frames
function character(x,y,body,hair,dir,frame,isPrincess=false){
const walk=frame%2===0?0:1;
const bob=walk?1:0;
// Shadow
rect(x+2,y+14,13,3,"#00000035");
// Legs
let legA=walk?2:0;
let legB=walk?-2:0;
rect(x+5+legA,y+10,3,5,"#493b37");
rect(x+9+legB,y+10,3,5,"#493b37");
// Shoes
rect(x+4+legA,y+14,4,2,"#68462e");
rect(x+9+legB,y+14,4,2,"#68462e");
// Dress or body
rect(x+4,y+5+bob,9,7,body);
rect(x+2,y+9+bob,13,4,body);
rect(x+4,y+12+bob,3,2,body);
rect(x+10,y+12+bob,3,2,body);
// Dress details
if(isPrincess){
rect(x+7,y+7+bob,3,5,"#e7a4c2");
rect(x+3,y+10+bob,2,2,"#e8c4d1");
}
// Arms
rect(x+2,y+7+bob,2,4,"#f0c39c");
rect(x+13,y+7+bob,2,4,"#f0c39c");
// Hair behind head
rect(x+3,y+1,10,6,hair);
rect(x+2,y+3,3,6,hair);
rect(x+12,y+3,3,6,hair);
// Face
if(dir!=="up"){
rect(x+4,y+2,8,6,"#f0c39c");
// Face details by direction
if(dir==="down"){
rect(x+5,y+5,1,1,"#49352d");
rect(x+10,y+5,1,1,"#49352d");
}else if(dir==="left"){
rect(x+4,y+5,1,1,"#49352d");
}else if(dir==="right"){
rect(x+11,y+5,1,1,"#49352d");
}
}else{
rect(x+3,y+1,10,7,hair);
}
// Hair highlights
rect(x+5,y+1,3,1,"#ffffff22");
// Crown
if(isPrincess){
rect(x+5,y-3,7,3,"#e7bd55");
rect(x+6,y-4,2,2,"#ffe58a");
rect(x+10,y-4,2,2,"#ffe58a");
rect(x+8,y-2,2,2,"#fff0a4");
}
}
function blocked(x,y){
if(x<0||y<0||x>W*S-16||y>H*S-16)return true;
const buildings=[
[7,5,11,7],[41,14,7,5],[50,14,7,5]
];
for(let b of buildings){
if(x+14>b[0]*S&&x<(b[0]+b[2])*S&&
y+15>b[1]*S&&y<(b[1]+b[3])*S)
return true;
}
// Tree collision
for(let ty=2;ty<40;ty+=3){
for(let tx of [2,61]){
if(x+12>tx*S+1&&x<tx*S+15&&
y+14>ty*S&&y<ty*S+12)return true;
}
}
return false;
}
function updateNPC(n,dt){
n.timer+=dt;
if(n.timer>2.5){
n.timer=0;
let dirs=[
[1,0,"right"],[-1,0,"left"],
[0,1,"down"],[0,-1,"up"],[0,0,n.dir]
];
let d=dirs[Math.floor(Math.random()*dirs.length)];
let nx=n.x+d[0]*S,ny=n.y+d[1]*S;
if(!blocked(nx,ny)){
n.x=nx;n.y=ny;n.dir=d[2];
n.frame++;
}
}
}
function update(dt){
let dx=0,dy=0;
if(keys.ArrowUp||keys.w){dy=-1;player.dir="up";}
if(keys.ArrowDown||keys.s){dy=1;player.dir="down";}
if(keys.ArrowLeft||keys.a){dx=-1;player.dir="left";}
if(keys.ArrowRight||keys.d){dx=1;player.dir="right";}
player.moving=dx!==0||dy!==0;
if(dx&&dy){dx*=.707;dy*=.707;}
let nx=player.x+dx*player.speed*dt;
let ny=player.y+dy*player.speed*dt;
if(!blocked(nx,player.y))player.x=nx;
if(!blocked(player.x,ny))player.y=ny;
if(player.moving){
player.step+=dt;
if(player.step>.13){
player.step=0;
player.frame++;
}
}
npcs.forEach(n=>updateNPC(n,dt));
worldTime+=dt;
clock+=dt/45;
if(clock>=20){
clock=8;day++;
message="A new day begins in Aveloria!";
showMessage();
}
const h=Math.floor(clock);
const min=Math.floor((clock-h)*60);
document.getElementById("time").textContent=
`${h>12?h-12:h}:${String(min).padStart(2,"0")} ${h>=12?"PM":"AM"}`;
document.getElementById("date").textContent="Spring "+day;
}
function draw(){
ctx.clearRect(0,0,640,400);
camera.x=Math.max(0,Math.min(player.x-320,W*S-640));
camera.y=Math.max(0,Math.min(player.y-200,H*S-400));
ctx.save();
ctx.translate(-Math.floor(camera.x),-Math.floor(camera.y));
drawWorld();
// Draw characters in depth order
let people=[
...npcs.map(n=>({x:n.x,y:n.y,npc:n})),
{x:player.x,y:player.y,player:true}
].sort((a,b)=>a.y-b.y);
for(let p of people){
if(p.player){
character(p.x,p.y,"#bd7097","#70422f",
player.dir,player.moving?player.frame:0,true);
}else{
let n=p.npc;
character(n.x,n.y,n.color,n.hair,n.dir,n.frame,false);
ctx.fillStyle="#fff4d9";
ctx.font="8px monospace";
ctx.textAlign="center";
ctx.fillText(n.name,n.x+8,n.y-5);
}
}
ctx.restore();
// Interaction prompt
if(npcs.some(n=>Math.hypot(player.x-n.x,player.y-n.y)<35)){
rect(245,365,150,23,"#40362f");
ctx.fillStyle="white";
ctx.font="11px monospace";
ctx.textAlign="center";
ctx.fillText("E TALK TO CHARACTER",320,380);
}
}
function interact(){
let nearest=null,dist=Infinity;
for(let n of npcs){
let d=Math.hypot(player.x-n.x,player.y-n.y);
if(d<35&&d<dist){nearest=n;dist=d;}
}
if(nearest){
message=nearest.name+": "+nearest.lines[
Math.floor(Math.random()*nearest.lines.length)
];
if(nearest.name==="Nicholas"){
hearts=Math.min(10,hearts+1);
document.getElementById("hearts").textContent=hearts;
}
}else{
message="You enjoy the peaceful gardens of Aveloria.";
}
showMessage();
}
function showMessage(){
document.getElementById("message").textContent=message;
}
function nextDay(){
day++;
clock=8;
message="Good morning! A new day in Aveloria.";
showMessage();
}
document.addEventListener("keydown",e=>{
let k=e.key.length===1?e.key.toLowerCase():e.key;
keys[k]=true;
if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"," "].includes(e.key))
e.preventDefault();
if(k==="e")interact();
if(k==="n")nextDay();
});
document.addEventListener("keyup",e=>{
let k=e.key.length===1?e.key.toLowerCase():e.key;
keys[k]=false;
});
// Mobile buttons
document.querySelectorAll("[data-key]").forEach(btn=>{
const k=btn.dataset.key;
btn.addEventListener("pointerdown",e=>{
e.preventDefault();keys[k]=true;
});
["pointerup","pointerleave","pointercancel"].forEach(event=>{
btn.addEventListener(event,()=>keys[k]=false);
});
});
function loop(t){
let dt=Math.min((t-last)/1000||0,.04);
last=t;
update(dt);
draw();
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
</script>
</body>
</html>