In a casual conversation, someone mentioned making a "Ninja Phone" game and I wondered what ChatGPT would give me out of that.
It didn't give anything I expected but it was a somewhat working game.
The limitations are that ChatGPT has a limit to how much it will output, so adding code-golfed version helps with getting more out of it.
The code-golfing ability was okay. When I said "minified," It didn't understand what I meant, so I changed it to code-golfed version and it worked.
- Write code for game called "Phone Ninja" using JavaScript
- Write a code-golfed version of this code in one HTML file.
- Collision with objects lost lives.
- Falling past the bottom of the screen was not losing lives.
- Increase the falling speed for each point earned.
- Added emojis
data:text/html,<title>Phone Ninja</title><meta charset=utf8><canvas id=c width=400 height=500 style="border:1px solid black"></canvas><script>x=c.getContext`2d`,k={l:false,r:false};onkeydown=e=>["a","ArrowLeft"].includes(e.key)?k.l=true:["d","ArrowRight"].includes(e.key)&&(k.r=true);onkeyup=e=>["a","ArrowLeft"].includes(e.key)?k.l=false:["d","ArrowRight"].includes(e.key)&&(k.r=false);p={x:175,y:460,w:50,h:30,s:7,draw:()=>{x.fillStyle="green";x.fillRect(p.x,p.y,p.w,p.h);x.fillText("π±βπ€",p.x+15,p.y+10)},update:()=>{k.l&&p.x>p.s&&(p.x-=p.s),k.r&&p.x<(c.width-p.w-p.s)&&(p.x+=p.s)}},e={x:Math.random()*(c.width-50),y:0,w:50,h:50,s:2,draw:()=>{x.fillStyle="red";x.fillRect(e.x,e.y,e.w,e.h);x.fillText("π±",e.x+15,e.y+30);},update:()=>{e.y+=e.s,e.y>c.height+50 &&(e.y=0,e.x=Math.random()*(c.width-50))}},s=0,l=3,g=false,d=()=>{if(!g){e.update(),x.clearRect(0,0,c.width,c.height),p.draw(),p.update(),e.draw(),e.y>c.height&&(l--,e.y=0,l<=0&&(g=true,x.fillStyle="black",x.font="30px Arial",x.fillText("ππππ",125,250))),x.fillStyle="black",x.font="20px Arial",x.fillText(`π΅ Score: $${s}`,10,30),x.fillText(`π Lives: ${l}`,10,60),e.x+e.w>p.x&&e.x<p.x+p.w&&e.y+e.h>p.y&&(s++,e.s+=1,p.s+=1,e.y=0,e.x=Math.random()*(c.width-50))}requestAnimationFrame(d)};d();</script>