c.width=w=800;c.height=h=500;c.style.backgroundColor="#69c";c.style.cursor="crosshair";f="fillStyle";for(p in a){a[p[0]+(p[6]||"")]=a[p];}function d(b,i,g){a.ba();a.a(b,i,g,0,Math.PI*2,true);a.f();}k={x:0,y:0,l:0,m:0};function e(){k.x+=k.l;k.y+=k.m;a[f]="#000";d(k.x,k.y,4);}function n(b,j){var g=this;g.x=b;g.y=j;g.u=function(){ax=g.x;ay=g.y;if(k.x<ax+35&&k.x>ax-35&&k.y<ay+40&&k.y>ay-40){g.g=true;}if(!g.g){g.x+=6;}a[f]="#754C24";d(ax,ay,31);d(ax-16,ay+26,6);d(ax+16,ay+26,6);d(ax+24,ay-25,16);d(ax+16,ay-41,7);d(ax+34,ay-41,7);d(ax-26,ay-15,4);if(!g.g){a[f]="#fff";d(ax+20,ay-29,4);d(ax+32,ay-29,4);a[f]="#000";d(ax+21,ay-29,2);d(ax+34,ay-29,2);}a[f]="#603813";d(ax+32,ay-16,13);};}c.onclick=function(b){s=b.pageX||b.offsetX;t=b.pageY||b.offsetY;k.x=400;k.y=h;k.l=(s-400)/60;k.m=(t-h)/60;};q=[];function o(){q.push(new n(-100,(Math.random()*300)+100));setTimeout(function(){o();},Math.random()*5000);}o();setInterval(function(){a.ce(0,0,w,h);a[f]="#390";a.fc(0,100,w,h);q.forEach(function(b){b.u();});e();},17);
//very close, but not identical to the finished version
c.width = 800;
c.height = 500;
c.style.backgroundColor = '#69c';
fps = 60;
bullets = [];
fs = 'fillStyle';
// set up that dope method rewriter
for(prop in a)
a[ prop[ 0 ] + ( prop[ 6 ] || '' ) ] = a[prop];
function drawCircle(x,y,radius) {
a.ba();
// arc(x, y, radius, startAngle, endAngle, anticlockwise)
a.a(x, y, radius, 0, Math.PI*2, true);
a.f();
}
bullet = {
x:0,
y:0,
moveX:0,
moveY:0,
gone:false
};
function updateBullet() {
if (!bullet.gone) {
bullet.x += bullet.moveX;
bullet.y += bullet.moveY;
a[fs] = '#000';
drawCircle(bullet.x, bullet.y, 4);
};
}
function Animal( x, y ) {
var me = this;
me.x = x;
me.y = y;
me.updatePos = function() {
ax = me.x;
ay = me.y;
if (bullet.x < ax+35 &&
bullet.x > ax-35 &&
bullet.y < ay+40 &&
bullet.y > ay-40
) {
me.dead = true;
}
if (!me.dead) {
me.x += 4;
}
// if 2 parts always left first, then right
//body
a[fs] = '#963';
drawCircle(ax, ay, 31);
//feet
drawCircle(ax-16, ay+26, 6);
drawCircle(ax+16, ay+26, 6);
//head
drawCircle(ax+24, ay-25, 16);
//ears
drawCircle(ax+16, ay-41, 7);
drawCircle(ax+34, ay-41, 7);
//tail
drawCircle(ax-26, ay-15, 4);
//eyes
if (!me.dead) {
a[fs] = '#fff';
drawCircle(ax+20, ay-29, 4);
drawCircle(ax+32, ay-29, 4);
a[fs] = '#000';
drawCircle(ax+21, ay-29, 2);
drawCircle(ax+34, ay-29, 2);
}
//nose
a[fs] = '#630';
drawCircle(ax+32, ay-16, 13);
};
}
c.onclick = function(event) {
mouseX = event.pageX || event.offsetX;
mouseY = event.pageY || event.offsetY;
bullet.gone = false;
bullet.x = 400;
bullet.y = 500;
bullet.moveX = (mouseX - 400) / fps;
bullet.moveY = (mouseY - 500) / fps;
};
animals = [];
function newAnimal() {
animals.push(new Animal(-100, (Math.random() * 300)+100 ) );
setTimeout(function() {
newAnimal();
}, Math.random() * 5000 );
}
newAnimal();
//main animation loop
setInterval(function(){
//clear canvas
a.ce(0,0,800,500);
//bg grass
a[fs] = '#390';
a.fc(0,100,800,500);
animals.forEach(function(current){
current.updatePos();
});
updateBullet();
},1000/fps);