🏠 Games Tutorials Dev blog JS code golf Other projects

Floppy dragon

February 2014

Introduction:

One of my entries for JS1k 2014's contest: a Flappy Bird clone in 1kb.
Play with mouse. The hitbox is located on the dragon's head only.
You can read a post-mortem of this game in the tech blog.

Github:

https://github.com/xem/flappydragon

Play:

https://js1k.com/2014-dragons/demo/1704

Source code:

c.scale(a.height/1E3,a.height/1E3);d=e=f=h=0;g=[];for(o=0;1E3>o;o++)g[o]=g[o+1E3]=8*Math.random()|0;i=j=300;k=20;l=50;ontouchstart=onmousedown=function(){if(e){d=e=f=h=0;g=[];for(o=0;1E3>o;o++)g[o]=g[o+1E3]=8*Math.random()|0;i=j=300;k=20;l=50}else h=45,d=1};(n=function(){c.fillStyle="#E50";c.fillRect(0,0,4E4,4E4);c.fillStyle="#920";c.beginPath();c.moveTo(-k,0);for(o=2E3;o--;)o%20?c.lineTo(40*o-k,20+4*g[o]):(c.lineTo(40*o-k,100*g[o]),c.lineTo(40*o-k-4,100*g[o]));c.lineTo(40*o-k,0);c.fill();c.beginPath();c.moveTo(-k,2E3);for(o=2E3;o--;)o%20?c.lineTo(40*o-k,980-4*g[o]):(c.lineTo(40*o-k,100*(g[o]+3)),c.lineTo(40*o-k-4,100*(g[o]+3)));c.lineTo(40*o-k,1E3);c.fill();p="fEFf&{{~_=,;=vviJ.jfVi/.OoyizyhkhEwf74)\n$fwwuvtU`"+(10>4),z=16-2*(p.charCodeAt(o)&15),c.lineTo(v+=e?y:z,w+=e?-z:y);c.fill();d&&(h-=6);d&&!e&&(k+=20,4E4j||950100*g[20*~~(k/800)+20]+250))e=40;c.fillStyle="#fff";c.font="6em Arial";d&&c.fillText(f,a.width/(a.height/1E3)/2,500);d||c.fillText("Flappy Dragon",a.width/(a.height/1E3)/2-300,500);e&&c.fillText("score",a.width/(a.height/1E3)/2-80,400);c.fillText(e?"restart":d?"":"start",a.width/(a.height/1E3)/2-100,600);setTimeout(n,l)})()

Demo: