瀏覽代碼

* libee/io.c:

+ Moved ee_get_key() here.
  * libee/math.c:
    + Moved r00t() here and renamed it to ee_sqrt().
    + Moved GET_RAND() here and renamed it to ee_rand().
  * src/math.c:
    + Removed this deprecated file.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@90 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 年之前
父節點
當前提交
7ac3775341
共有 14 個文件被更改,包括 87 次插入54 次删除
  1. +1
    -1
      libee/Makefile.am
  2. +0
    -22
      libee/ee.c
  3. +3
    -0
      libee/ee.h
  4. +48
    -0
      libee/io.c
  5. +16
    -5
      libee/math.c
  6. +0
    -1
      src/Makefile.am
  7. +1
    -1
      src/aliens.c
  8. +2
    -2
      src/collide.c
  9. +0
    -6
      src/common.h
  10. +1
    -1
      src/explosions.c
  11. +2
    -2
      src/main.c
  12. +9
    -9
      src/starfield.c
  13. +2
    -2
      src/tunnel.c
  14. +2
    -2
      src/weapons.c

+ 1
- 1
libee/Makefile.am 查看文件

@@ -15,6 +15,6 @@ CPPFLAGS_ncurses = -DUSE_NCURSES
endif

lib_LIBRARIES = libee.a
libee_a_SOURCES = ee.c ee.h
libee_a_SOURCES = ee.c ee.h io.c math.c
libee_a_CPPFLAGS = $(CPPFLAGS_slang) $(CPPFLAGS_ncurses)


+ 0
- 22
libee/ee.c 查看文件

@@ -204,25 +204,3 @@ void ee_end(void)
#endif
}

char ee_get_key(void)
{
#ifdef USE_SLANG
if(SLang_input_pending(0))
{
return SLang_getkey();
}
#elif USE_NCURSES
char key = getch();

if(key != ERR)
{
return key;
}
#else
return 0;

#endif

return 0;
}


+ 3
- 0
libee/ee.h 查看文件

@@ -72,3 +72,6 @@ void ee_end(void);

char ee_get_key(void);

int ee_rand(int, int);
int ee_sqrt(int);


+ 48
- 0
libee/io.c 查看文件

@@ -0,0 +1,48 @@
/*
* libee ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* 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 "config.h"

#include "ee.h"

char ee_get_key(void)
{
#ifdef USE_SLANG
if(SLang_input_pending(0))
{
return SLang_getkey();
}
#elif USE_NCURSES
char key = getch();

if(key != ERR)
{
return key;
}
#else
return 0;

#endif

return 0;
}


src/math.c → libee/math.c 查看文件

@@ -1,6 +1,6 @@
/*
* ttyvaders Textmode shoot'em up
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* libee ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
@@ -20,17 +20,28 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "common.h"
#include "config.h"

int r00t(int a)
#include <stdlib.h>

#include "ee.h"

int ee_rand(int min, int max)
{
return min + (int)((1.0*(max-min)) * rand() / (RAND_MAX+1.0));
}

int ee_sqrt(int a)
{
int x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1;
int x;

if(a <= 0)
{
return 0;
}

x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1;

/* Newton's method. Three iterations would be more than enough. */
x = (x * x + a) / x / 2;
x = (x * x + a) / x / 2;

+ 0
- 1
src/Makefile.am 查看文件

@@ -27,7 +27,6 @@ ttyvaders_SOURCES = \
common.h \
explosions.c \
main.c \
math.c \
overlay.c \
player.c \
starfield.c \


+ 1
- 1
src/aliens.c 查看文件

@@ -72,7 +72,7 @@ void update_aliens(game *g, aliens *al)
{
add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM);
al->type[i] = ALIEN_NONE;
add_bonus(g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE);
add_bonus(g, g->bo, al->x[i], al->y[i], ee_rand(0,5) ? BONUS_GREEN : BONUS_LIFE);
}

/* Update coordinates */


+ 2
- 2
src/collide.c 查看文件

@@ -125,12 +125,12 @@ void collide_weapons_tunnel(game *g, weapons *wp, tunnel *t, explosions *ex)
if(x - 2 <= t->left[y-j])
{
add_explosion(g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL);
t->left[y-j] -= GET_RAND(0,3);
t->left[y-j] -= ee_rand(0,3);
}
else if(x + 3 >= t->right[y-j])
{
add_explosion(g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL);
t->right[y-j] += GET_RAND(0,3);
t->right[y-j] += ee_rand(0,3);
}
}
break;


+ 0
- 6
src/common.h 查看文件

@@ -47,7 +47,6 @@
/*
* Useful macros
*/
#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
#define GET_MAX(a,b) ((a)>(b)?(a):(b))
#define GET_MIN(a,b) ((a)<(b)?(a):(b))

@@ -186,11 +185,6 @@ void add_explosion(game *, explosions *, int, int, int, int, int);
void draw_explosions(game *, explosions *);
void update_explosions(game *, explosions *);

/*
* From math.c
*/
int r00t(int);

/*
* From overlay.c
*/


+ 1
- 1
src/explosions.c 查看文件

@@ -73,7 +73,7 @@ void draw_explosions(game *g, explosions *ex)
#if 0
ee_color(GREEN);
ee_goto(ex->x[i] + 3, ex->y[i]);
switch(GET_RAND(0,3))
switch(ee_rand(0,3))
{
case 0:
ee_putchar('p');


+ 2
- 2
src/main.c 查看文件

@@ -182,11 +182,11 @@ static void start_game (game *g)
skip = 0;

/* XXX: to be removed */
if(GET_RAND(0,10) == 0)
if(ee_rand(0,10) == 0)
{
int list[3] = { ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ };

add_alien(g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)]);
add_alien(g, g->al, 0, rand() % g->h / 2, list[ee_rand(0,3)]);
}

/* Update game rules */


+ 9
- 9
src/starfield.c 查看文件

@@ -33,11 +33,11 @@ starfield * create_starfield(game *g)

for(i = 0; i < STARS; i++)
{
s[i].x = GET_RAND(0, g->w);
s[i].y = GET_RAND(0, g->h);
s[i].z = GET_RAND(1, 4);
s[i].c = GET_RAND(6, 8);
s[i].ch = GET_RAND(0, 2) ? '.' : '\'';
s[i].x = ee_rand(0, g->w);
s[i].y = ee_rand(0, g->h);
s[i].z = ee_rand(1, 4);
s[i].c = ee_rand(6, 8);
s[i].ch = ee_rand(0, 2) ? '.' : '\'';
}

return s;
@@ -66,11 +66,11 @@ void update_starfield(game *g, starfield *s)
{
if(s[i].x < 0)
{
s[i].x = GET_RAND(0, g->w);
s[i].x = ee_rand(0, g->w);
s[i].y = 0;
s[i].z = GET_RAND(1, 3);
s[i].c = GET_RAND(6, 8);
s[i].ch = GET_RAND(0, 2) ? '.' : '\'';
s[i].z = ee_rand(1, 3);
s[i].c = ee_rand(6, 8);
s[i].ch = ee_rand(0, 2) ? '.' : '\'';
}
else if(s[i].y < g->h-1)
{


+ 2
- 2
src/tunnel.c 查看文件

@@ -169,8 +169,8 @@ void update_tunnel(game *g, tunnel *t)
}

/* Generate new values */
i = delta[GET_RAND(0,6)];
j = delta[GET_RAND(0,6)];
i = delta[ee_rand(0,6)];
j = delta[ee_rand(0,6)];

/* Check in which direction we need to alter tunnel */
if(t->right[1] - t->left[1] < t->w)


+ 2
- 2
src/weapons.c 查看文件

@@ -172,7 +172,7 @@ void update_weapons(game *g, weapons *wp)
/* Normalize direction */
if(dx | dy)
{
int norm = r00t(dx * dx + 4 * dy * dy);
int norm = ee_sqrt(dx * dx + 4 * dy * dy);
dx = dx * 32 / norm;
dy = dy * 32 / norm;
}
@@ -184,7 +184,7 @@ void update_weapons(game *g, weapons *wp)
/* Normalize speed */
if(dx | dy)
{
int norm = r00t(dx * dx + 4 * dy * dy);
int norm = ee_sqrt(dx * dx + 4 * dy * dy);
wp->vx[i] = dx * 32 / norm;
wp->vy[i] = dy * 32 / norm;
}


Loading…
取消
儲存