diff --git a/libee/Makefile.am b/libee/Makefile.am index b5c2098..ecb2aeb 100644 --- a/libee/Makefile.am +++ b/libee/Makefile.am @@ -19,6 +19,7 @@ libee_a_SOURCES = \ ee.c \ ee.h \ io.c \ + circle.c \ line.c \ math.c \ $(NULL) diff --git a/libee/circle.c b/libee/circle.c new file mode 100644 index 0000000..edfb83f --- /dev/null +++ b/libee/circle.c @@ -0,0 +1,49 @@ +/* + * libee ASCII-Art library + * Copyright (c) 2002, 2003 Sam Hocevar + * 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 + +#include "ee.h" + +void ee_draw_circle(int x, int y, int r, char c) +{ + int test, dx, dy; + + /* Optimized Bresenham. Kick ass. */ + for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) + { + ee_putcharTO(x + dx, y + dy / 2, c); + ee_putcharTO(x - dx, y + dy / 2, c); + ee_putcharTO(x + dx, y - dy / 2, c); + ee_putcharTO(x - dx, y - dy / 2, c); + + ee_putcharTO(x + dy, y + dx / 2, c); + ee_putcharTO(x - dy, y + dx / 2, c); + ee_putcharTO(x + dy, y - dx / 2, c); + ee_putcharTO(x - dy, y - dx / 2, c); + + test += test > 0 ? dx - dy-- : dx; + } +} + diff --git a/libee/ee.h b/libee/ee.h index 15800db..b573d21 100644 --- a/libee/ee.h +++ b/libee/ee.h @@ -73,6 +73,7 @@ void ee_end(void); char ee_get_key(void); +void ee_draw_circle(int, int, int, char); void ee_draw_line(int, int, int, int, char); int ee_rand(int, int); diff --git a/libee/line.c b/libee/line.c index 5fd9963..487d46e 100644 --- a/libee/line.c +++ b/libee/line.c @@ -28,7 +28,7 @@ #include "ee.h" static uint8_t clip_bits(int, int); -static void _ee_draw_line(int, int, int, int, char); +static void draw_solid_line(int, int, int, int, char); void ee_draw_line(int x1, int y1, int x2, int y2, char c) { @@ -43,7 +43,7 @@ void ee_draw_line(int x1, int y1, int x2, int y2, char c) if(bits1 == 0) { if(bits2 == 0) - _ee_draw_line(x1, y1, x2, y2, c); + draw_solid_line(x1, y1, x2, y2, c); else ee_draw_line(x2, y2, x1, y1, c); @@ -76,7 +76,7 @@ void ee_draw_line(int x1, int y1, int x2, int y2, char c) ee_draw_line(x1, y1, x2, y2, c); } -static void _ee_draw_line(int x1, int y1, int x2, int y2, char c) +static void draw_solid_line(int x1, int y1, int x2, int y2, char c) { int dx = abs(x2-x1); int dy = abs(y2-y1); diff --git a/src/weapons.c b/src/weapons.c index 36fbef1..84ad161 100644 --- a/src/weapons.c +++ b/src/weapons.c @@ -27,7 +27,6 @@ static void draw_bomb(int x, int y, int vx, int vy); static void draw_nuke(int x, int y, int frame); static void draw_beam(int x, int y, int frame); -static void draw_circle(int x, int y, int r, char c); static void draw_fragbomb(int x, int y, int frame); void init_weapons(game *g, weapons *wp) @@ -703,32 +702,11 @@ static void draw_nuke(int x, int y, int frame) /* Lots of duplicate pixels, but we don't care */ ee_color(EE_BLUE); - draw_circle(x, y, r++, ':'); + ee_draw_circle(x, y, r++, ':'); ee_color(EE_CYAN); - draw_circle(x, y, r++, '%'); + ee_draw_circle(x, y, r++, '%'); ee_color(EE_WHITE); - draw_circle(x, y, r++, '#'); - draw_circle(x, y, r++, '#'); -} - -static void draw_circle(int x, int y, int r, char c) -{ - int test, dx, dy; - - /* Optimized Bresenham. Kick ass. */ - for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) - { - ee_putcharTO(x + dx, y + dy / 2, c); - ee_putcharTO(x - dx, y + dy / 2, c); - ee_putcharTO(x + dx, y - dy / 2, c); - ee_putcharTO(x - dx, y - dy / 2, c); - - ee_putcharTO(x + dy, y + dx / 2, c); - ee_putcharTO(x - dy, y + dx / 2, c); - ee_putcharTO(x + dy, y - dx / 2, c); - ee_putcharTO(x - dy, y - dx / 2, c); - - test += test > 0 ? dx - dy-- : dx; - } + ee_draw_circle(x, y, r++, '#'); + ee_draw_circle(x, y, r++, '#'); }