🎮ArcadeLab

Island Survival 2018

by MagicEagle14
124 lines3.7 KB
▶ Play

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Island Survival 2018</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#172c24;color:white;font-family:Arial;overflow:hidden}
#game{width:100vw;height:100dvh;display:block}
#hud{position:absolute;top:12px;left:12px;right:12px;display:flex;justify-content:space-between;pointer-events:none}
#stick{position:absolute;bottom:35px;left:25px;width:115px;height:115px;border-radius:50%;background:#ffffff35;border:2px solid white;touch-action:none}
#knob{position:absolute;left:34px;top:34px;width:43px;height:43px;border-radius:50%;background:white}
#jump{position:absolute;right:25px;bottom:55px;border:0;border-radius:50%;width:75px;height:75px;background:#e9a52b;color:#111;font-weight:bold}
#start{position:absolute;inset:0;background:#153a30;display:flex;align-items:center;justify-content:center;flex-direction:column;text-align:center}
#start button{padding:15px 35px;background:#f2a52b;border:0;border-radius:12px;font-size:20px}
</style>
</head>
<body>
<div id="hud"><b>ISLAND SURVIVAL</b><b id="score">Score: 0</b></div>
<canvas id="game"></canvas>
<div id="stick"><div id="knob"></div></div>
<button id="jump">JUMP</button>
<div id="start">
<h1>ISLAND SURVIVAL</h1>
<p>Explore the island and collect coins!</p>
<button onclick="begin()">PLAY GAME</button>
</div>
<script>
const c=document.getElementById("game");
const ctx=c.getContext("2d");
let W,H,playing=false,score=0;
let px=0,pz=0,dx=0,dz=0;
let coins=[];
function resize(){
W=c.width=innerWidth;
H=c.height=innerHeight;
}
addEventListener("resize",resize);
resize();

for(let i=0;i<25;i++){
coins.push({x:Math.random()*1200-600,z:Math.random()*1200-600,taken:false});
}
function begin(){
document.getElementById("start").style.display="none";
playing=true;
loop();
}
function drawTree(x,y,s){
ctx.fillStyle="#633b21";
ctx.fillRect(x-5*s,y,10*s,30*s);
ctx.fillStyle="#187a3c";
ctx.beginPath();ctx.arc(x,y,23*s,0,Math.PI*2);ctx.fill();
}
function loop(){
if(!playing)return;
ctx.fillStyle="#4e9a52";
ctx.fillRect(0,0,W,H);
let horizon=H*.43;
ctx.fillStyle="#62b9db";
ctx.fillRect(0,0,W,horizon);
ctx.fillStyle="#d6c38a";
ctx.fillRect(0,horizon,W,H-horizon);
ctx.fillStyle="#398b4a";
ctx.beginPath();
ctx.ellipse(W/2,H*.68,Math.min(W*.48,420),H*.35,0,0,Math.PI*2);
ctx.fill();
for(let i=0;i<18;i++){
let x=((i*173-px*.3)%W+W)%W;
let y=horizon+((i*91-pz*.3)%(H-horizon));
drawTree(x,y,.7);
}
coins.forEach(o=>{
if(o.taken)return;
let x=W/2+(o.x-px)*.45;
let y=H*.65+(o.z-pz)*.35;
if(x>0&&x<W&&y>horizon&&y<H){
ctx.fillStyle="#ffdb36";
ctx.beginPath();ctx.arc(x,y,9,0,Math.PI*2);ctx.fill();
}
});
ctx.fillStyle="#293cbb";
ctx.fillRect(W/2-13,H*.58,26,38);
ctx.fillStyle="#f0c19a";
ctx.beginPath();ctx.arc(W/2,H*.56,12,0,Math.PI*2);ctx.fill();
coins.forEach(o=>{
if(!o.taken&&Math.hypot(o.x-px,o.z-pz)<30){
o.taken=true;score++;
document.getElementById("score").textContent="Score: "+score;
}
});
requestAnimationFrame(loop);
}
function move(){
px+=dx*3;pz+=dz*3;
}
setInterval(()=>{if(playing)move()},30);

let stick=document.getElementById("stick");
let knob=document.getElementById("knob");
stick.addEventListener("pointermove",e=>{
if(!e.buttons)return;
let r=stick.getBoundingClientRect();
let x=e.clientX-r.left-57.5;
let y=e.clientY-r.top-57.5;
let d=Math.hypot(x,y);
if(d>35){x=x*35/d;y=y*35/d}
knob.style.left=(34+x)+"px";
knob.style.top=(34+y)+"px";
dx=x/35;dz=y/35;
});
function resetStick(){
dx=0;dz=0;knob.style.left="34px";knob.style.top="34px";
}
stick.addEventListener("pointerup",resetStick);
stick.addEventListener("pointercancel",resetStick);
document.getElementById("jump").onclick=()=>{
if(playing){score+=0; }
};
</script>
</body>
</html>

Game Source: Island Survival 2018

Creator: MagicEagle14

Libraries: none

Complexity: moderate (124 lines, 3.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: island-survival-2018-magiceagle14" to link back to the original. Then publish at arcadelab.ai/publish.