From 8471fc8c00d560372c37955adf76a24b1954b535 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 10 Nov 2003 23:38:50 +0000 Subject: [PATCH] * libee/graphics.c: + Moved ee_putstr() and ee_putchar() in here. * libee/ee.h: + Got rid of ee_goto(). + Moved or into libee. * Replaced ee_goto()/ee_putstr() pairs with ee_putstr(). * Ditto for ee_putchar(). git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@148 92316355-f0b4-4df1-b90c-862c8a59935f --- libee/Makefile.am | 1 + libee/conic.c | 26 +++---- libee/ee.c | 30 ++------- libee/ee.h | 34 ++-------- libee/graphics.c | 93 +++++++++++++++++++++++++ libee/io.c | 6 ++ libee/line.c | 26 +++---- libee/math.c | 6 ++ libee/sprite.c | 10 ++- libee/triangle.c | 11 +-- src/box.c | 20 +++--- src/overlay.c | 25 +++---- src/player.c | 15 ++--- src/starfield.c | 3 +- src/tunnel.c | 46 ++----------- src/weapons.c | 168 ++++++++++++++++------------------------------ test/demo.c | 53 ++++++--------- 17 files changed, 264 insertions(+), 309 deletions(-) create mode 100644 libee/graphics.c diff --git a/libee/Makefile.am b/libee/Makefile.am index 47d979f..9dacf92 100644 --- a/libee/Makefile.am +++ b/libee/Makefile.am @@ -6,6 +6,7 @@ lib_LIBRARIES = libee.a libee_a_SOURCES = \ ee.c \ ee.h \ + graphics.c \ io.c \ math.c \ line.c \ diff --git a/libee/conic.c b/libee/conic.c index e2ab940..b178838 100644 --- a/libee/conic.c +++ b/libee/conic.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include #include @@ -99,27 +105,15 @@ static void ellipsepoints(int xo, int yo, int x, int y, char c) b |= 0x8; if((b & (0x1|0x4)) == (0x1|0x4)) - { - ee_goto(xo + x, yo + y); - ee_putchar(c); - } + ee_putchar(xo + x, yo + y, c); if((b & (0x2|0x4)) == (0x2|0x4)) - { - ee_goto(xo - x, yo + y); - ee_putchar(c); - } + ee_putchar(xo - x, yo + y, c); if((b & (0x1|0x8)) == (0x1|0x8)) - { - ee_goto(xo + x, yo - y); - ee_putchar(c); - } + ee_putchar(xo + x, yo - y, c); if((b & (0x2|0x8)) == (0x2|0x8)) - { - ee_goto(xo - x, yo - y); - ee_putchar(c); - } + ee_putchar(xo - x, yo - y, c); } diff --git a/libee/ee.c b/libee/ee.c index 8ec6db2..3d39c8e 100644 --- a/libee/ee.c +++ b/libee/ee.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include #include #include @@ -127,28 +133,6 @@ int ee_get_height(void) #endif } -void ee_clear(void) -{ -#if defined(USE_SLANG) || defined(USE_NCURSES) - /* We could use SLsmg_cls(), but drawing empty lines is much faster */ - int x = ee_get_width(), y = ee_get_height(); - char *empty_line = malloc((x + 1) * sizeof(char)); - - memset(empty_line, ' ', x); - empty_line[x] = '\0'; - - while(y--) - { - ee_goto(0, y); - ee_putstr(empty_line); - } - - free(empty_line); -#else - /* Use dummy driver */ -#endif -} - static int64_t local_time(void) { struct timeval tv; @@ -166,8 +150,6 @@ void ee_refresh(void) static int64_t local_clock = 0; int64_t now; - ee_goto(0, 0); - if(!local_clock) { /* Initialize local_clock */ diff --git a/libee/ee.h b/libee/ee.h index 6a75415..f08d528 100644 --- a/libee/ee.h +++ b/libee/ee.h @@ -21,33 +21,7 @@ */ /* - * Graphics primitives - */ -#ifdef USE_SLANG -# include -# define ee_color(x) SLsmg_set_color(x) -# define ee_goto(x,y) SLsmg_gotorc(y,x) -# define ee_putchar(x) SLsmg_write_char(x) -# define ee_putstr(x) SLsmg_write_string(x) -#elif USE_NCURSES -# define box box_divert -# include -# undef box -# define ee_color(x) attrset(COLOR_PAIR(x)) -# define ee_goto(x,y) move(y,x) -# define ee_putchar(x) addch(x) -# define ee_putstr(x) addstr(x) -#else -# define ee_color(x) (void)(x) -# define ee_goto(x,y) do{ (void)(x); (void)(y); } while(0) -# define ee_putchar(x) (void)(x) -# define ee_putstr(x) (void)(x) -#endif - -#define ee_putcharTO(x,y,c) do{ ee_goto(x,y); ee_putchar(c); }while(0) - -/* - * Colours + * Colors */ #define EE_BLACK 1 #define EE_GREEN 2 @@ -72,12 +46,16 @@ int ee_init(void); void ee_set_delay(int); int ee_get_width(void); int ee_get_height(void); -void ee_clear(void); void ee_refresh(void); void ee_end(void); char ee_get_key(void); +void ee_color(int); +void ee_putchar(int, int, char); +void ee_putstr(int, int, char *); +void ee_clear(void); + void ee_draw_line(int, int, int, int, char); void ee_draw_thin_line(int, int, int, int); void ee_draw_circle(int, int, int, char); diff --git a/libee/graphics.c b/libee/graphics.c new file mode 100644 index 0000000..58bedc5 --- /dev/null +++ b/libee/graphics.c @@ -0,0 +1,93 @@ +/* + * 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" + +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + +#include +#include + +#include "ee.h" + +void ee_color(int color) +{ +#ifdef USE_SLANG + SLsmg_set_color(color); +#elif USE_NCURSES + attrset(COLOR_PAIR(color)); +#else + /* Use dummy driver */ +#endif +} + +void ee_putchar(int x, int y, char c) +{ +#ifdef USE_SLANG + SLsmg_gotorc(y,x); + SLsmg_write_char(c); +#elif USE_NCURSES + move(y,x); + addch(c); +#else + /* Use dummy driver */ +#endif +} + +void ee_putstr(int x, int y, char *s) +{ +#ifdef USE_SLANG + SLsmg_gotorc(y,x); + SLsmg_write_string(s); +#elif USE_NCURSES + move(y,x); + addstr(s); +#else + /* Use dummy driver */ +#endif +} + +void ee_clear(void) +{ +#if defined(USE_SLANG) || defined(USE_NCURSES) + /* We could use SLsmg_cls(), but drawing empty lines is much faster */ + int x = ee_get_width(), y = ee_get_height(); + char *empty_line = malloc((x + 1) * sizeof(char)); + + memset(empty_line, ' ', x); + empty_line[x] = '\0'; + + while(y--) + { + ee_putstr(0, y, empty_line); + } + + free(empty_line); +#else + /* Use dummy driver */ +#endif +} + diff --git a/libee/io.c b/libee/io.c index a50a19f..43aaedb 100644 --- a/libee/io.c +++ b/libee/io.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include "ee.h" char ee_get_key(void) diff --git a/libee/line.c b/libee/line.c index c636068..49e4418 100644 --- a/libee/line.c +++ b/libee/line.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include #include @@ -196,8 +202,7 @@ static void draw_solid_line(struct line* s) for(; dx>=0; dx--) { - ee_goto(x1, y1); - ee_putchar(s->c); + ee_putchar(x1, y1, s->c); if(delta > 0) { x1 += xinc; @@ -219,8 +224,7 @@ static void draw_solid_line(struct line* s) for(; dy >= 0; dy--) { - ee_goto(x1, y1); - ee_putchar(s->c); + ee_putchar(x1, y1, s->c); if(delta > 0) { x1 += xinc; @@ -290,10 +294,9 @@ static void draw_thin_line(struct line* s) for(; dx>=0; dx--) { - ee_goto(x1, y1); if(delta > 0) { - ee_putchar(charmapy[1]); + ee_putchar(x1, y1, charmapy[1]); x1++; y1 += yinc; delta += dpru; @@ -302,9 +305,9 @@ static void draw_thin_line(struct line* s) else { if(prev) - ee_putchar(charmapy[0]); + ee_putchar(x1, y1, charmapy[0]); else - ee_putchar('-'); + ee_putchar(x1, y1, '-'); x1++; delta += dpr; prev = 0; @@ -319,18 +322,17 @@ static void draw_thin_line(struct line* s) for(; dy >= 0; dy--) { - ee_goto(x1, y1); if(delta > 0) { - ee_putchar(charmapx[0]); - ee_putchar(charmapx[1]); + ee_putchar(x1, y1, charmapx[0]); + ee_putchar(x1 + 1, y1, charmapx[1]); x1++; y1 += yinc; delta += dpru; } else { - ee_putchar('|'); + ee_putchar(x1, y1, '|'); y1 += yinc; delta += dpr; } diff --git a/libee/math.c b/libee/math.c index 489c563..5bd108c 100644 --- a/libee/math.c +++ b/libee/math.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include #include "ee.h" diff --git a/libee/sprite.c b/libee/sprite.c index 0befb36..c613120 100644 --- a/libee/sprite.c +++ b/libee/sprite.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include #include #include @@ -166,9 +172,9 @@ void ee_draw_sprite(int x, int y, struct ee_sprite *sprite) int col = frame->color[frame->w * j + i]; if(col >= 0) { - ee_goto(x + i - frame->dx, y + j - frame->dy); ee_color(col); - ee_putchar(frame->chars[frame->w * j + i]); + ee_putchar(x + i - frame->dx, y + j - frame->dy, + frame->chars[frame->w * j + i]); } } } diff --git a/libee/triangle.c b/libee/triangle.c index 2a63d4a..6c50ab4 100644 --- a/libee/triangle.c +++ b/libee/triangle.c @@ -22,6 +22,12 @@ #include "config.h" +#ifdef USE_SLANG +# include +#elif USE_NCURSES +# include +#endif + #include #include "ee.h" @@ -81,10 +87,7 @@ void ee_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c) if(xb > xmax) xb = xmax; for(x = xa; x <= xb; x++) - { - ee_goto(x, y); - ee_putchar(c); - } + ee_putchar(x, y, c); } } diff --git a/src/box.c b/src/box.c index 4bf10e2..c6be773 100644 --- a/src/box.c +++ b/src/box.c @@ -85,16 +85,16 @@ void draw_box(game *g, box *b) ee_color(EE_YELLOW); /* FIXME: use a font */ - ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2); - ee_putstr("XXXX. .XXXX X X .XXXX .XXXX XXXX."); - ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3); - ee_putstr("X `X X' X X X X' X' X `X"); - ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4); - ee_putstr("XXXX' XXXXX X X `XXX XXXX X X"); - ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5); - ee_putstr("X' X' `X X. ,X `X X' X ,X"); - ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6); - ee_putstr("X X X `XXXX XXXX' `XXXX XXXX'"); + ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2, + "XXXX. .XXXX X X .XXXX .XXXX XXXX."); + ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3, + "X `X X' X X X X' X' X `X"); + ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4, + "XXXX' XXXXX X X `XXX XXXX X X"); + ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5, + "X' X' `X X. ,X `X X' X ,X"); + ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6, + "X X X `XXXX XXXX' `XXXX XXXX'"); } void free_box(box *b) diff --git a/src/overlay.c b/src/overlay.c index cc0cba2..8deefbf 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -33,8 +33,7 @@ void draw_status(game *g) /* Draw life jauge */ ee_color(EE_GRAY); - ee_goto(4, 1); - ee_putstr(dots30); + ee_putstr(4, 1, dots30); if(g->p->life > MAX_LIFE * 7 / 10) { @@ -49,19 +48,15 @@ void draw_status(game *g) ee_color(EE_RED); } - ee_goto(4, 1); - ee_putstr(dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE); + ee_putstr(4, 1, dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE); ee_color(EE_WHITE); - ee_goto(1, 1); - ee_putstr("L |"); - ee_goto(34, 1); - ee_putstr("|"); + ee_putstr(1, 1, "L |"); + ee_putstr(34, 1, "|"); /* Draw weapon jauge */ ee_color(EE_GRAY); - ee_goto(42, 1); - ee_putstr(dots30 + 10); + ee_putstr(42, 1, dots30 + 10); if(g->p->special > MAX_SPECIAL * 9 / 10) { @@ -76,13 +71,11 @@ void draw_status(game *g) ee_color(EE_BLUE); } - ee_goto(42, 1); - ee_putstr(dashes30 + 10 + (MAX_SPECIAL - g->p->special) * 20 / MAX_SPECIAL); + ee_putstr(42, 1, dashes30 + 10 + + (MAX_SPECIAL - g->p->special) * 20 / MAX_SPECIAL); ee_color(EE_WHITE); - ee_goto(39, 1); - ee_putstr("S |"); - ee_goto(62, 1); - ee_putstr("|"); + ee_putstr(39, 1, "S |"); + ee_putstr(62, 1, "|"); } diff --git a/src/player.c b/src/player.c index 7159ea9..00a7d4f 100644 --- a/src/player.c +++ b/src/player.c @@ -55,18 +55,13 @@ void draw_player(game *g, player *p) return; } - ee_goto(p->x + 2, p->y - 2); ee_color(EE_GREEN); - ee_putstr("/\\"); - ee_goto(p->x + 1, p->y - 1); - ee_putchar('('); + ee_putstr(p->x + 2, p->y - 2, "/\\"); + ee_putchar(p->x + 1, p->y - 1, '('); + ee_putchar(p->x + 4, p->y - 1, ')'); + ee_putstr(p->x, p->y, "I<__>I"); ee_color(EE_YELLOW); - ee_putstr("()"); - ee_color(EE_GREEN); - ee_putchar(')'); - ee_goto(p->x, p->y); - ee_color(EE_GREEN); - ee_putstr("I<__>I"); + ee_putstr(p->x + 2, p->y - 1, "()"); } void update_player(game *g, player *p) diff --git a/src/starfield.c b/src/starfield.c index 6884990..b4a3348 100644 --- a/src/starfield.c +++ b/src/starfield.c @@ -54,8 +54,7 @@ void draw_starfield(game *g, starfield *s) if(s[i].x >= 0) { ee_color(s[i].c); - ee_goto(s[i].x, s[i].y); - ee_putchar(s[i].ch); + ee_putchar(s[i].x, s[i].y, s[i].ch); } } } diff --git a/src/tunnel.c b/src/tunnel.c index 0adfb79..9cd17a1 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -77,83 +77,49 @@ void draw_tunnel(game *g, tunnel *t) for(i = 0; i < g->h ; i++) { if(t->left[i] <= -10) - { continue; - } if(i + 1 == g->h || t->left[i] > t->left[i+1]) - { c = (i == 0 || t->left[i] > t->left[i-1]) ? '>' : '/'; - } else - { c = (i == 0 || t->left[i] > t->left[i-1]) ? '\\' : '<'; - } - ee_goto(t->left[i] + 1, i); - ee_putchar(c); + ee_putchar(t->left[i] + 1, i, c); if(i + 1 < g->h) - { for(j = 1; j < t->left[i+1] - t->left[i]; j++) - { - ee_goto(t->left[i] + j + 1, i); - ee_putchar('_'); - } - } + ee_putchar(t->left[i] + j + 1, i, '_'); } /* Right border */ for(i = 0; i < g->h ; i++) { if(t->right[i] >= g->w + 10) - { continue; - } if(i + 1 == g->h || t->right[i] > t->right[i+1]) - { c = (i == 0 || t->right[i] > t->right[i-1]) ? '>' : '/'; - } else - { c = (i == 0 || t->right[i] > t->right[i-1]) ? '\\' : '<'; - } if(i + 1 < g->h) - { for(j = 1; j < t->right[i] - t->right[i+1]; j++) - { - ee_goto(t->right[i+1] + j - 1, i); - ee_putchar('_'); - } - } + ee_putchar(t->right[i+1] + j - 1, i, '_'); - ee_goto(t->right[i] - 1, i); - ee_putchar(c); + ee_putchar(t->right[i] - 1, i, c); } ee_color(EE_RED); /* Left concrete */ for(i = 0; i < g->h ; i++) - { for(j = 0 ; j <= t->left[i]; j++) - { - ee_goto(j, i); - ee_putchar('#'); - } - } + ee_putchar(j, i, '#'); /* Right concrete */ for(i = 0; i < g->h ; i++) - { for(j = t->right[i] ; j < g->w ; j++) - { - ee_goto(j, i); - ee_putchar('#'); - } - } + ee_putchar(j, i, '#'); } void update_tunnel(game *g, tunnel *t) diff --git a/src/weapons.c b/src/weapons.c index 7d08756..6c1226c 100644 --- a/src/weapons.c +++ b/src/weapons.c @@ -57,34 +57,24 @@ void draw_weapons(game *g, weapons *wp) { case WEAPON_LASER: ee_color(EE_WHITE); - ee_goto(wp->x[i] >> 4, wp->y[i] >> 4); - ee_putchar('|'); + ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '|'); ee_color(EE_CYAN); - ee_goto(wp->x[i] >> 4, (wp->y[i] >> 4) + 1); - ee_putchar('|'); + ee_putchar(wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|'); break; case WEAPON_SEEKER: ee_color(EE_CYAN); - ee_goto(wp->x3[i] >> 4, wp->y3[i] >> 4); - ee_putchar('.'); - ee_goto(wp->x2[i] >> 4, wp->y2[i] >> 4); - ee_putchar('o'); + ee_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.'); + ee_putchar(wp->x2[i] >> 4, wp->y2[i] >> 4, 'o'); ee_color(EE_WHITE); - ee_goto(wp->x[i] >> 4, wp->y[i] >> 4); - ee_putchar('@'); + ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '@'); break; case WEAPON_BOMB: ee_color(EE_GRAY); - ee_goto((wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4); - ee_putchar('.'); - ee_goto((wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4); - ee_putchar('.'); - ee_goto((wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4); - ee_putchar('.'); - ee_goto(wp->x3[i] >> 4, wp->y3[i] >> 4); - ee_putchar('.'); - ee_goto(wp->x2[i] >> 4, wp->y2[i] >> 4); - ee_putchar('.'); + ee_putchar((wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.'); + ee_putchar((wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.'); + ee_putchar((wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4, '.'); + ee_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.'); + ee_putchar(wp->x2[i] >> 4, wp->y2[i] >> 4, '.'); draw_bomb(wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i]); break; case WEAPON_FRAGBOMB: @@ -367,131 +357,85 @@ static void draw_beam(int x, int y, int frame) { case 24: ee_color(EE_WHITE); - ee_goto(x, y-3); - ee_putstr("__"); - ee_goto(x-1, y-2); - ee_putchar('\''); - ee_goto(x+2, y-2); - ee_putchar('`'); + ee_putstr(x, y-3, "__"); + ee_putchar(x-1, y-2, '\''); + ee_putchar(x+2, y-2, '`'); break; case 23: ee_color(EE_CYAN); - ee_goto(x, y-3); - ee_putstr("__"); + ee_putstr(x, y-3, "__"); ee_color(EE_WHITE); - ee_goto(x-2, y-2); - ee_putstr("-'"); - ee_goto(x+2, y-2); - ee_putstr("`-"); + ee_putstr(x-2, y-2, "-'"); + ee_putstr(x+2, y-2, "`-"); break; case 22: ee_color(EE_CYAN); - ee_goto(x, y-3); - ee_putstr("__"); - ee_goto(x-1, y-2); - ee_putchar('\''); - ee_goto(x+2, y-2); - ee_putchar('`'); + ee_putstr(x, y-3, "__"); + ee_putchar(x-1, y-2, '\''); + ee_putchar(x+2, y-2, '`'); ee_color(EE_WHITE); - ee_goto(x-3, y-2); - ee_putstr(",-"); - ee_goto(x+3, y-2); - ee_putstr("-."); + ee_putstr(x-3, y-2, ",-"); + ee_putstr(x+3, y-2, "-."); break; case 21: ee_color(EE_CYAN); - ee_goto(x-1, y-3); - ee_putstr("____"); - ee_goto(x-2, y-2); - ee_putchar('\''); - ee_goto(x+3, y-2); - ee_putchar('`'); + ee_putstr(x-1, y-3, "____"); + ee_putchar(x-2, y-2, '\''); + ee_putchar(x+3, y-2, '`'); ee_color(EE_WHITE); - ee_goto(x-4, y-2); - ee_putstr(",-"); - ee_goto(x+4, y-2); - ee_putstr("-."); + ee_putstr(x-4, y-2, ",-"); + ee_putstr(x+4, y-2, "-."); break; case 20: ee_color(EE_WHITE); - ee_goto(x, y-3); - ee_putstr("%%"); - ee_goto(x-4, y-2); - ee_putchar(','); - ee_goto(x+5, y-2); - ee_putchar('.'); + ee_putstr(x, y-3, "%%"); + ee_putchar(x-4, y-2, ','); + ee_putchar(x+5, y-2, '.'); ee_color(EE_CYAN); - ee_goto(x-1, y-3); - ee_putchar(':'); - ee_goto(x+2, y-3); - ee_putchar(':'); - ee_goto(x-3, y-2); - ee_putstr("-'"); - ee_goto(x+3, y-2); - ee_putstr("`-"); + ee_putchar(x-1, y-3, ':'); + ee_putchar(x+2, y-3, ':'); + ee_putstr(x-3, y-2, "-'"); + ee_putstr(x+3, y-2, "`-"); break; case 19: ee_color(EE_WHITE); - ee_goto(x, y-4); - ee_putstr("%%"); - ee_goto(x, y-3); - ee_putstr("##"); + ee_putstr(x, y-4, "%%"); + ee_putstr(x, y-3, "##"); ee_color(EE_CYAN); - ee_goto(x-1, y-4); - ee_putchar(':'); - ee_goto(x+2, y-4); - ee_putchar(':'); - ee_goto(x-1, y-3); - ee_putchar('%'); - ee_goto(x+2, y-3); - ee_putchar('%'); - ee_goto(x-4, y-2); - ee_putstr(",-'"); - ee_goto(x+3, y-2); - ee_putstr("`-."); + ee_putchar(x-1, y-4, ':'); + ee_putchar(x+2, y-4, ':'); + ee_putchar(x-1, y-3, '%'); + ee_putchar(x+2, y-3, '%'); + ee_putstr(x-4, y-2, ",-'"); + ee_putstr(x+3, y-2, "`-."); ee_color(EE_BLUE); - ee_goto(x-2, y-3); - ee_putchar(':'); - ee_goto(x+3, y-3); - ee_putchar(':'); + ee_putchar(x-2, y-3, ':'); + ee_putchar(x+3, y-3, ':'); break; case 18: default: r = (18 - frame) * (18 - frame); ee_color(EE_WHITE); - ee_goto(x-1, y-5-r); - ee_putstr(":%%:"); - ee_goto(x-1, y-4-r); - ee_putstr("%##%"); + ee_putstr(x-1, y-5-r, ":%%:"); + ee_putstr(x-1, y-4-r, "%##%"); ee_color(EE_CYAN); - ee_goto(x-2, y-4-r); - ee_putchar(':'); - ee_goto(x+3, y-4-r); - ee_putchar(':'); - ee_goto(x-2, y-2); - ee_putchar('\''); - ee_goto(x+3, y-2); - ee_putchar('`'); + ee_putchar(x-2, y-4-r, ':'); + ee_putchar(x+3, y-4-r, ':'); + ee_putchar(x-2, y-2, '\''); + ee_putchar(x+3, y-2, '`'); ee_color(EE_BLUE); - ee_goto(x-3, y-2); - ee_putchar(':'); - ee_goto(x+4, y-2); - ee_putchar(':'); + ee_putchar(x-3, y-2, ':'); + ee_putchar(x+4, y-2, ':'); for(i = 0; i <= r; i++) { ee_color(EE_WHITE); - ee_goto(x-1, y-3-i); - ee_putstr((i+frame) % 5 ? "####" : "%%%%"); + ee_putstr(x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%"); ee_color(EE_CYAN); - ee_goto(x-2, y-3-i); - ee_putchar('%'); - ee_goto(x+3, y-3-i); - ee_putchar('%'); + ee_putchar(x-2, y-3-i, '%'); + ee_putchar(x+3, y-3-i, '%'); ee_color(EE_BLUE); - ee_goto(x-3, y-3-i); - ee_putchar(':'); - ee_goto(x+4, y-3-i); - ee_putchar(':'); + ee_putchar(x-3, y-3-i, ':'); + ee_putchar(x+4, y-3-i, ':'); } break; } diff --git a/test/demo.c b/test/demo.c index f3ab63a..d9ff3b2 100644 --- a/test/demo.c +++ b/test/demo.c @@ -138,32 +138,20 @@ static void display_menu(void) ee_draw_line(xo, 1, xo, yo, ':'); ee_draw_line(1, 1, xo, 1, '.'); - ee_goto((xo - strlen("libee demo")) / 2, 3); - ee_putstr("libee demo"); - ee_goto((xo - strlen("============")) / 2, 4); - ee_putstr("============"); - - ee_goto(4, 6); - ee_putstr("0: complete demo"); - ee_goto(4, 7); - ee_putstr("1: dots demo"); - ee_goto(4, 8); - ee_putstr("2: lines demo"); - ee_goto(4, 9); - ee_putstr("3: thin lines demo"); - ee_goto(4, 10); - ee_putstr("4: circles demo"); - ee_goto(4, 11); - ee_putstr("5: ellipses demo"); - ee_goto(4, 12); - ee_putstr("6: triangles demo"); - ee_goto(4, 13); - ee_putstr("7: outlined triangles demo"); - ee_goto(4, 14); - ee_putstr("8: sprites demo"); - - ee_goto(4, yo - 2); - ee_putstr("q: quit"); + ee_putstr((xo - strlen("libee demo")) / 2, 3, "libee demo"); + ee_putstr((xo - strlen("============")) / 2, 4, "============"); + + ee_putstr(4, 6, "0: complete demo"); + ee_putstr(4, 7, "1: dots demo"); + ee_putstr(4, 8, "2: lines demo"); + ee_putstr(4, 9, "3: thin lines demo"); + ee_putstr(4, 10, "4: circles demo"); + ee_putstr(4, 11, "5: ellipses demo"); + ee_putstr(4, 12, "6: triangles demo"); + ee_putstr(4, 13, "7: outlined triangles demo"); + ee_putstr(4, 14, "8: sprites demo"); + + ee_putstr(4, yo - 2, "q: quit"); ee_refresh(); } @@ -265,11 +253,11 @@ static void demo_all(void) { int delta = ee_rand(-5, 5); ee_color(ee_rand(1, 10)); - ee_goto(ee_get_width() / 2 - + cos(0.02*j) * (delta + ee_get_width() / 4), - ee_get_height() / 2 - + sin(0.02*j) * (delta + ee_get_height() / 3)); - ee_putchar('#'); + ee_putchar(ee_get_width() / 2 + + cos(0.02*j) * (delta + ee_get_width() / 4), + ee_get_height() / 2 + + sin(0.02*j) * (delta + ee_get_height() / 3), + '#'); } /* Draw foreground sprite */ @@ -290,8 +278,7 @@ static void demo_dots(void) { /* Putpixel */ ee_color(ee_rand(1, 10)); - ee_goto(ee_rand(0, xmax), ee_rand(0, ymax)); - ee_putchar('#'); + ee_putchar(ee_rand(0, xmax), ee_rand(0, ymax), '#'); } ee_refresh(); }