Forest Friends 3D: Grumpy Deer Chase
by LunarFlare59517 lines14.7 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Forest Friends 3D</title>
<style>
*{box-sizing:border-box}
body{
margin:0;background:#173e2b;color:white;
font-family:Trebuchet MS,Arial,sans-serif;
overflow:hidden;touch-action:none;
}
#game{height:100dvh;width:100%;display:flex;flex-direction:column}
header{
background:#245c39;text-align:center;padding:7px;
flex-shrink:0;
}
h1{font-size:clamp(19px,4vw,30px);margin:2px}
header p{font-size:12px;margin:3px}
#stats{
display:flex;justify-content:center;gap:7px;
flex-wrap:wrap;padding:6px;background:#34754a;
}
.stat{
background:#fff;color:#244b30;border-radius:10px;
padding:5px 10px;font-weight:bold;font-size:13px;
}
#scene{position:relative;flex:1;min-height:0;background:#9bdc8c}
canvas{width:100%;height:100%;display:block}
#message{
position:absolute;top:9px;left:50%;transform:translateX(-50%);
background:#fff4cf;color:#354b27;
border:3px solid #c9a64e;border-radius:14px;
padding:8px 13px;font-weight:bold;font-size:13px;
width:max-content;max-width:90%;text-align:center;
pointer-events:none;
}
#controls{
background:#245c39;padding:8px;
display:flex;justify-content:space-between;align-items:center;
gap:8px;flex-shrink:0;
}
.pad{
display:grid;grid-template-columns:repeat(3,43px);
grid-template-rows:repeat(2,40px);gap:3px;
}
.control{
background:#6da94e;color:white;border:2px solid #b4df8b;
border-radius:10px;font-size:20px;padding:0;
touch-action:none;user-select:none;
}
.control:active,.control.active{background:#d59c42}
.up{grid-column:2;grid-row:1}
.left{grid-column:1;grid-row:2}
.down{grid-column:2;grid-row:2}
.right{grid-column:3;grid-row:2}
.actions{
display:flex;flex-wrap:wrap;justify-content:center;
gap:6px;flex:1;
}
.action{
background:#e49b38;color:#fff;border:0;
border-radius:11px;padding:10px 9px;
font-weight:bold;font-size:12px;
box-shadow:0 3px #9c6025;touch-action:manipulation;
}
.action:disabled{opacity:.4}
#tip{text-align:center;font-size:10px;padding:4px;background:#173e2b}
@media(max-width:440px){
.pad{grid-template-columns:repeat(3,38px);grid-template-rows:repeat(2,36px)}
.action{font-size:11px;padding:9px 6px}
#controls{padding:5px;gap:4px}
}
</style>
</head>
<body>
<div id="game">
<header>
<h1>🌲 FOREST FRIENDS 3D 🦌</h1>
<p>Explore, collect, build and watch out for the GRUMPY DEER!</p>
</header>
<div id="stats">
<div class="stat">🪵 Wood: <span id="wood">0</span></div>
<div class="stat">🍓 Berries: <span id="berries">0</span></div>
<div class="stat">🔥 Fire: <span id="fuel">0</span></div>
<div class="stat">🌙 Night: <span id="night">0</span>/3</div>
</div>
<div id="scene">
<canvas id="world"></canvas>
<div id="message">Welcome! Explore the forest and find some wood!</div>
</div>
<div id="controls">
<div class="pad">
<button class="control up" data-dir="up">⬆️</button>
<button class="control left" data-dir="left">⬅️</button>
<button class="control down" data-dir="down">⬇️</button>
<button class="control right" data-dir="right">➡️</button>
</div>
<div class="actions">
<button class="action" onclick="collect()">🪓 Collect</button>
<button class="action" onclick="pickBerry()">🍓 Berry</button>
<button class="action" onclick="craft()">🛠️ Craft</button>
<button class="action" onclick="addFire()">🔥 Fuel</button>
<button class="action" onclick="feedDeer()">🦌 Feed</button>
<button class="action" onclick="nextNight()">🌙 Next Night</button>
</div>
</div>
<div id="tip">Move with the arrows or WASD. Walk near trees and bushes, then tap Collect or Berry!</div>
</div>
<script>
const canvas=document.getElementById("world");
const ctx=canvas.getContext("2d");
let W=800,H=500;
let wood=0,berries=0,fuel=0,night=0;
let built=false,gameOver=false;
let player={x:9,z:12};
let deer={x:3,z:3,active:false,stun:0};
let keys={};
let messageTimer=0;
let trees=[],bushes=[],rocks=[];
let last=0;
let time=0;
function resize(){
const r=canvas.getBoundingClientRect();
const d=Math.min(devicePixelRatio||1,2);
W=r.width;H=r.height;
canvas.width=Math.round(W*d);
canvas.height=Math.round(H*d);
ctx.setTransform(d,0,0,d,0,0);
}
new ResizeObserver(resize).observe(canvas);
resize();
function say(t){
document.getElementById("message").textContent=t;
messageTimer=220;
}
function updateStats(){
document.getElementById("wood").textContent=wood;
document.getElementById("berries").textContent=berries;
document.getElementById("fuel").textContent=fuel;
document.getElementById("night").textContent=night;
}
function sound(freq=450){
try{
const a=new(window.AudioContext||window.webkitAudioContext)();
const o=a.createOscillator(),g=a.createGain();
o.connect(g);g.connect(a.destination);
o.frequency.value=freq;
g.gain.setValueAtTime(.06,a.currentTime);
g.gain.exponentialRampToValueAtTime(.001,a.currentTime+.12);
o.start();o.stop(a.currentTime+.12);
o.onended=()=>a.close();
}catch(e){}
}
function rand(a,b){return Math.random()*(b-a)+a}
function distance(a,b){return Math.hypot(a.x-b.x,a.z-b.z)}
function occupied(x,z){
return trees.some(t=>Math.hypot(t.x-x,t.z-z)<1.1);
}
function makeWorld(){
trees=[];bushes=[];rocks=[];
for(let i=0;i<37;i++){
let x=rand(1,19),z=rand(1,19);
if(Math.hypot(x-9,z-12)>3&&!occupied(x,z)){
trees.push({x,z,cut:false});
}
}
for(let i=0;i<13;i++){
let x=rand(1,19),z=rand(1,19);
if(!occupied(x,z))bushes.push({x,z,used:false});
}
for(let i=0;i<14;i++){
rocks.push({x:rand(1,19),z:rand(1,19)});
}
}
makeWorld();
const tile=30;
function project(x,z,y=0){
const cx=W/2,cy=H*.49;
const dx=x-player.x,dz=z-player.z;
const depth=dx+dz;
const scale=1/(1+depth*.018);
return {
x:cx+(dx-dz)*tile*scale,
y:cy+(dx+dz)*tile*.47*scale-y*scale,
s:scale
};
}
function polygon(points,color){
ctx.fillStyle=color;
ctx.beginPath();
ctx.moveTo(points[0][0],points[0][1]);
for(let i=1;i<points.length;i++)ctx.lineTo(points[i][0],points[i][1]);
ctx.closePath();ctx.fill();
}
function cube(x,z,y,size,color){
const p=project(x,z,y);
const s=size*p.s;
const xx=p.x,yy=p.y;
polygon([[xx,yy-s*.7],[xx+s,yy-s*.2],[xx,yy+s*.3],[xx-s,yy-s*.2]],color);
polygon([[xx-s,yy-s*.2],[xx,yy+s*.3],[xx,yy+s*1.2],[xx-s,yy+s*.7]],"#80552e");
polygon([[xx,yy+s*.3],[xx+s,yy-s*.2],[xx+s,yy+s*.7],[xx,yy+s*1.2]],"#986637");
polygon([[xx,yy-s*.7],[xx+s,yy-s*.2],[xx,yy+s*.3],[xx-s,yy-s*.2]],color);
}
function ground(){
const cx=W/2,cy=H*.49;
for(let x=0;x<=20;x++){
for(let z=0;z<=20;z++){
let p=project(x,z);
if(p.x<-80||p.x>W+80||p.y<-60||p.y>H+60)continue;
let s=tile*p.s;
polygon([
[p.x,p.y-s*.47],
[p.x+s,p.y],
[p.x,p.y+s*.47],
[p.x-s,p.y]
],(x+z)%2===0?"#83c96a":"#78bd61");
if((x*7+z*3)%17===0){
ctx.fillStyle="#4c9d4b";
ctx.fillRect(p.x-2,p.y-2,3,3);
}
}
}
}
function drawTree(t){
if(t.cut)return;
let p=project(t.x,t.z);
let s=tile*p.s;
// trunk
cube(t.x,t.z,5,8,"#a46c38");
// blocky leafy crown
cube(t.x,t.z,24,17,"#27834b");
cube(t.x-.17,t.z,35,12,"#389f50");
cube(t.x+.17,t.z,35,12,"#48ad59");
cube(t.x,t.z,45,9,"#5cbb5b");
}
function drawBush(b){
let p=project(b.x,b.z),s=tile*p.s;
if(b.used)return;
ctx.fillStyle="#388a43";
ctx.beginPath();ctx.ellipse(p.x,p.y-5*s,13*s,9*s,0,0,Math.PI*2);ctx.fill();
ctx.fillStyle="#e94e78";
for(let i=0;i<3;i++){
ctx.beginPath();ctx.arc(p.x+(i-1)*7*s,p.y-10*s,3*s,0,Math.PI*2);ctx.fill();
}
}
function drawRock(r){
cube(r.x,r.z,3,8,"#9aa9a0");
}
function drawCamp(){
let p=project(9,12);
let s=tile*p.s;
ctx.fillStyle="#d1a36a";
ctx.beginPath();ctx.ellipse(p.x,p.y,30*s,14*s,0,0,Math.PI*2);ctx.fill();
if(built){
ctx.fillStyle="#6b4325";
ctx.fillRect(p.x-15*s,p.y-5*s,30*s,8*s);
ctx.fillStyle="#ff9b2e";
ctx.beginPath();ctx.moveTo(p.x,p.y-40*s);ctx.lineTo(p.x-12*s,p.y-3*s);ctx.lineTo(p.x+13*s,p.y-3*s);ctx.fill();
ctx.fillStyle="#ffdf55";
ctx.beginPath();ctx.moveTo(p.x,p.y-30*s);ctx.lineTo(p.x-5*s,p.y-4*s);ctx.lineTo(p.x+7*s,p.y-4*s);ctx.fill();
}else{
ctx.fillStyle="#895a32";
ctx.fillRect(p.x-12*s,p.y-6*s,24*s,5*s);
}
}
function drawPlayer(){
let p=project(player.x,player.z);
let s=tile*p.s;
// shadow
ctx.fillStyle="#0003";
ctx.beginPath();ctx.ellipse(p.x,p.y,13*s,6*s,0,0,Math.PI*2);ctx.fill();
// feet
ctx.fillStyle="#59402c";
ctx.fillRect(p.x-9*s,p.y-17*s,7*s,15*s);
ctx.fillRect(p.x+2*s,p.y-17*s,7*s,15*s);
// body
ctx.fillStyle="#3286d0";
ctx.fillRect(p.x-12*s,p.y-41*s,24*s,25*s);
ctx.fillStyle="#f2bd8c";
ctx.fillRect(p.x-9*s,p.y-60*s,18*s,19*s);
// hair
ctx.fillStyle="#65452d";
ctx.fillRect(p.x-10*s,p.y-63*s,20*s,7*s);
ctx.fillStyle="#fff";
ctx.fillRect(p.x-5*s,p.y-53*s,3*s,3*s);
ctx.fillRect(p.x+3*s,p.y-53*s,3*s,3*s);
}
function drawDeer(){
if(!deer.active)return;
let p=project(deer.x,deer.z),s=tile*p.s;
// shadow
ctx.fillStyle="#0003";
ctx.beginPath();ctx.ellipse(p.x,p.y,18*s,7*s,0,0,Math.PI*2);ctx.fill();
// legs
ctx.fillStyle="#8b572f";
for(let i=-1;i<=1;i+=2){
ctx.fillRect(p.x+i*9*s,p.y-20*s,5*s,20*s);
ctx.fillRect(p.x+i*4*s,p.y-20*s,4*s,20*s);
}
// body
ctx.fillStyle="#b9783e";
ctx.fillRect(p.x-17*s,p.y-38*s,34*s,22*s);
// neck and head
ctx.fillRect(p.x+7*s,p.y-48*s,9*s,22*s);
ctx.fillStyle="#c98950";
ctx.fillRect(p.x+7*s,p.y-57*s,18*s,16*s);
// ears
polygon([[p.x+10*s,p.y-55*s],[p.x+5*s,p.y-68*s],[p.x+16*s,p.y-58*s]],"#b9783e");
polygon([[p.x+22*s,p.y-55*s],[p.x+29*s,p.y-67*s],[p.x+25*s,p.y-51*s]],"#b9783e");
// antlers
ctx.strokeStyle="#68432a";ctx.lineWidth=3*s;
ctx.beginPath();
ctx.moveTo(p.x+13*s,p.y-56*s);ctx.lineTo(p.x+7*s,p.y-69*s);
ctx.lineTo(p.x+2*s,p.y-74*s);
ctx.moveTo(p.x+7*s,p.y-69*s);ctx.lineTo(p.x+12*s,p.y-76*s);
ctx.moveTo(p.x+23*s,p.y-55*s);ctx.lineTo(p.x+29*s,p.y-69*s);
ctx.lineTo(p.x+35*s,p.y-74*s);
ctx.moveTo(p.x+29*s,p.y-69*s);ctx.lineTo(p.x+24*s,p.y-76*s);
ctx.stroke();
// grumpy face
ctx.fillStyle="#34251d";
ctx.fillRect(p.x+12*s,p.y-52*s,3*s,3*s);
ctx.fillRect(p.x+22*s,p.y-52*s,3*s,3*s);
ctx.strokeStyle="#34251d";ctx.lineWidth=2*s;
ctx.beginPath();ctx.moveTo(p.x+11*s,p.y-57*s);ctx.lineTo(p.x+16*s,p.y-55*s);
ctx.moveTo(p.x+21*s,p.y-55*s);ctx.lineTo(p.x+26*s,p.y-57*s);ctx.stroke();
ctx.fillStyle="#fff";
ctx.font=`bold ${Math.max(10,12*s)}px Arial`;
ctx.fillText("GRUMPY!",p.x-24*s,p.y-84*s);
}
function render(){
ctx.clearRect(0,0,W,H);
ground();
let things=[];
trees.forEach(t=>things.push({d:t.x+t.z,fn:()=>drawTree(t)}));
bushes.forEach(b=>things.push({d:b.x+b.z,fn:()=>drawBush(b)}));
rocks.forEach(r=>things.push({d:r.x+r.z,fn:()=>drawRock(r)}));
things.push({d:21,fn:drawCamp});
things.push({d:player.x+player.z,fn:drawPlayer});
if(deer.active)things.push({d:deer.x+deer.z,fn:drawDeer});
things.sort((a,b)=>a.d-b.d);
things.forEach(t=>t.fn());
}
function move(dx,dz){
if(gameOver)return;
let nx=Math.max(.5,Math.min(19.5,player.x+dx));
let nz=Math.max(.5,Math.min(19.5,player.z+dz));
if(!trees.some(t=>!t.cut&&Math.hypot(t.x-nx,t.z-nz)<.65)){
player.x=nx;player.z=nz;
}
}
function collect(){
if(gameOver)return;
let t=trees.find(t=>!t.cut&&distance(player,t)<1.6);
if(!t){say("Walk closer to a tree to collect wood! 🌳");return}
t.cut=true;wood++;sound(500);
say("Chop! You collected one wood! 🪵");
updateStats();
}
function pickBerry(){
if(gameOver)return;
let b=bushes.find(b=>!b.used&&distance(player,b)<1.7);
if(!b){say("Find a berry bush and walk close to it! 🍓");return}
b.used=true;berries++;sound(650);
say("Yummy! You found a berry!");
updateStats();
}
function craft(){
if(gameOver)return;
if(built){say("You already built your campfire!");return}
if(wood<5){say("You need 5 wood to build your campfire!");return}
wood-=5;built=true;sound(700);
say("You built a cozy campfire! 🔥");
updateStats();
}
function addFire(){
if(gameOver||!built||wood<1){say("You need a campfire and one wood!");return}
wood--;fuel++;sound(550);
say("Your campfire is glowing brighter!");
updateStats();
}
function feedDeer(){
if(gameOver||!deer.active||berries<1){say("You need a berry and a nearby deer!");return}
berries--;deer.active=false;deer.stun=4;
say('The deer gobbles the berry! "HMPH! That was tasty!" 🍓');
sound(700);updateStats();
}
function startDeer(){
if(deer.active)return;
deer.active=true;
deer.x=Math.max(1,Math.min(19,player.x+rand(-7,7)));
deer.z=Math.max(1,Math.min(19,player.z+rand(-7,7)));
if(distance(deer,player)<4){deer.x=1;deer.z=1}
say('🦌😠 "HEY! YOU! I AM COMING TO GET YOUR WOOD!"');
sound(180);
}
function nextNight(){
if(gameOver)return;
if(!built||fuel<2){say("Build your campfire and add 2 wood before bedtime!");return}
fuel-=2;night++;
if(night>=3){
gameOver=true;
say("YOU DID IT! You completed three cozy nights! 🏆");
setTimeout(()=>alert("🏆 FOREST CHAMPION! 🏆\nYou made it through all three nights!\nEven the grumpy deer is impressed!"),200);
}else{
say("Night "+night+" complete! The grumpy deer is back in the forest!");
deer.active=false;
startDeer();
}
updateStats();
}
function caught(){
say('BONK! The grumpy deer gave you a silly head bump! Back to camp!');
player.x=9;player.z=12;
deer.x=3;deer.z=3;
wood=Math.max(0,wood-1);
sound(130);
updateStats();
}
function update(dt){
time+=dt;
if(deer.active&&!gameOver){
if(deer.stun>0){deer.stun-=dt;}
else{
let d=distance(deer,player);
if(d>.65){
let speed=.9+night*.13;
deer.x+=(player.x-deer.x)/d*speed*dt;
deer.z+=(player.z-deer.z)/d*speed*dt;
}
if(d<.75) caught();
}
}
// Automatic deer arrival every 18 seconds
if(!deer.active&&time>18&&!gameOver){
time=0;startDeer();
}
if(messageTimer>0)messageTimer-=dt;
}
function loop(ts){
let dt=Math.min((ts-last)/1000||0,.05);last=ts;
let dx=0,dz=0;
if(keys.up||keys.w)dz-=1;
if(keys.down||keys.s)dz+=1;
if(keys.left||keys.a)dx-=1;
if(keys.right||keys.d)dx+=1;
if(dx||dz){
let l=Math.hypot(dx,dz);
move(dx/l*3*dt,dz/l*3*dt);
}
update(dt);
render();
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
window.addEventListener("keydown",e=>{
const k=e.key.toLowerCase();
if(["arrowup","arrowdown","arrowleft","arrowright"," "].includes(k))e.preventDefault();
if(k.startsWith("arrow"))keys[
{arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right"}[k]
]=true;
else keys[k]=true;
});
window.addEventListener("keyup",e=>{
const k=e.key.toLowerCase();
if(k.startsWith("arrow"))keys[
{arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right"}[k]
]=false;
else keys[k]=false;
});
document.querySelectorAll("[data-dir]").forEach(btn=>{
const dir=btn.dataset.dir;
btn.addEventListener("pointerdown",e=>{
e.preventDefault();keys[dir]=true;btn.classList.add("active");
btn.setPointerCapture(e.pointerId);
});
function release(e){
keys[dir]=false;btn.classList.remove("active");
}
btn.addEventListener("pointerup",release);
btn.addEventListener("pointercancel",release);
btn.addEventListener("lostpointercapture",release);
});
updateStats();
</script>
</body>
</html>
Game Source: Forest Friends 3D: Grumpy Deer Chase
Creator: LunarFlare59
Libraries: none
Complexity: complex (517 lines, 14.7 KB)
The full source code is displayed above on this page.
Remix Instructions
To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: forest-friends-3d-grumpy-deer-chase-lunarflare59" to link back to the original. Then publish at arcadelab.ai/publish.