Skip to content

Instantly share code, notes, and snippets.

@lewdev
Last active March 22, 2023 01:46
Show Gist options
  • Select an option

  • Save lewdev/f87e630c734c41b5b454667f2012c0d9 to your computer and use it in GitHub Desktop.

Select an option

Save lewdev/f87e630c734c41b5b454667f2012c0d9 to your computer and use it in GitHub Desktop.
πŸ±β€πŸ‘€ Ninja Phone By ChatGPT

πŸ±β€πŸ‘€ Ninja Phone By ChatGPT

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.

πŸ—£ The prompts I used

  • Write code for game called "Phone Ninja" using JavaScript
  • Write a code-golfed version of this code in one HTML file.

πŸ›  Adjustments made

  • 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

πŸ“­ Copy-paste code into address bar

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment