Skip to content

Instantly share code, notes, and snippets.

@liamstrilchuk
Last active November 30, 2020 07:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamstrilchuk/848df92b56bd329e23294e20316a7ac6 to your computer and use it in GitHub Desktop.
Save liamstrilchuk/848df92b56bd329e23294e20316a7ac6 to your computer and use it in GitHub Desktop.
Flappy Bird in 373 bytes
<body onload="z=c.getContext`2d`;c.width=W=400,c.height=H=600,Y=E=200,Q=z.fillRect.bind(z),M=S=p=0;N=M=>z.fillStyle=M;c.onclick=_=>M=9;R=_=>{M=S=p=0,Y=E};setInterval(_=>{p=p||[W,Math.random()*W],N`red`,Q(0,0,W,H),Y-=M-=.5,X=p[0]-=8,N`black`,Q(X,0,V=50,Z=p[1]),Q(X,Z+E,V,H),(Y<Z||Y>Z+E)&&X<B&&R(),X<-V&&(p=0,S++),Y>H&&R(),Q(0,Y-9,B,B),z.fillText(S,9,B)},B=24)"><canvas id=c>
@liamstrilchuk
Copy link
Author

liamstrilchuk commented Sep 11, 2020

Dataurl:

data:text/html,<body onload="z=c.getContext`2d`;c.width=W=400,c.height=H=600,Y=E=200,Q=z.fillRect.bind(z),M=S=p=0;N=M=>z.fillStyle=M;c.onclick=_=>M=9;R=_=>{M=S=p=0,Y=E};setInterval(_=>{p=p||[W,Math.random()*W],N`red`,Q(0,0,W,H),Y-=M-=.5,X=p[0]-=8,N`black`,Q(X,0,V=50,Z=p[1]),Q(X,Z+E,V,H),(Y<Z||Y>Z+E)&&X<B&&R(),X<-V&&(p=0,S++),Y>H&&R(),Q(0,Y-9,B,B),z.fillText(S,9,B)},B=24)"><canvas id=c>

@liamstrilchuk
Copy link
Author

Copy link

ghost commented Sep 12, 2020

Should this:

(Y<Z||Y>Z+E)&&X<V

be this: ...?

(Y<Z||Y>Z+E)&&X<B

@liamstrilchuk
Copy link
Author

@mauvexephos Yeah, it works better that way. It just changes how close you have to get to the pipes to die (B: 24px, V: 50px).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment