Skip to content
Browse files

got the eyes and mouth to work, moved scores to top left... 1015bytes

  • Loading branch information...
1 parent 3e6adaa commit 530bc2e1499fc18e3209421a0a8788b0e2dea6df Brett Wejrowski committed Mar 3, 2012
Showing with 26 additions and 27 deletions.
  1. +23 −21 HHH.js
  2. +2 −2 HHH.min.js
  3. +1 −4 mini.html
View
44 HHH.js
@@ -1,5 +1,5 @@
// setup
-for (c.width = c.height = W = 510, a.font = "4em a", z = j = 15, N=99, f = 255, S = 0, T = 10, l = [], o = [], p = Math, q = 2 * p.PI, r = p.random, s = p.sqrt, t = p.abs, P=p.pow,
+for (c.width = c.height = W = 510, a.font = "3em a", z = j = 15, N=99, f = 255, F=40, E=50, S = 0, T = 10, l = [], o = [], p = Math, q = 2 * p.PI, r = p.random, s = p.sqrt, t = p.abs, P=p.pow,
// spacebar hits
onkeyup = onkeydown = function(d) {
@@ -9,14 +9,14 @@ onkeyup = onkeydown = function(d) {
// function to handle graphing
A = function(d, b, g, e , w) {
with (a)
- e && (fillStyle = "#"+"0ff0f009000fff".substr(e - 1, 3)),
- w ? fillText( d , b , g ) :
+ e+1 && (fillStyle = "#"+"0ff0f009000fff".substr(e , 3)),
+ w ? fillText( g , d , b ) :
(beginPath(), arc(d, b, g, q, 0, 0), fill());
return A
},
// draw our hippos
-Z = function(d, b, g, e, w) {
+C = function(d, b, g, e, w) {
// make sure we are within our bounds
z < (b+=d) ? b = z : 0 > b && (b = 0);
@@ -26,7 +26,10 @@ Z = function(d, b, g, e, w) {
// set the movement
for (u = 0, k = 8 * b - f,
- K = f + g * k , J = f + e * k ;
+ V = function( Z , M , U , G , D ){
+ A( f + g * ( k + M ) - ( g || Z ) , f + e * ( k + M ) - ( e || Z ) , U , G , D );
+ return V
+ };
// iterate through balls
n = l[u++]; )
@@ -39,39 +42,38 @@ Z = function(d, b, g, e, w) {
j || (
// get acceleration
- v = 40 < s( P(X-f,2) + P(Y-f,2) ) ? -.15 : .4,
+ v = F < s( P(x-f,2) + P(y-f,2) ) ? -.15 : .4,
// get velocity and position
x += X += v/2 * (x > f ? 1 : -1) - 1e-4,
y += Y += v/2 * (y > f ? 1 : -1),
// draw ball
- A(x, y, z, 12)
+ A(x, y, z, 11)
),
// check if we have eaten the ball!
- t(x - f - g * (k + 55)) < 25 && 50 > t(y - f - e * ( k + 55 ) ) &&
+ t(x - f - g * ( k + E ) ) < 25 && F > t(y - f - e * ( k + E ) ) &&
// bump
- (~d ? (X=g*3||X) && (X=e*3||Y) :
+ (~d ? (X=g*2||X) && (X=e*2||Y) :
// eat
S++ && (1 ^ n && w++, l[u - 1] = 1));
+
+ // draw the score
+ A( T+j*E , E , w , j , 1 );
// draw our hippo
- A( K + g * 60, J + e * 60, 50+b/3, j + 1)(K + g * z, J + e * z, 60)
-
-
- // draw the score
- ( w , f - g * 180 - ( g || -e * N ), f - e * 180 - ( e || g * N ) , 0 , 1 )
+ V( 0, E , F+b/3 ) ( 0 , z , E )
// draw the eyes
- ( K + g * 40 - ( g || z ), J + e * 40 - ( e || z ) , T+b/3 , 12 )
- ( K + g * 40 + ( g || z ), J + e * 40 + ( e || z ) , T+b/3 , 12 )
- ( K + g * 45 - ( g || T ), J + e * 45 - ( e || T ) , 7 , 9 )
- ( K + g * 44 + ( g || T ), J + e * 44 + ( e || T ) , 7 , 9 )
-
+ ( z , F , T+b/3 , 11 )
+ ( -z , F , T+b/3 )
+ ( z , 44 , 5 , 8 )
+ ( -z , 44 , 5 )
+
return arguments
}; --j + 1; )
@@ -86,11 +88,11 @@ Z = function(d, b, g, e, w) {
setInterval(function() {
// draw board
- A(f, f, W, 8)(f, f, f, 5);
+ A(f, f, W, 7)(f, f, f, 4);
// iterate through hippos and update
for (j = 0, I = 0|r()*N; i = o[j];j++)
- o[j] = Z.apply(c, i);
+ o[j] = C.apply(c, i);
// randomly make an AI hippo bite
o[++I] && S <= z && (o[I][0] = 1)
View
4 HHH.min.js
@@ -1,2 +1,2 @@
-for(c.width=c.height=W=510,a.font="3em m",z=j=20,f=255,n=k=v=u=i=I=S=0,T=10,l=[],o=[],p=Math,q=2*p.PI,r=p.random,s=p.sqrt,t=p.abs,P=p.pow,onkeyup=onkeydown=function(d){o[0][0]=d.type[5]?1:-1},A=function(d,b,g,e,M){with(a)e&&(fillStyle="#"+"0ff0f009000fff".substr(e-1,3)),M?fillText(d,b,g):(beginPath(),arc(d,b,g,q,0,0),fill());return A},Z=function(d,b,g,e,w){15<(b+=d)?b=15:0>b&&(b=0);k=8*b-f;b%15||(d=b&&j?-1:0);for(u=0,K=f+g*k,J=f+e*k;n=l[u++];)if(1^n){if(!j){v=40<s(P(n.x-f,2)+P(n.y-f,2))?-0.15:0.4;
-n.x+=n.a+=v/2*(n.x>f?1:-1)-1.0E-4;n.y+=n.b+=v/2*(n.y>f?1:-1);A(n.x,n.y,z,12)}t(n.x-f-g*(k+55))<25&&40>t(n.y-f-e*(k+55))&&(~d?(n.a=g*3||n.a)&&(n.b=e*3||n.b):S++&&(1^n&&w++,l[u-1]=1))}A(K+g*65,J+e*65,50,j+1)(K+g*z,J+e*z,60)(w,K+g*40-T,J+e*40-T,9,1);return arguments};--j+1;)l.push({x:99+300*r(),y:99+300*r(),a:0,b:0})&&4>j&&o.push([0,0,j&&2-j,3-j&&1-j,0]);setInterval(function(){A(f,f,2*W,8)(f,f,250,5);for(j=0,I=0|r()*99;i=o[j];j++)o[j]=Z.apply(c,i);o[++I]&&S^z+1&&(o[I][0]=1)},15);
+for(c.width=c.height=W=510,a.font="3em a",z=j=15,N=99,f=255,F=40,E=50,S=0,T=10,l=[],o=[],p=Math,q=2*p.PI,r=p.random,s=p.sqrt,t=p.abs,P=p.pow,onkeyup=onkeydown=function(d){o[0][0]=d.type[5]?1:-1},A=function(d,b,g,e,w){with(a)e+1&&(fillStyle="#"+"0ff0f009000fff".substr(e,3)),w?fillText(g,d,b):(beginPath(),arc(d,b,g,q,0,0),fill());return A},C=function(d,b,g,e,w){z<(b+=d)?b=z:0>b&&(b=0);b%z||(d=b&&j?-1:0);for(u=0,k=8*b-f,V=function(Z,M,U,G,D){A(f+g*(k+M)-(g||Z),f+e*(k+M)-(e||Z),U,G,D);return V};n=l[u++];)if(1^
+n)with(n)j||(v=F<s(P(x-f,2)+P(y-f,2))?-0.15:0.4,x+=X+=v/2*(x>f?1:-1)-1.0E-4,y+=Y+=v/2*(y>f?1:-1),A(x,y,z,11)),t(x-f-g*(k+E))<25&&F>t(y-f-e*(k+E))&&(~d?(X=g*2||X)&&(X=e*2||Y):S++&&(1^n&&w++,l[u-1]=1));A(T+j*E,E,w,j,1);V(0,E,F+b/3)(0,z,E)(z,F,T+b/3,11)(-z,F,T+b/3)(z,44,5,8)(-z,44,5);return arguments};--j+1;)l.push({x:N+f*r(),y:N+f*r(),X:0,Y:0})&&4>j&&o.push([0,0,j&&2-j,3-j&&1-j,0]);setInterval(function(){A(f,f,W,7)(f,f,f,4);for(j=0,I=0|r()*N;i=o[j];j++)o[j]=C.apply(c,i);o[++I]&&S<=z&&(o[I][0]=1)},z);
View
5 mini.html
@@ -12,9 +12,6 @@
var a = c.getContext('2d');
document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218
</script>
- <script>
- for(c.width=c.height=W=510,a.font="3em m",z=j=20,f=255,n=k=v=u=i=I=S=0,T=10,l=[],o=[],p=Math,q=2*p.PI,r=p.random,s=p.sqrt,t=p.abs,P=p.pow,onkeyup=onkeydown=function(d){o[0][0]=d.type[5]?1:-1},A=function(d,b,g,e,M){with(a)e&&(fillStyle="#"+"0ff0f009000fff".substr(e-1,3)),M?fillText(d,b,g):(beginPath(),arc(d,b,g,q,0,0),fill());return A},Z=function(d,b,g,e,w){15<(b+=d)?b=15:0>b&&(b=0);k=8*b-f;b%15||(d=b&&j?-1:0);for(u=0,K=f+g*k,J=f+e*k;n=l[u++];)if(1^n){if(!j){v=40<s(P(n.x-f,2)+P(n.y-f,2))?-0.15:0.4;
- n.x+=n.a+=v/2*(n.x>f?1:-1)-1.0E-4;n.y+=n.b+=v/2*(n.y>f?1:-1);A(n.x,n.y,z,12)}t(n.x-f-g*(k+55))<25&&40>t(n.y-f-e*(k+55))&&(~d?(n.a=g*3||n.a)&&(n.b=e*3||n.b):S++&&(1^n&&w++,l[u-1]=1))}A(K+g*65,J+e*65,50,j+1)(K+g*z,J+e*z,60)(w,K+g*40-T,J+e*40-T,9,1);return arguments};--j+1;)l.push({x:99+300*r(),y:99+300*r(),a:0,b:0})&&4>j&&o.push([0,0,j&&2-j,3-j&&1-j,0]);setInterval(function(){A(f,f,2*W,8)(f,f,250,5);for(j=0,I=0|r()*99;i=o[j];j++)o[j]=Z.apply(c,i);o[++I]&&S^z+1&&(o[I][0]=1)},15);
- </script>
+ <script src="HHH.min.js"></script>
</body>
</html>

0 comments on commit 530bc2e

Please sign in to comment.
Something went wrong with that request. Please try again.