diff --git a/src/Makefile.am b/src/Makefile.am index 651b2aa..d056d0d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ ttyvaders_SOURCES = \ common.h \ explosions.c \ main.c \ + math.c \ starfield.c \ weapons.c \ collide.c \ diff --git a/src/common.h b/src/common.h index 5de390e..5b08181 100644 --- a/src/common.h +++ b/src/common.h @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: common.h,v 1.8 2002/12/22 22:17:41 sam Exp $ + * $Id: common.h,v 1.9 2002/12/22 22:36:42 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -185,3 +185,5 @@ void update_explosions( game *g, explosions *ex ); void ceo_alert( void ); +int r00t( int a ); + diff --git a/src/math.c b/src/math.c new file mode 100644 index 0000000..24bb71d --- /dev/null +++ b/src/math.c @@ -0,0 +1,37 @@ +/* + * ttyvaders Textmode shoot'em up + * Copyright (c) 2002 Sam Hocevar + * All Rights Reserved + * + * $Id: math.c,v 1.1 2002/12/22 22:36:42 sam Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "common.h" + +int r00t( int a ) +{ + int x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1; + + /* Newton's method. Three iterations are more than enough. */ + x = (x * x + a) / x / 2; + x = (x * x + a) / x / 2; + x = (x * x + a) / x / 2; + x = (x * x + a) / x / 2; + + return x; +} + diff --git a/src/weapons.c b/src/weapons.c index fbc8c2a..6d512fd 100644 --- a/src/weapons.c +++ b/src/weapons.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: weapons.c,v 1.8 2002/12/22 22:17:41 sam Exp $ + * $Id: weapons.c,v 1.9 2002/12/22 22:36:42 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ */ #include -#include #include "common.h" @@ -172,9 +171,9 @@ void update_weapons( game *g, weapons *wp ) /* Normalize and update speed */ wp->vx[i] = (7 * wp->vx[i] - + (dx * 48) / sqrt(dx*dx+dy*dy) ) / 8; + + (dx * 48) / r00t(dx*dx+dy*dy) ) / 8; wp->vy[i] = (7 * wp->vy[i] - + (dy * 24) / sqrt(dx*dx+dy*dy) ) / 8; + + (dy * 24) / r00t(dx*dx+dy*dy) ) / 8; break; case WEAPON_FRAGBOMB: