Kaynağa Gözat

* Removed the dependency on <math.h>. We don't need no stinking sqrt!

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@44 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 22 yıl önce
ebeveyn
işleme
a303f24f91
4 değiştirilmiş dosya ile 44 ekleme ve 5 silme
  1. +1
    -0
      src/Makefile.am
  2. +3
    -1
      src/common.h
  3. +37
    -0
      src/math.c
  4. +3
    -4
      src/weapons.c

+ 1
- 0
src/Makefile.am Dosyayı Görüntüle

@@ -24,6 +24,7 @@ ttyvaders_SOURCES = \
common.h \
explosions.c \
main.c \
math.c \
starfield.c \
weapons.c \
collide.c \


+ 3
- 1
src/common.h Dosyayı Görüntüle

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* 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 );


+ 37
- 0
src/math.c Dosyayı Görüntüle

@@ -0,0 +1,37 @@
/*
* ttyvaders Textmode shoot'em up
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* 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;
}


+ 3
- 4
src/weapons.c Dosyayı Görüntüle

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* 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 <stdlib.h>
#include <math.h>

#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:


Yükleniyor…
İptal
Kaydet