b=document,e=480,f=-45,h=270,i=4,k=37,l=m=0,n=250,q=400,r=[],s=15,z="http://www.w3.org/2000/svg",B="transform",C="setAttribute",D="translate(",E="createElementNS",F="appendChild",H="rotate(",J="fill",K="#fe0",N=.017;a=b[E](z,"svg");a[C]("width",e);a[C]("height",e);a[C]("style","background:#000");b.body[F](a);t=b.createElement("b");b.body[F](t);for(u=s;u<e;u+=30){G=[];for(v=s;v<e;v+=30)w=b[E](z,"circle"),w[C]("r","5"),w[C](J,K),w[C](B,D+u+","+v+")"),a[F](w),G.push(w);r.push(G)}x=b[E](z,"g");a[F](x);y=b[E](z,"path");y[C](J,K);x[F](y);onkeydown=function(e){k=e.which};setInterval(function(){if(f>0||f<-45)i=-i;f+=i,h+=i*2,g=s-s*Math.cos(h*N),o=s*Math.sin(h*N);y[C](B,H+f+")");y[C]("d","M0,0 h-"+s+" a"+s+","+s+" 0 1,0 "+g+","+o+" z");if(k==40)l=270,q<e-s?q+=5:0;if(k==39)l=180,n<e-s?n+=5:0;if(k==38)l=90,q>s?q-=5:0;if(k==37)l=0,n>s?n-=5:0;x[C](B,D+n+","+q+"),"+H+l+")");g=s;for(o=0;g<e;g+=30,o++){G=r[o];for(p=s,A=0;p<e;p+=30,A++){w=G[A];if(!w.a&&g>n-s&&g<n+s&&p>q-s&&p<q+s)w[C](J,""),w.a=1,m+=10}}t.innerHTML=m},25)
var svgns = "http://www.w3.org/2000/svg",
paper,
doc = document,
setAttribute = "setAttribute",
createElementNS = "createElementNS",
appendChild = "appendChild",
playfieldSize = 480,
rotation = -45,
angle = 270,
rotChange = 4,
playerDir = 37,
playerRot = score = 0,
x = 250,
y = 400,
dots = [],
playerRadius = 15;
paper = doc[createElementNS](svgns, "svg");
paper[setAttribute]("width", playfieldSize);
paper[setAttribute]("height", playfieldSize);
paper[setAttribute]("style", "background:#000");
doc.body[appendChild](paper);
var scoreBlock = doc.createElement("b");
doc.body[appendChild](scoreBlock);
// dots
for(var i = playerRadius; i < playfieldSize; i += 30) {
dotRow = [];
for(var j = playerRadius; j < playfieldSize; j += 30)
dot = doc[createElementNS](svgns, "circle"),
dot[setAttribute]("r", "5"),
dot[setAttribute]("fill", "#fe0"),
dot[setAttribute]("transform", "translate("+i+","+j+")"),
paper[appendChild](dot),
dotRow.push(dot);
dots.push(dotRow);
}
var player = doc[createElementNS](svgns, "g");
paper[appendChild](player);
var playerPath = doc[createElementNS](svgns, "path");
playerPath[setAttribute]("fill", "#fe0");
player[appendChild](playerPath);
// could save two more bytes on keyup...
onkeydown = function(e) {
// which is shorter than keyCode
playerDir = e.which;
};
setInterval(function() {
if (rotation >= -1 || rotation < -45) {
rotChange = -rotChange;
}
rotation += rotChange;
angle += rotChange*2;
var xpos = playerRadius - playerRadius * Math.cos(angle * (Math.PI/180));
var ypos = playerRadius * Math.sin(angle * (Math.PI/180));
playerPath[setAttribute]("transform", "rotate(" + rotation + ")");
playerPath[setAttribute]("d", "M0,0 h-"+playerRadius+" a"+playerRadius+","+playerRadius+" 0 1,0 " + xpos + "," + ypos + " z");
// Animate player position based on user set direction (arrow keys)
// while keeping the player inside the board
if (playerDir == 40) //down
playerRot = 270,
(y < playfieldSize - playerRadius)? y += 5:0;
if (playerDir == 39) //right
playerRot = 180,
(x < playfieldSize - playerRadius)? x += 5:0;
if (playerDir == 38) //up
playerRot = 90,
(y > playerRadius)? y -= 5:0;
if (playerDir == 37) //left
playerRot = 0,
(x > playerRadius)? x -= 5:0;
player[setAttribute]("transform", "translate(" + x + "," + y + "), rotate(" + playerRot + ")");
for(var i = playerRadius, k = 0; i < playfieldSize; i += 30, k++) {
dotRow = dots[k];
for(var j = playerRadius, l = 0; j < playfieldSize; j += 30, l++) {
dot = dotRow[l];
// collision detection
if (!dot.hidden && i > x-playerRadius && i < x+playerRadius && j > y-playerRadius && j < y+playerRadius)
dot[setAttribute]("fill", ""),
dot.hidden = 1,
score += 10;
}
}
scoreBlock.innerHTML = score;
}, 25)