🎮ArcadeLab

Godistjuven

by BlazeCoder92
140 lines14.3 KB
▶ Play
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Godistjuven</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap">
<style>
:root{--paper:#fbf6e6;--ink:#262320;--candy:#ff3d86;--sun:#ffd23f;--ok:#2e8f57;--warn:#d98a00;--bad:#d62839;
box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){--paper:#17171f;--ink:#f1ede2;--ok:#5fd68c;--warn:#ffb938;--bad:#ff6b78}}
:root[data-theme="dark"]{--paper:#17171f;--ink:#f1ede2;--ok:#5fd68c;--warn:#ffb938;--bad:#ff6b78}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0}
body{max-width:760px;margin:0 auto;width:100%}
body{background:var(--paper);color:var(--ink);font-family:"Patrick Hand","Comic Sans MS",cursive;font-size:1.15rem;display:flex;flex-direction:column;gap:8px;padding:10px 12px;overflow:hidden;user-select:none;-webkit-user-select:none}
.hud{display:flex;justify-content:space-between;align-items:baseline;font-size:1.4rem}
.hud b{font-weight:400;font-size:1.7rem}
#wrap{position:relative;flex:1;min-height:0;display:flex;align-items:center}
svg{width:100%;max-height:100%}
.l{stroke:var(--ink);stroke-width:2.4;stroke-linecap:round;stroke-linejoin:round;fill:none}
.f{fill:var(--paper)}
.o{stroke:#161616;stroke-width:1.6;stroke-linejoin:round;stroke-linecap:round}
.t{fill:var(--ink);font-family:inherit}
#boss{transition:transform .35s ease-in-out;transform-origin:285px 120px}
#boss.away{transform:scaleX(-1)}
#boss.warn{animation:wob .18s infinite alternate}
@keyframes wob{from{transform:rotate(-2deg)}to{transform:rotate(2deg)}}
#boss.away.warn{animation:none}
#me.hit{animation:shake .12s 8}
@keyframes shake{50%{transform:translateX(3px)}}
#plantF{display:none}
#status{text-align:center;min-height:1.6em;font-size:1.35rem}
.btns{display:flex;gap:8px;margin-bottom:4px}
.btns button{font:inherit;font-size:1.5rem;color:#fff;border:3px solid var(--ink);border-radius:18px;padding:18px 6px;touch-action:none}
#hold{flex:2;background:var(--candy)}
#hide{flex:1;background:#3fae5a}
.btns button.on{transform:translateY(2px);filter:brightness(.88)}
button:focus-visible{outline:3px solid var(--ink);outline-offset:3px}
#bust{position:absolute;inset:0;display:none;align-items:center;justify-content:center;background:color-mix(in srgb,var(--paper) 94%,transparent);z-index:5}
#bust svg{width:min(86vw,320px);max-height:100%}
#bust .lolli{transform:translate(250px,70px)}#bust .tongue,#bust .lips{opacity:0}#bust.go .tongue{animation:lick 4.2s}#bust.go .lips{animation:lips 4.2s forwards}
#bust.go .lolli{animation:lmove 4.2s ease-in-out forwards}
@keyframes lmove{0%{transform:translate(250px,70px)}33%,64%{transform:translate(124px,134px)}72%,100%{transform:translate(102px,137px)}}@keyframes lick{0%,34%{opacity:0;transform:translate(0,0)}36%{opacity:1;transform:translate(0,0)}42%{opacity:1;transform:translate(9px,-3px)}48%{opacity:1;transform:translate(0,0)}54%{opacity:1;transform:translate(9px,-3px)}60%{opacity:1;transform:translate(0,0)}62%,100%{opacity:0}}@keyframes lips{0%,70%{opacity:0}74%,100%{opacity:1}}
#bust .ring,#bust .cheek{transform-box:fill-box;transform-origin:center}
#bust.go .ring{animation:ring .4s ease-out}
@keyframes ring{from{transform:scale(1.7);opacity:0}}
#bust.go .cheek{animation:puff 4.2s}
@keyframes puff{0%,80%{transform:scale(1)}84%{transform:scale(1.45)}88%{transform:scale(1)}92%{transform:scale(1.45)}96%,100%{transform:scale(1)}}
#ov{position:absolute;inset:0;background:color-mix(in srgb,var(--paper) 92%,transparent);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;text-align:center;padding:16px}
#ov h2{margin:0;font-size:2rem;font-weight:400}
#ov p{margin:0;max-width:32ch;line-height:1.25}
#go{font:inherit;font-size:1.5rem;background:var(--candy);color:#fff;border:3px solid var(--ink);border-radius:18px;padding:10px 28px}
</style>
</head>
<body>
<div class="hud"><span id="lives">♥♥♥</span><span>Godis: <b id="score">0</b></span></div>
<div id="wrap">
<svg id="scene" viewBox="0 0 360 200" role="img" aria-label="Ett kontor där en tecknad kille smyger mot en godispåse medan chefen sitter i sin stol">
<defs><g id="plant">
  <ellipse class="o" cx="-14" cy="-30" rx="7" ry="20" fill="#3f9e4d" transform="rotate(-20 -14 -30)"/><ellipse class="o" cx="14" cy="-30" rx="7" ry="20" fill="#3f9e4d" transform="rotate(20 14 -30)"/>
  <ellipse class="o" cx="0" cy="-38" rx="11" ry="28" fill="#4cb85c"/><path class="o" d="M-12 0L-9 -16H9L12 0Z" fill="#c26b3a"/>
</g></defs>
<g transform="translate(0,26)">
  <path class="l" d="M0 160H360M100 -26V50M100 50V160"/>
  <rect class="l f" x="116" y="-14" width="54" height="18"/><text class="t" x="143" y="0" font-size="12" text-anchor="middle">CHEFEN</text>
  <rect class="l f" x="322" y="30" width="30" height="62"/><path class="l" d="M337 30V92M322 61H352"/><circle cx="330" cy="44" r="6" fill="var(--sun)" stroke="var(--ink)" stroke-width="1.6"/>
  <rect class="o" x="163" y="112" width="62" height="7" rx="1.5" fill="#c58d4f"/><rect class="o" x="167" y="119" width="17" height="41" fill="#a9743a"/><rect class="o" x="204" y="119" width="17" height="41" fill="#a9743a"/><rect class="o" x="184" y="119" width="20" height="36" fill="#8a5a2a"/><path class="o" fill="none" d="M167 132H184M167 146H184M204 132H221M204 146H221"/><circle cx="175.5" cy="125.5" r="1.8" fill="#4a2e12"/><circle cx="175.5" cy="139" r="1.8" fill="#4a2e12"/><circle cx="175.5" cy="153" r="1.8" fill="#4a2e12"/><circle cx="212.5" cy="125.5" r="1.8" fill="#4a2e12"/><circle cx="212.5" cy="139" r="1.8" fill="#4a2e12"/><circle cx="212.5" cy="153" r="1.8" fill="#4a2e12"/><path fill="none" stroke="#8a5a2a" stroke-width="1" stroke-linecap="round" d="M168 115.5H190M196 116H218"/>
  <path class="l f" d="M184 112L186 90Q196 84 206 90L208 112Z"/><path class="l" d="M185 90L189 83L194 89L199 82L204 89L207 84"/>
  <text class="t" x="196" y="105" font-size="8" text-anchor="middle">GODIS</text>
  <ellipse cx="177" cy="109" rx="4" ry="2.6" fill="var(--candy)" stroke="var(--ink)" stroke-width="1.4"/><ellipse cx="214" cy="109" rx="4" ry="2.6" fill="var(--candy)" stroke="var(--ink)" stroke-width="1.4"/>
  <use href="#plant" x="135" y="160"/>
  <g id="boss">
    <path class="l" d="M285 160V130M268 158H302"/><circle class="l f" cx="268" cy="158" r="2.5"/><circle class="l f" cx="285" cy="158" r="2.5"/><circle class="l f" cx="302" cy="158" r="2.5"/>
    <path class="l" style="stroke-width:3.6" d="M270 127H297M297 127Q305 108 299 86"/>
    <rect class="o" x="262" y="122" width="20" height="9" rx="4" fill="#2a2f45"/><rect class="o" x="259" y="124" width="9" height="30" rx="4" fill="#2a2f45"/><ellipse class="o" cx="257" cy="154" rx="7" ry="3.5" fill="#111"/>
    <rect class="o" x="268" y="97" width="28" height="30" rx="9" fill="#3a3a3f"/><path class="o" fill="none" d="M271 99Q283 109 295 99M276 104V126"/>
    <rect class="o" x="264" y="104" width="14" height="9" rx="4" fill="#3a3a3f"/><ellipse class="o" cx="262" cy="109" rx="4.5" ry="3.8" fill="#ffd9a8"/>
    <circle class="o" cx="283" cy="84" r="14" fill="#ffe3cc"/><path d="M270 88Q272 98 283 99Q294 98 296 88Q290 94 283 94Q276 94 270 88Z" fill="#a88a5a" opacity=".55"/><path class="o" d="M269 83Q266 66 281 65Q298 62 298 79Q292 71 283 73Q274 72 269 83Z" fill="#d9b36a"/><circle cx="296" cy="87" r="2.6" fill="#fff" stroke="#161616" stroke-width="1"/>
    <ellipse class="o" cx="279.5" cy="85" rx="3.7" ry="4.8" fill="#fff"/><ellipse class="o" cx="273" cy="85" rx="3.7" ry="4.8" fill="#fff"/><circle cx="278.3" cy="85" r="1.3" fill="#111"/><circle cx="271.8" cy="85" r="1.3" fill="#111"/>
    <path d="M269 94Q273 97 277 94" fill="none" stroke="#161616" stroke-width="1.4" stroke-linecap="round"/><path class="o" fill="none" style="stroke-width:1.8" d="M270 95L254 100"/><circle class="o" cx="269" cy="95" r="5" fill="#ff3d86"/><path fill="none" stroke="#fff" stroke-width="1" stroke-linecap="round" d="M269 95a.8 .8 0 1 1 .8 .8a1.8 1.8 0 1 1 -1.8 -1.8a3 3 0 1 1 3 3"/>
  </g>
  <text id="bub" class="t" x="285" y="58" font-size="24" text-anchor="middle"></text>
  <g id="me"><g id="flip">
    <rect id="lA" class="o" x="-9" y="-9" width="7" height="9" rx="3" fill="#2b3a67"/><rect id="lB" class="o" x="2" y="-9" width="7" height="9" rx="3" fill="#2b3a67"/>
    <rect class="o" x="-12" y="-30" width="24" height="24" rx="9" fill="#7a7480"/><path class="o" fill="none" d="M5 -29V-7"/><ellipse class="o" cx="12" cy="-20" rx="4.5" ry="3.5" fill="#f1caa0"/>
    <circle class="o" cx="1" cy="-43" r="15" fill="#f1caa0"/><path class="o" d="M-12 -34Q-12 -26 1 -26Q14 -26 15 -34Q11 -30 1 -30Q-8 -30 -12 -34Z" fill="#2a1c14"/><path class="o" d="M-14 -46A15 15 0 0 1 16 -46Q9 -51 1 -50Q-6 -51 -14 -46Z" fill="#1d1a19"/>
    <ellipse class="o" cx="4.5" cy="-42" rx="3.8" ry="4.8" fill="#fff"/><ellipse class="o" cx="11" cy="-42" rx="3.8" ry="4.8" fill="#fff"/><circle cx="5.7" cy="-42" r="1.3" fill="#111"/><circle cx="12.2" cy="-42" r="1.3" fill="#111"/>
    <path d="M6 -35Q10 -33 13 -36" fill="none" stroke="#f0a0a0" stroke-width="1.6" stroke-linecap="round"/><path d="M1 -49L8 -49.5M10 -49.5L16 -48" stroke="#1d1a19" stroke-width="2" stroke-linecap="round"/>
    <g id="cin" style="display:none" transform="translate(14,-24)"><ellipse rx="5" ry="3.2" fill="var(--candy)" stroke="#161616" stroke-width="1.4"/><path class="o" fill="none" style="stroke-width:1.3" d="M-5 0L-8 -3M-5 0L-8 3M5 0L8 -3M5 0L8 3"/></g>
  </g></g>
  <use id="plantF" href="#plant" x="135" y="160"/>
</g>
</svg>
<div id="bust"><svg viewBox="0 0 220 210" aria-hidden="true"><text class="t" x="110" y="28" font-size="28" text-anchor="middle" style="fill:var(--bad)">Ertappad!</text><g transform="translate(0,20)"><circle class="ring" cx="100" cy="100" r="80" fill="none" stroke="#d62839" stroke-width="6"/><circle class="o" cx="42" cy="104" r="10" fill="#ffe3cc"/><circle cx="41" cy="106" r="3.5" fill="#fff" stroke="#161616" stroke-width="1"/><circle class="o" cx="158" cy="104" r="10" fill="#ffe3cc"/><circle class="o" cx="100" cy="100" r="58" fill="#ffe3cc"/><path d="M44 112Q48 160 100 160Q152 160 156 112Q132 146 100 146Q68 146 44 112Z" fill="#a88a5a" opacity=".5"/><path class="o" d="M42 92Q30 36 90 34Q150 24 158 92Q140 56 100 62Q60 58 42 92Z" fill="#d9b36a"/><path d="M66 72L92 70M108 70L134 72" stroke="#7a5a2a" stroke-width="4" stroke-linecap="round"/><ellipse class="o" cx="80" cy="92" rx="12" ry="15" fill="#fff"/><ellipse class="o" cx="120" cy="92" rx="12" ry="15" fill="#fff"/><circle cx="80" cy="96" r="4" fill="#111"/><circle cx="120" cy="96" r="4" fill="#111"/><circle class="cheek" cx="68" cy="128" r="9" fill="#ff9aa8" opacity=".6"/><circle class="cheek" cx="132" cy="128" r="9" fill="#ff9aa8" opacity=".6"/><path d="M100 102L96 117H104" fill="none" stroke="#161616" stroke-width="2" stroke-linecap="round"/><ellipse cx="100" cy="136" rx="9" ry="5" fill="#8a2a2a" stroke="#161616" stroke-width="1.6"/><ellipse class="tongue" cx="100" cy="140" rx="9" ry="4.5" fill="#ff6b81" stroke="#161616" stroke-width="1.2"/><g class="lolli"><path d="M0 0L66 -20" stroke="#161616" stroke-width="5" stroke-linecap="round"/><path d="M0 0L66 -20" stroke="#fff" stroke-width="2.6" stroke-linecap="round"/><circle class="o" r="9" fill="#ff3d86"/><path fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" d="M0 0a1.5 1.5 0 1 1 1.5 1.5a3.5 3.5 0 1 1 -3.5 -3.5a5.5 5.5 0 1 1 5.5 5.5"/><ellipse class="o" cx="44" cy="-13" rx="8" ry="6.5" fill="#ffe3cc"/></g><ellipse class="lips" cx="100" cy="137" rx="13" ry="10" fill="#e8828e" stroke="#161616" stroke-width="1.6"/></g></svg></div>
<div id="ov"><h2 id="ot">Godistjuven</h2><p id="op">Chefen har en påse godis. Smyg in när han tittar ut genom fönstret, sno en godis och ta ut den. När han vänder sig: ställ dig vid krukan och håll in Göm!</p><button id="go">Börja smyga</button></div>
</div>
<div id="status">&nbsp;</div>
<div class="btns"><button id="hold">Smyg</button><button id="hide">Göm</button></div>
<script>
const $=id=>document.getElementById(id);
const DOOR=100,BAG=162,HOME=42,PLANT=135,SPEED=58;
let px=24,dir=1,carry=false,score=0,lives=3,run=false,hold=false,hold2=false,hidden=false,ph=0,freeze=0,best=0,last=0;
let boss={s:"window",t:2.5},msgT=0;
try{best=+localStorage.getItem("godistjuven-best")||0}catch(e){}
const rnd=(a,b)=>a+Math.random()*(b-a);
const lvl=()=>Math.min(1+score*.1,1.8);
function say(t,c){const s=$("status");s.textContent=t;s.style.color=c}
function stateMsg(){
  if(boss.s==="window")say("Han tittar ut. Smyg!","var(--ok)");
  else if(boss.s==="warn")say("Stolen knarrar! Göm dig!","var(--warn)");
  else say("Han tittar! Göm dig eller stå utanför","var(--bad)")}
function flash(t,c){say(t,c);msgT=1.4}
function setBoss(s){
  boss.s=s;const b=$("boss");
  if(s==="window"){boss.t=rnd(2,3.4)/lvl();b.classList.add("away");b.classList.remove("warn");$("bub").textContent=""}
  if(s==="warn"){boss.t=.8;b.classList.add("warn");$("bub").textContent="?"}
  if(s==="watch"){boss.t=rnd(1.2,2.2)*(1+(lvl()-1)*.8);b.classList.remove("away","warn");$("bub").textContent=""}
  if(msgT<=0)stateMsg()}
function caught(){
  lives--;carry=false;px=24;freeze=4.3;hold=false;showBust();$("hold").classList.remove("on");
  $("bub").textContent="";$("me").classList.add("hit");setTimeout(()=>$("me").classList.remove("hit"),1000);
  const n=Math.max(lives,0);$("lives").textContent="♥".repeat(n)+"♡".repeat(3-n);
  flash("Ertappad!","var(--bad)");
  if(lives<=0)setTimeout(end,4200)}
function showBust(){const b=$("bust");b.classList.remove("go");void b.offsetWidth;b.style.display="flex";b.classList.add("go")}
function draw(moving){
  const a=Math.sin(ph)*5;
  $("lA").setAttribute("transform",`translate(${moving?a:0},0)`);$("lB").setAttribute("transform",`translate(${moving?-a:0},0)`);
  $("cin").style.display=carry?"block":"none";
  $("flip").setAttribute("transform",`scale(${dir},1)`);
  $("me").setAttribute("transform",`translate(${px},160)`);
  $("me").style.visibility=hidden?"hidden":"visible";$("plantF").style.display=hidden?"block":"none"}
function tick(now){
  const dt=Math.min((now-last)/1000||0,.05);last=now;
  if(run){
    if(msgT>0){msgT-=dt;if(msgT<=0)stateMsg()}
    if(freeze>0){freeze-=dt;if(freeze<=0&&lives>0){$("bust").style.display="none";setBoss("window");boss.t=2;stateMsg()}}
    if(freeze<=0)boss.t-=dt;if(boss.t<=0&&freeze<=0&&lives>0)setBoss(boss.s==="window"?"warn":boss.s==="warn"?"watch":"window");
    hidden=freeze

Game Source: Godistjuven

Creator: BlazeCoder92

Libraries: none

Complexity: moderate (140 lines, 14.3 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: godistjuven-blazecoder92" to link back to the original. Then publish at arcadelab.ai/publish.