Pārlūkot izejas kodu

* Renamed libee to libcaca. Far less collisions.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@186 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam pirms 21 gadiem
vecāks
revīzija
45d3deb083
35 mainītis faili ar 739 papildinājumiem un 739 dzēšanām
  1. +1
    -1
      Makefile.am
  2. +1
    -1
      TODO
  3. +1
    -1
      configure.ac
  4. +6
    -6
      libcaca/Makefile.am
  5. +10
    -10
      libcaca/blit.c
  6. +23
    -23
      libcaca/box.c
  7. +40
    -40
      libcaca/caca.c
  8. +116
    -0
      libcaca/caca.h
  9. +5
    -5
      libcaca/caca_internals.h
  10. +21
    -21
      libcaca/conic.c
  11. +31
    -31
      libcaca/graphics.c
  12. +4
    -4
      libcaca/io.c
  13. +19
    -19
      libcaca/line.c
  14. +6
    -6
      libcaca/math.c
  15. +25
    -25
      libcaca/sprite.c
  16. +17
    -17
      libcaca/triangle.c
  17. +0
    -116
      libee/ee.h
  18. +2
    -2
      src/Makefile.am
  19. +10
    -10
      src/aliens.c
  20. +6
    -6
      src/bonus.c
  21. +14
    -14
      src/box.c
  22. +3
    -3
      src/ceo.c
  23. +2
    -2
      src/collide.c
  24. +1
    -1
      src/common.h
  25. +20
    -20
      src/explosions.c
  26. +19
    -19
      src/intro.c
  27. +10
    -10
      src/main.c
  28. +18
    -18
      src/overlay.c
  29. +3
    -3
      src/player.c
  30. +11
    -11
      src/starfield.c
  31. +10
    -10
      src/tunnel.c
  32. +99
    -99
      src/weapons.c
  33. +4
    -4
      test/Makefile.am
  34. +151
    -151
      test/demo.c
  35. +30
    -30
      test/spritedit.c

+ 1
- 1
Makefile.am Parādīt failu

@@ -2,7 +2,7 @@
# Automake targets and declarations for ttyvaders
###############################################################################

SUBDIRS = libee test src
SUBDIRS = libcaca test src
DIST_SUBDIRS = $(SUBDIRS) autotools data debian

EXTRA_DIST = BUGS doc/shapes.txt bootstrap


+ 1
- 1
TODO Parādīt failu

@@ -1,6 +1,6 @@
$Id$

TODO for libee
TODO for libcaca

o Sprite library



+ 1
- 1
configure.ac Parādīt failu

@@ -60,7 +60,7 @@ CFLAGS="${CFLAGS} -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-protot

AC_OUTPUT([
Makefile
libee/Makefile
libcaca/Makefile
test/Makefile
src/Makefile
autotools/Makefile


libee/Makefile.am → libcaca/Makefile.am Parādīt failu

@@ -1,12 +1,12 @@
###############################################################################
# Automake targets and declarations for libee
# Automake targets and declarations for libcaca
###############################################################################

lib_LIBRARIES = libee.a
libee_a_SOURCES = \
ee.c \
ee.h \
ee_internals.h \
lib_LIBRARIES = libcaca.a
libcaca_a_SOURCES = \
caca.c \
caca.h \
caca_internals.h \
graphics.c \
io.c \
math.c \

libee/blit.c → libcaca/blit.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -30,11 +30,11 @@ typedef unsigned char uint8_t;

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

#include <stdio.h>
void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
{
char foo[] = { ' ', '.', ':', ';', '=', '$', '%', '@', '#', '8', 'W' };
int x, y, pitch;
@@ -51,8 +51,8 @@ void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)

pitch = (3 * w + 3) / 4 * 4;

for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= ee_get_height(); y++)
for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= ee_get_width(); x++)
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= caca_get_height(); y++)
for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= caca_get_width(); x++)
{
int fromx = w * (x - x1) / (x2 - x1 + 1);
int fromy = h * (y - y1) / (y2 - y1 + 1);
@@ -62,7 +62,7 @@ void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)

if(r == g && g == b)
{
ee_set_color(EE_LIGHTGRAY);
caca_set_color(EE_LIGHTGRAY);
}
else
{
@@ -88,15 +88,15 @@ void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
if( hue < 0 )
hue += 360;

ee_set_color(foo_colors[(int)(hue + 30) / 60]);
caca_set_color(foo_colors[(int)(hue + 30) / 60]);
}
else
{
ee_set_color(EE_LIGHTGRAY);
caca_set_color(EE_LIGHTGRAY);
}
}

ee_putchar(x, y, foo[(r + g + b) / 3 / 25]);
caca_putchar(x, y, foo[(r + g + b) / 3 / 25]);
}
}


libee/box.c → libcaca/box.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -24,18 +24,18 @@

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

void ee_draw_box(int x1, int y1, int x2, int y2, char c)
void caca_draw_box(int x1, int y1, int x2, int y2, char c)
{
ee_draw_line(x1, y1, x1, y2, c);
ee_draw_line(x1, y2, x2, y2, c);
ee_draw_line(x2, y2, x2, y1, c);
ee_draw_line(x2, y1, x1, y1, c);
caca_draw_line(x1, y1, x1, y2, c);
caca_draw_line(x1, y2, x2, y2, c);
caca_draw_line(x2, y2, x2, y1, c);
caca_draw_line(x2, y1, x1, y1, c);
}

void ee_draw_thin_box(int x1, int y1, int x2, int y2)
void caca_draw_thin_box(int x1, int y1, int x2, int y2)
{
int x, y, xmax, ymax;

@@ -51,8 +51,8 @@ void ee_draw_thin_box(int x1, int y1, int x2, int y2)
y1 = y2; y2 = tmp;
}

xmax = ee_get_width() - 1;
ymax = ee_get_height() - 1;
xmax = caca_get_width() - 1;
ymax = caca_get_height() - 1;

if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
return;
@@ -60,35 +60,35 @@ void ee_draw_thin_box(int x1, int y1, int x2, int y2)
/* Draw edges */
if(y1 >= 0)
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
ee_putchar(x, y1, '-');
caca_putchar(x, y1, '-');

if(y2 <= ymax)
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
ee_putchar(x, y2, '-');
caca_putchar(x, y2, '-');

if(x1 >= 0)
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
ee_putchar(x1, y, '|');
caca_putchar(x1, y, '|');

if(x2 <= xmax)
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
ee_putchar(x2, y, '|');
caca_putchar(x2, y, '|');

/* Draw corners */
if(x1 >= 0 && y1 >= 0)
ee_putchar(x1, y1, ',');
caca_putchar(x1, y1, ',');

if(x1 >= 0 && y2 <= ymax)
ee_putchar(x1, y2, '`');
caca_putchar(x1, y2, '`');

if(x2 <= xmax && y1 >= 0)
ee_putchar(x2, y1, '.');
caca_putchar(x2, y1, '.');

if(x2 <= xmax && y2 <= ymax)
ee_putchar(x2, y2, '\'');
caca_putchar(x2, y2, '\'');
}

void ee_fill_box(int x1, int y1, int x2, int y2, char c)
void caca_fill_box(int x1, int y1, int x2, int y2, char c)
{
int x, y, xmax, ymax;

@@ -104,8 +104,8 @@ void ee_fill_box(int x1, int y1, int x2, int y2, char c)
y1 = y2; y2 = tmp;
}

xmax = ee_get_width() - 1;
ymax = ee_get_height() - 1;
xmax = caca_get_width() - 1;
ymax = caca_get_height() - 1;

if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
return;
@@ -117,6 +117,6 @@ void ee_fill_box(int x1, int y1, int x2, int y2, char c)

for(y = y1; y <= y2; y++)
for(x = x1; x <= x2; x++)
ee_putchar(x, y, c);
caca_putchar(x, y, c);
}


libee/ee.c → libcaca/caca.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -42,24 +42,24 @@
#include <sys/time.h>
#include <time.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

static unsigned int _ee_delay;
static unsigned int _ee_rendertime;
char *_ee_empty_line;
char *_ee_scratch_line;
static unsigned int _caca_delay;
static unsigned int _caca_rendertime;
char *_caca_empty_line;
char *_caca_scratch_line;

#if defined(USE_NCURSES)
int _ee_attr[16];
int _caca_attr[16];
#endif

#if defined(USE_CONIO)
static struct text_info ti;
char *_ee_screen;
char *_caca_screen;
#endif

int ee_init(void)
int caca_init(void)
{
#if defined(USE_SLANG)
static char *slang_colors[16] =
@@ -143,38 +143,38 @@ int ee_init(void)

for(i = 0; i < 8; i++)
{
_ee_attr[i] = COLOR_PAIR(1 + i);
_ee_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i);
_caca_attr[i] = COLOR_PAIR(1 + i);
_caca_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i);
}

#elif defined(USE_CONIO)
gettextinfo(&ti);
_ee_screen = malloc(2 * ti.screenwidth * ti.screenheight);
if(_ee_screen == NULL)
_caca_screen = malloc(2 * ti.screenwidth * ti.screenheight);
if(_caca_screen == NULL)
return -1;
_wscroll = 0;
_setcursortype(_NOCURSOR);
clrscr();
# if defined(SCREENUPDATE_IN_PC_H)
ScreenRetrieve(_ee_screen);
ScreenRetrieve(_caca_screen);
# else
/* FIXME */
# endif

#endif
_ee_empty_line = malloc(ee_get_width() + 1);
memset(_ee_empty_line, ' ', ee_get_width());
_ee_empty_line[ee_get_width()] = '\0';
_caca_empty_line = malloc(caca_get_width() + 1);
memset(_caca_empty_line, ' ', caca_get_width());
_caca_empty_line[caca_get_width()] = '\0';

_ee_scratch_line = malloc(ee_get_width() + 1);
_caca_scratch_line = malloc(caca_get_width() + 1);

_ee_delay = 0;
_ee_rendertime = 0;
_caca_delay = 0;
_caca_rendertime = 0;

return 0;
}

unsigned int ee_get_width(void)
unsigned int caca_get_width(void)
{
#if defined(USE_SLANG)
return SLtt_Screen_Cols;
@@ -185,7 +185,7 @@ unsigned int ee_get_width(void)
#endif
}

unsigned int ee_get_height(void)
unsigned int caca_get_height(void)
{
#if defined(USE_SLANG)
return SLtt_Screen_Rows;
@@ -196,17 +196,17 @@ unsigned int ee_get_height(void)
#endif
}

void ee_set_delay(unsigned int usec)
void caca_set_delay(unsigned int usec)
{
_ee_delay = usec;
_caca_delay = usec;
}

unsigned int ee_get_rendertime(void)
unsigned int caca_get_rendertime(void)
{
return _ee_rendertime;
return _caca_rendertime;
}

const char *ee_get_color_name(unsigned int color)
const char *caca_get_color_name(unsigned int color)
{
static const char *color_names[16] =
{
@@ -234,7 +234,7 @@ const char *ee_get_color_name(unsigned int color)
return color_names[color];
}

static unsigned int _ee_getticks(void)
static unsigned int _caca_getticks(void)
{
static unsigned int last_sec = 0, last_usec = 0;

@@ -254,11 +254,11 @@ static unsigned int _ee_getticks(void)
return ticks;
}

void ee_refresh(void)
void caca_refresh(void)
{
#define IDLE_USEC 10000
static unsigned int lastticks = 0;
unsigned int ticks = lastticks + _ee_getticks();
unsigned int ticks = lastticks + _caca_getticks();

#if defined(USE_SLANG)
SLsmg_refresh();
@@ -266,28 +266,28 @@ void ee_refresh(void)
refresh();
#elif defined(USE_CONIO)
# if defined(SCREENUPDATE_IN_PC_H)
ScreenUpdate(_ee_screen);
ScreenUpdate(_caca_screen);
# else
/* FIXME */
# endif
#endif

/* Wait until _ee_delay + time of last call */
ticks += _ee_getticks();
for(; ticks < _ee_delay - IDLE_USEC; ticks += _ee_getticks())
/* Wait until _caca_delay + time of last call */
ticks += _caca_getticks();
for(; ticks < _caca_delay - IDLE_USEC; ticks += _caca_getticks())
usleep(IDLE_USEC);

/* Update the sliding mean of the render time */
_ee_rendertime = (7 * _ee_rendertime + ticks) / 8;
_caca_rendertime = (7 * _caca_rendertime + ticks) / 8;

lastticks = ticks - _ee_delay;
lastticks = ticks - _caca_delay;

/* If we drifted too much, it's bad, bad, bad. */
if(lastticks > _ee_delay)
if(lastticks > _caca_delay)
lastticks = 0;
}

void ee_end(void)
void caca_end(void)
{
#if defined(USE_SLANG)
SLtt_set_cursor_visibility(1);
@@ -300,7 +300,7 @@ void ee_end(void)
_wscroll = 1;
textcolor((enum COLORS)WHITE);
textbackground((enum COLORS)BLACK);
gotoxy(ee_get_width(), ee_get_height());
gotoxy(caca_get_width(), caca_get_height());
cputs("\r\n");
_setcursortype(_NORMALCURSOR);
#endif

+ 116
- 0
libcaca/caca.h Parādīt failu

@@ -0,0 +1,116 @@
/*
* libcaca 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.
*/

#ifndef __EE_H__
#define __EE_H__

#ifdef __cplusplus
extern "C"
{
#endif

/*
* Colors
*/
enum caca_colors
{
EE_BLACK = 0,
EE_BLUE = 1,
EE_GREEN = 2,
EE_CYAN = 3,
EE_RED = 4,
EE_MAGENTA = 5,
EE_BROWN = 6,
EE_LIGHTGRAY = 7,
EE_DARKGRAY = 8,
EE_LIGHTBLUE = 9,
EE_LIGHTGREEN = 10,
EE_LIGHTCYAN = 11,
EE_LIGHTRED = 12,
EE_LIGHTMAGENTA = 13,
EE_YELLOW = 14,
EE_WHITE = 15
};

/*
* Types
*/
struct caca_sprite;

/*
* Prototypes
*/
int caca_init(void);
void caca_set_delay(unsigned int);
unsigned int caca_get_rendertime(void);
unsigned int caca_get_width(void);
unsigned int caca_get_height(void);
const char *caca_get_color_name(unsigned int);
void caca_refresh(void);
void caca_end(void);

char caca_get_key(void);

void caca_set_color(int);
int caca_get_color(void);
void caca_putchar(int, int, char);
void caca_putstr(int, int, const char *);
void caca_printf(int, int, const char *, ...);
void caca_clear(void);

void caca_draw_line(int, int, int, int, char);
void caca_draw_polyline(const int[], const int[], int, char);
void caca_draw_thin_line(int, int, int, int);
void caca_draw_thin_polyline(const int[], const int[], int);

void caca_draw_circle(int, int, int, char);
void caca_draw_ellipse(int, int, int, int, char);
void caca_draw_thin_ellipse(int, int, int, int);
void caca_fill_ellipse(int, int, int, int, char);

void caca_draw_box(int, int, int, int, char);
void caca_draw_thin_box(int, int, int, int);
void caca_fill_box(int, int, int, int, char);

void caca_draw_triangle(int, int, int, int, int, int, char);
void caca_draw_thin_triangle(int, int, int, int, int, int);
void caca_fill_triangle(int, int, int, int, int, int, char);

int caca_rand(int, int);
unsigned int caca_sqrt(unsigned int);

struct caca_sprite * caca_load_sprite(const char *);
int caca_get_sprite_frames(struct caca_sprite *);
int caca_get_sprite_width(struct caca_sprite *, int);
int caca_get_sprite_height(struct caca_sprite *, int);
int caca_get_sprite_dx(struct caca_sprite *, int);
int caca_get_sprite_dy(struct caca_sprite *, int);
void caca_draw_sprite(int, int, struct caca_sprite *, int);
void caca_free_sprite(struct caca_sprite *);

void caca_blit(int, int, int, int, void *, int, int);

#ifdef __cplusplus
}
#endif

#endif /* __EE_H__ */

libee/ee_internals.h → libcaca/caca_internals.h Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -24,14 +24,14 @@
#define __EE_INTERNALS_H__

#if defined(USE_NCURSES)
extern int _ee_attr[];
extern int _caca_attr[];
#endif

#if defined(USE_CONIO)
extern char *_ee_screen;
extern char *_caca_screen;
#endif

extern char *_ee_empty_line;
extern char *_ee_scratch_line;
extern char *_caca_empty_line;
extern char *_caca_scratch_line;

#endif /* __EE_INTERNALS_H__ */

libee/conic.c → libcaca/conic.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -30,12 +30,12 @@ typedef unsigned char uint8_t;

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

static void ellipsepoints(int, int, int, int, char);

void ee_draw_circle(int x, int y, int r, char c)
void caca_draw_circle(int x, int y, int r, char c)
{
int test, dx, dy;

@@ -49,7 +49,7 @@ void ee_draw_circle(int x, int y, int r, char c)
}
}

void ee_fill_ellipse(int xo, int yo, int a, int b, char c)
void caca_fill_ellipse(int xo, int yo, int a, int b, char c)
{
int d2;
int x = 0;
@@ -65,15 +65,15 @@ void ee_fill_ellipse(int xo, int yo, int a, int b, char c)
else
{
d1 += b*b*(2*x*1) + a*a*(-2*y+2);
ee_draw_line(xo - x, yo - y, xo + x, yo - y, c);
ee_draw_line(xo - x, yo + y, xo + x, yo + y, c);
caca_draw_line(xo - x, yo - y, xo + x, yo - y, c);
caca_draw_line(xo - x, yo + y, xo + x, yo + y, c);
y--;
}
x++;
}

ee_draw_line(xo - x, yo - y, xo + x, yo - y, c);
ee_draw_line(xo - x, yo + y, xo + x, yo + y, c);
caca_draw_line(xo - x, yo - y, xo + x, yo - y, c);
caca_draw_line(xo - x, yo + y, xo + x, yo + y, c);

d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
while(y > 0)
@@ -89,12 +89,12 @@ void ee_fill_ellipse(int xo, int yo, int a, int b, char c)
}

y--;
ee_draw_line(xo - x, yo - y, xo + x, yo - y, c);
ee_draw_line(xo - x, yo + y, xo + x, yo + y, c);
caca_draw_line(xo - x, yo - y, xo + x, yo - y, c);
caca_draw_line(xo - x, yo + y, xo + x, yo + y, c);
}
}

void ee_draw_ellipse(int xo, int yo, int a, int b, char c)
void caca_draw_ellipse(int xo, int yo, int a, int b, char c)
{
int d2;
int x = 0;
@@ -136,7 +136,7 @@ void ee_draw_ellipse(int xo, int yo, int a, int b, char c)
}
}

void ee_draw_thin_ellipse(int xo, int yo, int a, int b)
void caca_draw_thin_ellipse(int xo, int yo, int a, int b)
{
/* FIXME: this is not correct */
int d2;
@@ -183,25 +183,25 @@ static void ellipsepoints(int xo, int yo, int x, int y, char c)
{
uint8_t b = 0;

if(xo + x >= 0 && xo + x < ee_get_width())
if(xo + x >= 0 && xo + x < caca_get_width())
b |= 0x1;
if(xo - x >= 0 && xo - x < ee_get_width())
if(xo - x >= 0 && xo - x < caca_get_width())
b |= 0x2;
if(yo + y >= 0 && yo + y < ee_get_height())
if(yo + y >= 0 && yo + y < caca_get_height())
b |= 0x4;
if(yo - y >= 0 && yo - y < ee_get_height())
if(yo - y >= 0 && yo - y < caca_get_height())
b |= 0x8;

if((b & (0x1|0x4)) == (0x1|0x4))
ee_putchar(xo + x, yo + y, c);
caca_putchar(xo + x, yo + y, c);

if((b & (0x2|0x4)) == (0x2|0x4))
ee_putchar(xo - x, yo + y, c);
caca_putchar(xo - x, yo + y, c);

if((b & (0x1|0x8)) == (0x1|0x8))
ee_putchar(xo + x, yo - y, c);
caca_putchar(xo + x, yo - y, c);

if((b & (0x2|0x8)) == (0x2|0x8))
ee_putchar(xo - x, yo - y, c);
caca_putchar(xo - x, yo - y, c);
}


libee/graphics.c → libcaca/graphics.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -36,34 +36,34 @@
#include <stdlib.h>
#include <stdarg.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

static int _ee_color = 0;
static int _caca_color = 0;

void ee_set_color(int color)
void caca_set_color(int color)
{
if(color < 0 || color > 15)
return;

_ee_color = color;
_caca_color = color;
#if defined(USE_SLANG)
SLsmg_set_color(color + 1);
#elif defined(USE_NCURSES)
attrset(_ee_attr[color]);
attrset(_caca_attr[color]);
#elif defined(USE_CONIO)
textcolor(color);
#endif
}

int ee_get_color(void)
int caca_get_color(void)
{
return _ee_color;
return _caca_color;
}

void ee_putchar(int x, int y, char c)
void caca_putchar(int x, int y, char c)
{
if(x < 0 || x >= ee_get_width() || y < 0 || y >= ee_get_height())
if(x < 0 || x >= caca_get_width() || y < 0 || y >= caca_get_height())
return;

#if defined(USE_SLANG)
@@ -73,18 +73,18 @@ void ee_putchar(int x, int y, char c)
move(y, x);
addch(c);
#elif defined(USE_CONIO)
_ee_screen[2 * (x + y * ee_get_width())] = c;
_ee_screen[2 * (x + y * ee_get_width()) + 1] = _ee_color;
_caca_screen[2 * (x + y * caca_get_width())] = c;
_caca_screen[2 * (x + y * caca_get_width()) + 1] = _caca_color;
// gotoxy(x + 1, y + 1);
// putch(c);
#endif
}

void ee_putstr(int x, int y, const char *s)
void caca_putstr(int x, int y, const char *s)
{
int len;

if(y < 0 || y >= ee_get_height() || x >= ee_get_width())
if(y < 0 || y >= caca_get_height() || x >= caca_get_width())
return;

len = strlen(s);
@@ -98,11 +98,11 @@ void ee_putstr(int x, int y, const char *s)
x = 0;
}

if(x + len >= ee_get_width())
if(x + len >= caca_get_width())
{
memcpy(_ee_scratch_line, s, ee_get_width() - x);
_ee_scratch_line[ee_get_width() - x] = '\0';
s = _ee_scratch_line;
memcpy(_caca_scratch_line, s, caca_get_width() - x);
_caca_scratch_line[caca_get_width() - x] = '\0';
s = _caca_scratch_line;
}

#if defined(USE_SLANG)
@@ -112,46 +112,46 @@ void ee_putstr(int x, int y, const char *s)
move(y, x);
addstr(s);
#elif defined(USE_CONIO)
char *buf = _ee_screen + 2 * (x + y * ee_get_width());
char *buf = _caca_screen + 2 * (x + y * caca_get_width());
while(*s)
{
*buf++ = *s++;
*buf++ = _ee_color;
*buf++ = _caca_color;
}
// gotoxy(x + 1, y + 1);
// cputs(s);
#endif
}

void ee_printf(int x, int y, const char *format, ...)
void caca_printf(int x, int y, const char *format, ...)
{
char tmp[BUFSIZ];
char *buf = tmp;
va_list args;

if(y < 0 || y >= ee_get_height() || x >= ee_get_width())
if(y < 0 || y >= caca_get_height() || x >= caca_get_width())
return;

if(ee_get_width() - x + 1 > BUFSIZ)
buf = malloc(ee_get_width() - x + 1);
if(caca_get_width() - x + 1 > BUFSIZ)
buf = malloc(caca_get_width() - x + 1);

va_start(args, format);
vsnprintf(buf, ee_get_width() - x + 1, format, args);
buf[ee_get_width() - x] = '\0';
vsnprintf(buf, caca_get_width() - x + 1, format, args);
buf[caca_get_width() - x] = '\0';
va_end(args);

ee_putstr(x, y, buf);
caca_putstr(x, y, buf);

if(buf != tmp)
free(buf);
}

void ee_clear(void)
void caca_clear(void)
{
/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
int y = ee_get_height();
int y = caca_get_height();

while(y--)
ee_putstr(0, y, _ee_empty_line);
caca_putstr(0, y, _caca_empty_line);
}


libee/io.c → libcaca/io.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -32,10 +32,10 @@
# error "no graphics library detected"
#endif

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

char ee_get_key(void)
char caca_get_key(void)
{
#if defined(USE_SLANG)
return SLang_input_pending(0) ? SLang_getkey() : 0;

libee/line.c → libcaca/line.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -30,8 +30,8 @@ typedef unsigned char uint8_t;

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

struct line
{
@@ -56,7 +56,7 @@ static void draw_thin_line(struct line*);
* \param c Character to draw the line with.
* \return nothing
*/
void ee_draw_line(int x1, int y1, int x2, int y2, char c)
void caca_draw_line(int x1, int y1, int x2, int y2, char c)
{
struct line s;
s.x1 = x1;
@@ -68,7 +68,7 @@ void ee_draw_line(int x1, int y1, int x2, int y2, char c)
clip_line(&s);
}

void ee_draw_polyline(const int x[], const int y[], int n, char c)
void caca_draw_polyline(const int x[], const int y[], int n, char c)
{
int i;
struct line s;
@@ -94,7 +94,7 @@ void ee_draw_polyline(const int x[], const int y[], int n, char c)
* \param y2 Y coordinate of the second point.
* \return nothing
*/
void ee_draw_thin_line(int x1, int y1, int x2, int y2)
void caca_draw_thin_line(int x1, int y1, int x2, int y2)
{
struct line s;
s.x1 = x1;
@@ -105,7 +105,7 @@ void ee_draw_thin_line(int x1, int y1, int x2, int y2)
clip_line(&s);
}

void ee_draw_thin_polyline(const int x[], const int y[], int n)
void caca_draw_thin_polyline(const int x[], const int y[], int n)
{
int i;
struct line s;
@@ -163,7 +163,7 @@ static void clip_line(struct line* s)
}
else if(bits1 & (1<<1))
{
int xmax = ee_get_width() - 1;
int xmax = caca_get_width() - 1;
s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1);
s->x1 = xmax;
}
@@ -174,7 +174,7 @@ static void clip_line(struct line* s)
}
else if(bits1 & (1<<3))
{
int ymax = ee_get_height() - 1;
int ymax = caca_get_height() - 1;
s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1);
s->y1 = ymax;
}
@@ -195,12 +195,12 @@ static uint8_t clip_bits(int x, int y)

if(x < 0)
b |= (1<<0);
else if(x >= ee_get_width())
else if(x >= caca_get_width())
b |= (1<<1);

if(y < 0)
b |= (1<<2);
else if(y >= ee_get_height())
else if(y >= caca_get_height())
b |= (1<<3);

return b;
@@ -235,7 +235,7 @@ static void draw_solid_line(struct line* s)

for(; dx>=0; dx--)
{
ee_putchar(x1, y1, s->c);
caca_putchar(x1, y1, s->c);
if(delta > 0)
{
x1 += xinc;
@@ -257,7 +257,7 @@ static void draw_solid_line(struct line* s)

for(; dy >= 0; dy--)
{
ee_putchar(x1, y1, s->c);
caca_putchar(x1, y1, s->c);
if(delta > 0)
{
x1 += xinc;
@@ -329,7 +329,7 @@ static void draw_thin_line(struct line* s)
{
if(delta > 0)
{
ee_putchar(x1, y1, charmapy[1]);
caca_putchar(x1, y1, charmapy[1]);
x1++;
y1 += yinc;
delta += dpru;
@@ -338,9 +338,9 @@ static void draw_thin_line(struct line* s)
else
{
if(prev)
ee_putchar(x1, y1, charmapy[0]);
caca_putchar(x1, y1, charmapy[0]);
else
ee_putchar(x1, y1, '-');
caca_putchar(x1, y1, '-');
x1++;
delta += dpr;
prev = 0;
@@ -357,15 +357,15 @@ static void draw_thin_line(struct line* s)
{
if(delta > 0)
{
ee_putchar(x1, y1, charmapx[0]);
ee_putchar(x1 + 1, y1, charmapx[1]);
caca_putchar(x1, y1, charmapx[0]);
caca_putchar(x1 + 1, y1, charmapx[1]);
x1++;
y1 += yinc;
delta += dpru;
}
else
{
ee_putchar(x1, y1, '|');
caca_putchar(x1, y1, '|');
y1 += yinc;
delta += dpr;
}

libee/math.c → libcaca/math.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -24,15 +24,15 @@

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

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

unsigned int ee_sqrt(unsigned int a)
unsigned int caca_sqrt(unsigned int a)
{
if(a == 0)
return 0;
@@ -54,6 +54,6 @@ unsigned int ee_sqrt(unsigned int a)
return x;
}

return 2 * ee_sqrt(a / 4);
return 2 * caca_sqrt(a / 4);
}


libee/sprite.c → libcaca/sprite.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -26,10 +26,10 @@
#include <stdlib.h>
#include <string.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

struct ee_frame
struct caca_frame
{
int w, h;
int dx, dy;
@@ -37,23 +37,23 @@ struct ee_frame
int *color;
};

struct ee_sprite
struct caca_sprite
{
int nf;
struct ee_frame *frames;
struct caca_frame *frames;
};

struct ee_sprite *ee_load_sprite(const char *file)
struct caca_sprite *caca_load_sprite(const char *file)
{
char buf[BUFSIZ];
struct ee_sprite *sprite;
struct caca_sprite *sprite;
FILE *fd;

fd = fopen(file, "r");
if(fd == NULL)
return NULL;

sprite = malloc(sizeof(struct ee_sprite));
sprite = malloc(sizeof(struct caca_sprite));
if(sprite == NULL)
goto sprite_alloc_failed;

@@ -64,7 +64,7 @@ struct ee_sprite *ee_load_sprite(const char *file)
{
int x, y;
int w = 0, h = 0, dx = 0, dy = 0;
struct ee_frame *frame;
struct caca_frame *frame;

/* Get width and height */
if(!fgets(buf, BUFSIZ, fd))
@@ -77,7 +77,7 @@ struct ee_sprite *ee_load_sprite(const char *file)
if(sprite->nf)
{
void *tmp = realloc(sprite->frames,
(sprite->nf + 1) * sizeof(struct ee_frame));
(sprite->nf + 1) * sizeof(struct caca_frame));
if(tmp == NULL)
goto frame_failed;
sprite->frames = tmp;
@@ -85,7 +85,7 @@ struct ee_sprite *ee_load_sprite(const char *file)
}
else
{
sprite->frames = malloc((sprite->nf + 1) * sizeof(struct ee_frame));
sprite->frames = malloc((sprite->nf + 1) * sizeof(struct caca_frame));
if(sprite->frames == NULL)
goto sprite_failed;
sprite->nf++;
@@ -158,7 +158,7 @@ sprite_alloc_failed:
return NULL;
}

int ee_get_sprite_frames(struct ee_sprite *sprite)
int caca_get_sprite_frames(struct caca_sprite *sprite)
{
if(sprite == NULL)
return 0;
@@ -166,7 +166,7 @@ int ee_get_sprite_frames(struct ee_sprite *sprite)
return sprite->nf;
}

int ee_get_sprite_width(struct ee_sprite *sprite, int f)
int caca_get_sprite_width(struct caca_sprite *sprite, int f)
{
if(sprite == NULL)
return 0;
@@ -177,7 +177,7 @@ int ee_get_sprite_width(struct ee_sprite *sprite, int f)
return sprite->frames[f].w;
}

int ee_get_sprite_height(struct ee_sprite *sprite, int f)
int caca_get_sprite_height(struct caca_sprite *sprite, int f)
{
if(sprite == NULL)
return 0;
@@ -188,7 +188,7 @@ int ee_get_sprite_height(struct ee_sprite *sprite, int f)
return sprite->frames[f].h;
}

int ee_get_sprite_dx(struct ee_sprite *sprite, int f)
int caca_get_sprite_dx(struct caca_sprite *sprite, int f)
{
if(sprite == NULL)
return 0;
@@ -199,7 +199,7 @@ int ee_get_sprite_dx(struct ee_sprite *sprite, int f)
return sprite->frames[f].dx;
}

int ee_get_sprite_dy(struct ee_sprite *sprite, int f)
int caca_get_sprite_dy(struct caca_sprite *sprite, int f)
{
if(sprite == NULL)
return 0;
@@ -210,10 +210,10 @@ int ee_get_sprite_dy(struct ee_sprite *sprite, int f)
return sprite->frames[f].dy;
}

void ee_draw_sprite(int x, int y, struct ee_sprite *sprite, int f)
void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f)
{
int i, j, oldcol;
struct ee_frame *frame;
struct caca_frame *frame;

if(sprite == NULL)
return;
@@ -223,7 +223,7 @@ void ee_draw_sprite(int x, int y, struct ee_sprite *sprite, int f)

frame = &sprite->frames[f];

oldcol = ee_get_color();
oldcol = caca_get_color();

for(j = 0; j < frame->h; j++)
{
@@ -232,17 +232,17 @@ void ee_draw_sprite(int x, int y, struct ee_sprite *sprite, int f)
int col = frame->color[frame->w * j + i];
if(col >= 0)
{
ee_set_color(col);
ee_putchar(x + i - frame->dx, y + j - frame->dy,
caca_set_color(col);
caca_putchar(x + i - frame->dx, y + j - frame->dy,
frame->chars[frame->w * j + i]);
}
}
}

ee_set_color(oldcol);
caca_set_color(oldcol);
}

void ee_free_sprite(struct ee_sprite *sprite)
void caca_free_sprite(struct caca_sprite *sprite)
{
int i;

@@ -251,7 +251,7 @@ void ee_free_sprite(struct ee_sprite *sprite)

for(i = sprite->nf; i--;)
{
struct ee_frame *frame = &sprite->frames[i];
struct caca_frame *frame = &sprite->frames[i];
free(frame->chars);
free(frame->color);
}

libee/triangle.c → libcaca/triangle.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* libee ASCII-Art library
* libcaca ASCII-Art library
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -24,37 +24,37 @@

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"
#include "caca.h"
#include "caca_internals.h"

void ee_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
void caca_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
{
ee_draw_line(x1, y1, x2, y2, c);
ee_draw_line(x2, y2, x3, y3, c);
ee_draw_line(x3, y3, x1, y1, c);
caca_draw_line(x1, y1, x2, y2, c);
caca_draw_line(x2, y2, x3, y3, c);
caca_draw_line(x3, y3, x1, y1, c);
}

void ee_draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
void caca_draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
ee_draw_thin_line(x1, y1, x2, y2);
ee_draw_thin_line(x2, y2, x3, y3);
ee_draw_thin_line(x3, y3, x1, y1);
caca_draw_thin_line(x1, y1, x2, y2);
caca_draw_thin_line(x2, y2, x3, y3);
caca_draw_thin_line(x3, y3, x1, y1);
}

void ee_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
void caca_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
{
int x, y, xa, xb, xmax, ymax;

/* Bubble-sort y1 <= y2 <= y3 */
if(y1 > y2)
{
ee_fill_triangle(x2, y2, x1, y1, x3, y3, c);
caca_fill_triangle(x2, y2, x1, y1, x3, y3, c);
return;
}

if(y2 > y3)
{
ee_fill_triangle(x1, y1, x3, y3, x2, y2, c);
caca_fill_triangle(x1, y1, x3, y3, x2, y2, c);
return;
}

@@ -63,8 +63,8 @@ void ee_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
x2 *= 4;
x3 *= 4;

xmax = ee_get_width() - 1;
ymax = ee_get_height() - 1;
xmax = caca_get_width() - 1;
ymax = caca_get_height() - 1;

/* Rasterize our triangle */
for(y = y1 < 0 ? 0 : y1; y <= y3 && y <= ymax; y++)
@@ -96,7 +96,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_putchar(x, y, c);
caca_putchar(x, y, c);
}
}


+ 0
- 116
libee/ee.h Parādīt failu

@@ -1,116 +0,0 @@
/*
* 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.
*/

#ifndef __EE_H__
#define __EE_H__

#ifdef __cplusplus
extern "C"
{
#endif

/*
* Colors
*/
enum ee_colors
{
EE_BLACK = 0,
EE_BLUE = 1,
EE_GREEN = 2,
EE_CYAN = 3,
EE_RED = 4,
EE_MAGENTA = 5,
EE_BROWN = 6,
EE_LIGHTGRAY = 7,
EE_DARKGRAY = 8,
EE_LIGHTBLUE = 9,
EE_LIGHTGREEN = 10,
EE_LIGHTCYAN = 11,
EE_LIGHTRED = 12,
EE_LIGHTMAGENTA = 13,
EE_YELLOW = 14,
EE_WHITE = 15
};

/*
* Types
*/
struct ee_sprite;

/*
* Prototypes
*/
int ee_init(void);
void ee_set_delay(unsigned int);
unsigned int ee_get_rendertime(void);
unsigned int ee_get_width(void);
unsigned int ee_get_height(void);
const char *ee_get_color_name(unsigned int);
void ee_refresh(void);
void ee_end(void);

char ee_get_key(void);

void ee_set_color(int);
int ee_get_color(void);
void ee_putchar(int, int, char);
void ee_putstr(int, int, const char *);
void ee_printf(int, int, const char *, ...);
void ee_clear(void);

void ee_draw_line(int, int, int, int, char);
void ee_draw_polyline(const int[], const int[], int, char);
void ee_draw_thin_line(int, int, int, int);
void ee_draw_thin_polyline(const int[], const int[], int);

void ee_draw_circle(int, int, int, char);
void ee_draw_ellipse(int, int, int, int, char);
void ee_draw_thin_ellipse(int, int, int, int);
void ee_fill_ellipse(int, int, int, int, char);

void ee_draw_box(int, int, int, int, char);
void ee_draw_thin_box(int, int, int, int);
void ee_fill_box(int, int, int, int, char);

void ee_draw_triangle(int, int, int, int, int, int, char);
void ee_draw_thin_triangle(int, int, int, int, int, int);
void ee_fill_triangle(int, int, int, int, int, int, char);

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

struct ee_sprite * ee_load_sprite(const char *);
int ee_get_sprite_frames(struct ee_sprite *);
int ee_get_sprite_width(struct ee_sprite *, int);
int ee_get_sprite_height(struct ee_sprite *, int);
int ee_get_sprite_dx(struct ee_sprite *, int);
int ee_get_sprite_dy(struct ee_sprite *, int);
void ee_draw_sprite(int, int, struct ee_sprite *, int);
void ee_free_sprite(struct ee_sprite *);

void ee_blit(int, int, int, int, void *, int, int);

#ifdef __cplusplus
}
#endif

#endif /* __EE_H__ */

+ 2
- 2
src/Makefile.am Parādīt failu

@@ -2,7 +2,7 @@
# Automake targets and declarations for ttyvaders
###############################################################################

AM_CPPFLAGS = -I$(top_srcdir)/libee
AM_CPPFLAGS = -I$(top_srcdir)/libcaca

if USE_SLANG
LDFLAGS_slang = -lslang
@@ -29,5 +29,5 @@ ttyvaders_SOURCES = \
tunnel.c \
weapons.c \
$(NULL)
ttyvaders_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
ttyvaders_LDADD = ../libcaca/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm


+ 10
- 10
src/aliens.c Parādīt failu

@@ -26,9 +26,9 @@

#include "common.h"

struct ee_sprite *foo_sprite;
struct ee_sprite *bar_sprite;
struct ee_sprite *baz_sprite;
struct caca_sprite *foo_sprite;
struct caca_sprite *bar_sprite;
struct caca_sprite *baz_sprite;

void init_aliens(game *g, aliens *al)
{
@@ -39,9 +39,9 @@ void init_aliens(game *g, aliens *al)
al->type[i] = ALIEN_NONE;
}

foo_sprite = ee_load_sprite("data/foofight.txt");
bar_sprite = ee_load_sprite("data/barfight.txt");
baz_sprite = ee_load_sprite("data/bazfight.txt");
foo_sprite = caca_load_sprite("data/foofight.txt");
bar_sprite = caca_load_sprite("data/barfight.txt");
baz_sprite = caca_load_sprite("data/bazfight.txt");
}

void draw_aliens(game *g, aliens *al)
@@ -53,13 +53,13 @@ void draw_aliens(game *g, aliens *al)
switch(al->type[i])
{
case ALIEN_FOO:
ee_draw_sprite(al->x[i], al->y[i], foo_sprite, al->img[i] % 8);
caca_draw_sprite(al->x[i], al->y[i], foo_sprite, al->img[i] % 8);
break;
case ALIEN_BAR:
ee_draw_sprite(al->x[i], al->y[i], bar_sprite, al->img[i] % 2);
caca_draw_sprite(al->x[i], al->y[i], bar_sprite, al->img[i] % 2);
break;
case ALIEN_BAZ:
ee_draw_sprite(al->x[i], al->y[i], baz_sprite, al->img[i] % 6);
caca_draw_sprite(al->x[i], al->y[i], baz_sprite, al->img[i] % 6);
break;
case ALIEN_NONE:
break;
@@ -78,7 +78,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], ee_rand(0,4) ? BONUS_GREEN : BONUS_LIFE);
add_bonus(g, g->bo, al->x[i], al->y[i], caca_rand(0,4) ? BONUS_GREEN : BONUS_LIFE);
}

/* Update coordinates */


+ 6
- 6
src/bonus.c Parādīt failu

@@ -26,8 +26,8 @@

#include "common.h"

struct ee_sprite *heart_sprite;
struct ee_sprite *gem_sprite;
struct caca_sprite *heart_sprite;
struct caca_sprite *gem_sprite;

void init_bonus(game *g, bonus *bo)
{
@@ -38,8 +38,8 @@ void init_bonus(game *g, bonus *bo)
bo->type[i] = BONUS_NONE;
}

heart_sprite = ee_load_sprite("data/bonheart.txt");
gem_sprite = ee_load_sprite("data/bongem.txt");
heart_sprite = caca_load_sprite("data/bonheart.txt");
gem_sprite = caca_load_sprite("data/bongem.txt");
}

void draw_bonus(game *g, bonus *bo)
@@ -51,11 +51,11 @@ void draw_bonus(game *g, bonus *bo)
switch(bo->type[i])
{
case BONUS_GREEN:
ee_draw_sprite(bo->x[i], bo->y[i], gem_sprite,
caca_draw_sprite(bo->x[i], bo->y[i], gem_sprite,
(bo->n[i]/2 % 3) ? 0 : 1);
break;
case BONUS_LIFE:
ee_draw_sprite(bo->x[i], bo->y[i], heart_sprite,
caca_draw_sprite(bo->x[i], bo->y[i], heart_sprite,
(bo->n[i] % 3) ? 0 : 1);
break;
case BONUS_NONE:


+ 14
- 14
src/box.c Parādīt failu

@@ -45,12 +45,12 @@ void draw_box(game *g, box *b)
{
int j, frame;

ee_set_color(EE_YELLOW);
caca_set_color(EE_YELLOW);

/* Draw the thin horizontal line */
if(b->frame < 8)
{
ee_draw_line(b->x - b->w * b->frame / 16, b->y,
caca_draw_line(b->x - b->w * b->frame / 16, b->y,
b->x + b->w * b->frame / 16 - 1, b->y, 'X');
return;
}
@@ -58,23 +58,23 @@ void draw_box(game *g, box *b)
/* Draw the frame */
frame = b->frame < 12 ? b->frame : 12;

ee_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
caca_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8, 'X');
ee_draw_line(b->x - b->w / 2, b->y + b->h * (frame - 8) / 8,
caca_draw_line(b->x - b->w / 2, b->y + b->h * (frame - 8) / 8,
b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8, 'X');

ee_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
caca_draw_line(b->x - b->w / 2, b->y - b->h * (frame - 8) / 8,
b->x - b->w / 2, b->y + b->h * (frame - 8) / 8 - 1, 'X');
ee_draw_line(b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8,
caca_draw_line(b->x + b->w / 2 - 1, b->y - b->h * (frame - 8) / 8,
b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, 'X');

ee_set_color(EE_BLACK);
caca_set_color(EE_BLACK);

for(j = b->y - b->h * (frame - 8) / 8 + 1;
j < b->y + b->h * (frame - 8) / 8;
j++)
{
ee_draw_line(b->x - b->w / 2 + 1, j,
caca_draw_line(b->x - b->w / 2 + 1, j,
b->x + b->w / 2 - 2, j, 'X');
}

@@ -84,18 +84,18 @@ void draw_box(game *g, box *b)
}

/* Draw the text inside the frame */
ee_set_color(EE_YELLOW);
caca_set_color(EE_YELLOW);

/* FIXME: use a font */
ee_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2,
caca_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,
caca_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,
caca_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,
caca_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,
caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6,
"X X X `XXXX XXXX' `XXXX XXXX'");
}



+ 3
- 3
src/ceo.c Parādīt failu

@@ -33,16 +33,16 @@ void ceo_alert(game *g)

while(!end)
{
ee_clear();
caca_clear();

if(ee_get_key() == '\t')
if(caca_get_key() == '\t')
{
end = 1;
}

fprintf(stderr, "foo\n");

ee_refresh();
caca_refresh();

usleep(40000);
}


+ 2
- 2
src/collide.c Parādīt failu

@@ -127,12 +127,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] -= ee_rand(0,2);
t->left[y-j] -= caca_rand(0,2);
}
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] += ee_rand(0,2);
t->right[y-j] += caca_rand(0,2);
}
}
break;


+ 1
- 1
src/common.h Parādīt failu

@@ -44,7 +44,7 @@ void intro(void);
/*
* Graphics primitives
*/
#include "ee.h"
#include "caca.h"

/*
* Useful macros


+ 20
- 20
src/explosions.c Parādīt failu

@@ -26,8 +26,8 @@

#include "common.h"

struct ee_sprite *medium_sprite;
struct ee_sprite *small_sprite;
struct caca_sprite *medium_sprite;
struct caca_sprite *small_sprite;

void init_explosions(game *g, explosions *ex)
{
@@ -38,8 +38,8 @@ void init_explosions(game *g, explosions *ex)
ex->type[i] = EXPLOSION_NONE;
}

medium_sprite = ee_load_sprite("data/xplmed.txt");
small_sprite = ee_load_sprite("data/xplsmall.txt");
medium_sprite = caca_load_sprite("data/xplmed.txt");
small_sprite = caca_load_sprite("data/xplsmall.txt");
}

void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
@@ -76,38 +76,38 @@ void draw_explosions(game *g, explosions *ex)
for(i = 0; i < EXPLOSIONS; i++)
{
#if 0
ee_set_color(GREEN);
ee_goto(ex->x[i] + 3, ex->y[i]);
switch(ee_rand(0,2))
caca_set_color(GREEN);
caca_goto(ex->x[i] + 3, ex->y[i]);
switch(caca_rand(0,2))
{
case 0:
ee_putchar('p');
ee_putchar('i');
ee_putchar('f');
caca_putchar('p');
caca_putchar('i');
caca_putchar('f');
break;
case 1:
ee_putchar('p');
ee_putchar('a');
ee_putchar('f');
caca_putchar('p');
caca_putchar('a');
caca_putchar('f');
break;
case 2:
ee_putchar('p');
ee_putchar('o');
ee_putchar('u');
ee_putchar('f');
caca_putchar('p');
caca_putchar('o');
caca_putchar('u');
caca_putchar('f');
break;
}
ee_putchar('!');
caca_putchar('!');
#endif

switch(ex->type[i])
{
case EXPLOSION_MEDIUM:
ee_draw_sprite(ex->x[i], ex->y[i], medium_sprite,
caca_draw_sprite(ex->x[i], ex->y[i], medium_sprite,
10 - ex->n[i]);
break;
case EXPLOSION_SMALL:
ee_draw_sprite(ex->x[i], ex->y[i], small_sprite,
caca_draw_sprite(ex->x[i], ex->y[i], small_sprite,
6 - ex->n[i]);
break;
case EXPLOSION_NONE:


+ 19
- 19
src/intro.c Parādīt failu

@@ -30,27 +30,27 @@

void intro(void)
{
struct ee_sprite *foo_sprite = ee_load_sprite("data/foofight.txt");
struct ee_sprite *bar_sprite = ee_load_sprite("data/barfight.txt");
struct ee_sprite *baz_sprite = ee_load_sprite("data/bazfight.txt");
struct caca_sprite *foo_sprite = caca_load_sprite("data/foofight.txt");
struct caca_sprite *bar_sprite = caca_load_sprite("data/barfight.txt");
struct caca_sprite *baz_sprite = caca_load_sprite("data/bazfight.txt");

int frame = 0;

while(ee_get_key() == 0)
while(caca_get_key() == 0)
{
int i, xo, yo, x[5], y[5];

frame++;

ee_clear();
caca_clear();

xo = ee_get_width() / 2;
yo = ee_get_height() / 2;
xo = caca_get_width() / 2;
yo = caca_get_height() / 2;

ee_set_color(EE_RED);
ee_fill_ellipse(xo, yo, 16, 8, '#');
ee_set_color(EE_GREEN);
ee_draw_thin_ellipse(xo, yo, 16, 8);
caca_set_color(EE_RED);
caca_fill_ellipse(xo, yo, 16, 8, '#');
caca_set_color(EE_GREEN);
caca_draw_thin_ellipse(xo, yo, 16, 8);

for(i = 0; i < 4; i ++)
{
@@ -60,16 +60,16 @@ void intro(void)
x[4] = x[0];
y[4] = y[0];

ee_set_color(EE_BLACK);
ee_fill_triangle(x[0], y[0], x[1], y[1], x[2], y[2], ' ');
ee_fill_triangle(x[0], y[0], x[3], y[3], x[2], y[2], ' ');
ee_draw_line(x[0], y[0], x[2], y[2], ' ');
ee_set_color(EE_GREEN);
ee_draw_thin_polyline(x, y, 4);
caca_set_color(EE_BLACK);
caca_fill_triangle(x[0], y[0], x[1], y[1], x[2], y[2], ' ');
caca_fill_triangle(x[0], y[0], x[3], y[3], x[2], y[2], ' ');
caca_draw_line(x[0], y[0], x[2], y[2], ' ');
caca_set_color(EE_GREEN);
caca_draw_thin_polyline(x, y, 4);

ee_draw_sprite(xo, yo, foo_sprite, frame % 5);
caca_draw_sprite(xo, yo, foo_sprite, frame % 5);

ee_refresh();
caca_refresh();

usleep(40000);
}


+ 10
- 10
src/main.c Parādīt failu

@@ -41,16 +41,16 @@ int main (int argc, char **argv)

srand(time(NULL));

if(ee_init())
if(caca_init())
{
return 1;
}

ee_set_delay(100000);
caca_set_delay(100000);

/* Initialize our program */
g->w = ee_get_width();
g->h = ee_get_height();
g->w = caca_get_width();
g->h = caca_get_height();

intro();

@@ -58,7 +58,7 @@ intro();
start_game(g);

/* Clean up */
ee_end();
caca_end();

return 0;
}
@@ -100,7 +100,7 @@ static void start_game (game *g)
{
char key;

while((key = ee_get_key()))
while((key = caca_get_key()))
{
switch(key)
{
@@ -198,11 +198,11 @@ static void start_game (game *g)
skip = 0;

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

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

/* Update game rules */
@@ -231,7 +231,7 @@ static void start_game (game *g)
}

/* Clear screen */
ee_clear();
caca_clear();

/* Print starfield, tunnel, aliens, player and explosions */
draw_starfield(g, g->sf);
@@ -251,7 +251,7 @@ static void start_game (game *g)
}

/* Refresh */
ee_refresh();
caca_refresh();

purcompteur++;
}


+ 18
- 18
src/overlay.c Parādīt failu

@@ -32,50 +32,50 @@ void draw_status(game *g)
static char dashes30[] = "==============================";

/* Draw life jauge */
ee_set_color(EE_DARKGRAY);
ee_putstr(4, 1, dots30);
caca_set_color(EE_DARKGRAY);
caca_putstr(4, 1, dots30);

if(g->p->life > MAX_LIFE * 7 / 10)
{
ee_set_color(EE_GREEN);
caca_set_color(EE_GREEN);
}
else if(g->p->life > MAX_LIFE * 3 / 10)
{
ee_set_color(EE_YELLOW);
caca_set_color(EE_YELLOW);
}
else
{
ee_set_color(EE_RED);
caca_set_color(EE_RED);
}

ee_putstr(4, 1, dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE);
caca_putstr(4, 1, dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE);

ee_set_color(EE_WHITE);
ee_putstr(1, 1, "L |");
ee_putstr(34, 1, "|");
caca_set_color(EE_WHITE);
caca_putstr(1, 1, "L |");
caca_putstr(34, 1, "|");

/* Draw weapon jauge */
ee_set_color(EE_DARKGRAY);
ee_putstr(42, 1, dots30 + 10);
caca_set_color(EE_DARKGRAY);
caca_putstr(42, 1, dots30 + 10);

if(g->p->special > MAX_SPECIAL * 9 / 10)
{
ee_set_color(EE_WHITE);
caca_set_color(EE_WHITE);
}
else if(g->p->special > MAX_SPECIAL * 3 / 10)
{
ee_set_color(EE_CYAN);
caca_set_color(EE_CYAN);
}
else
{
ee_set_color(EE_BLUE);
caca_set_color(EE_BLUE);
}

ee_putstr(42, 1, dashes30 + 10
caca_putstr(42, 1, dashes30 + 10
+ (MAX_SPECIAL - g->p->special) * 20 / MAX_SPECIAL);

ee_set_color(EE_WHITE);
ee_putstr(39, 1, "S |");
ee_putstr(62, 1, "|");
caca_set_color(EE_WHITE);
caca_putstr(39, 1, "S |");
caca_putstr(62, 1, "|");
}


+ 3
- 3
src/player.c Parādīt failu

@@ -26,7 +26,7 @@

#include "common.h"

struct ee_sprite *ship_sprite;
struct caca_sprite *ship_sprite;

/* Init tunnel */
player * create_player(game *g)
@@ -44,7 +44,7 @@ player * create_player(game *g)
p->life = MAX_LIFE;
p->dead = 0;

ship_sprite = ee_load_sprite("data/ship.txt");
ship_sprite = caca_load_sprite("data/ship.txt");

return p;
}
@@ -59,7 +59,7 @@ void draw_player(game *g, player *p)
if(p->dead)
return;

ee_draw_sprite(p->x, p->y, ship_sprite, 0);
caca_draw_sprite(p->x, p->y, ship_sprite, 0);
}

void update_player(game *g, player *p)


+ 11
- 11
src/starfield.c Parādīt failu

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

for(i = 0; i < STARS; i++)
{
s[i].x = ee_rand(0, g->w - 1);
s[i].y = ee_rand(0, g->h - 1);
s[i].z = ee_rand(1, 3);
s[i].c = ee_rand(0, 1) ? EE_LIGHTGRAY : EE_DARKGRAY;
s[i].ch = ee_rand(0, 1) ? '.' : '\'';
s[i].x = caca_rand(0, g->w - 1);
s[i].y = caca_rand(0, g->h - 1);
s[i].z = caca_rand(1, 3);
s[i].c = caca_rand(0, 1) ? EE_LIGHTGRAY : EE_DARKGRAY;
s[i].ch = caca_rand(0, 1) ? '.' : '\'';
}

return s;
@@ -55,8 +55,8 @@ void draw_starfield(game *g, starfield *s)
{
if(s[i].x >= 0)
{
ee_set_color(s[i].c);
ee_putchar(s[i].x, s[i].y, s[i].ch);
caca_set_color(s[i].c);
caca_putchar(s[i].x, s[i].y, s[i].ch);
}
}
}
@@ -69,11 +69,11 @@ void update_starfield(game *g, starfield *s)
{
if(s[i].x < 0)
{
s[i].x = ee_rand(0, g->w - 1);
s[i].x = caca_rand(0, g->w - 1);
s[i].y = 0;
s[i].z = ee_rand(1, 2);
s[i].c = ee_rand(0, 1) ? EE_LIGHTGRAY : EE_DARKGRAY;
s[i].ch = ee_rand(0, 1) ? '.' : '\'';
s[i].z = caca_rand(1, 2);
s[i].c = caca_rand(0, 1) ? EE_LIGHTGRAY : EE_DARKGRAY;
s[i].ch = caca_rand(0, 1) ? '.' : '\'';
}
else if(s[i].y < g->h-1)
{


+ 10
- 10
src/tunnel.c Parādīt failu

@@ -77,7 +77,7 @@ void draw_tunnel(game *g, tunnel *t)
int i, j;
char c;

ee_set_color(EE_GREEN);
caca_set_color(EE_GREEN);

/* Left border */
for(i = 0; i < g->h ; i++)
@@ -90,11 +90,11 @@ void draw_tunnel(game *g, tunnel *t)
else
c = (i == 0 || t->left[i] > t->left[i-1]) ? '\\' : '<';

ee_putchar(t->left[i] + 1, i, c);
caca_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_putchar(t->left[i] + j + 1, i, '_');
caca_putchar(t->left[i] + j + 1, i, '_');
}

/* Right border */
@@ -110,22 +110,22 @@ void draw_tunnel(game *g, tunnel *t)

if(i + 1 < g->h)
for(j = 1; j < t->right[i] - t->right[i+1]; j++)
ee_putchar(t->right[i+1] + j - 1, i, '_');
caca_putchar(t->right[i+1] + j - 1, i, '_');

ee_putchar(t->right[i] - 1, i, c);
caca_putchar(t->right[i] - 1, i, c);
}

ee_set_color(EE_RED);
caca_set_color(EE_RED);

/* Left concrete */
for(i = 0; i < g->h ; i++)
for(j = 0 ; j <= t->left[i]; j++)
ee_putchar(j, i, '#');
caca_putchar(j, i, '#');

/* Right concrete */
for(i = 0; i < g->h ; i++)
for(j = t->right[i] ; j < g->w ; j++)
ee_putchar(j, i, '#');
caca_putchar(j, i, '#');
}

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

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

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


+ 99
- 99
src/weapons.c Parādīt failu

@@ -31,8 +31,8 @@ static void draw_nuke(int x, int y, int frame);
static void draw_beam(int x, int y, int frame);
static void draw_fragbomb(int x, int y, int frame);

struct ee_sprite *bomb_sprite;
struct ee_sprite *fragbomb_sprite;
struct caca_sprite *bomb_sprite;
struct caca_sprite *fragbomb_sprite;

void init_weapons(game *g, weapons *wp)
{
@@ -43,8 +43,8 @@ void init_weapons(game *g, weapons *wp)
wp->type[i] = WEAPON_NONE;
}

bomb_sprite = ee_load_sprite("data/wpnbomb.txt");
fragbomb_sprite = ee_load_sprite("data/wpnfrag.txt");
bomb_sprite = caca_load_sprite("data/wpnbomb.txt");
fragbomb_sprite = caca_load_sprite("data/wpnfrag.txt");
}

void draw_weapons(game *g, weapons *wp)
@@ -56,25 +56,25 @@ void draw_weapons(game *g, weapons *wp)
switch(wp->type[i])
{
case WEAPON_LASER:
ee_set_color(EE_WHITE);
ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '|');
ee_set_color(EE_CYAN);
ee_putchar(wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
caca_set_color(EE_WHITE);
caca_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '|');
caca_set_color(EE_CYAN);
caca_putchar(wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
break;
case WEAPON_SEEKER:
ee_set_color(EE_CYAN);
ee_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
ee_putchar(wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
ee_set_color(EE_WHITE);
ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '@');
caca_set_color(EE_CYAN);
caca_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
caca_putchar(wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
caca_set_color(EE_WHITE);
caca_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '@');
break;
case WEAPON_BOMB:
ee_set_color(EE_DARKGRAY);
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, '.');
caca_set_color(EE_DARKGRAY);
caca_putchar((wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.');
caca_putchar((wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.');
caca_putchar((wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4, '.');
caca_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
caca_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:
@@ -169,7 +169,7 @@ void update_weapons(game *g, weapons *wp)
/* Normalize direction */
if(dx | dy)
{
unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy);
unsigned int norm = caca_sqrt(dx * dx + 4 * dy * dy);
dx = dx * 32 / norm;
dy = dy * 32 / norm;
}
@@ -181,7 +181,7 @@ void update_weapons(game *g, weapons *wp)
/* Normalize speed */
if(dx | dy)
{
unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy);
unsigned int norm = caca_sqrt(dx * dx + 4 * dy * dy);
wp->vx[i] = dx * 32 / norm;
wp->vy[i] = dy * 32 / norm;
}
@@ -333,16 +333,16 @@ static void draw_bomb(int x, int y, int vx, int vy)
}
}

ee_draw_sprite(x, y, bomb_sprite, frame);
caca_draw_sprite(x, y, bomb_sprite, frame);
}

static void draw_fragbomb(int x, int y, int frame)
{
/* Draw the head */
ee_draw_sprite(x, y, fragbomb_sprite, frame & 1);
caca_draw_sprite(x, y, fragbomb_sprite, frame & 1);

/* Draw the tail */
ee_draw_sprite(x, y, fragbomb_sprite, 2 + (frame % 4));
caca_draw_sprite(x, y, fragbomb_sprite, 2 + (frame % 4));
}

static void draw_beam(int x, int y, int frame)
@@ -353,86 +353,86 @@ static void draw_beam(int x, int y, int frame)
switch(frame)
{
case 24:
ee_set_color(EE_WHITE);
ee_putstr(x, y-3, "__");
ee_putchar(x-1, y-2, '\'');
ee_putchar(x+2, y-2, '`');
caca_set_color(EE_WHITE);
caca_putstr(x, y-3, "__");
caca_putchar(x-1, y-2, '\'');
caca_putchar(x+2, y-2, '`');
break;
case 23:
ee_set_color(EE_CYAN);
ee_putstr(x, y-3, "__");
ee_set_color(EE_WHITE);
ee_putstr(x-2, y-2, "-'");
ee_putstr(x+2, y-2, "`-");
caca_set_color(EE_CYAN);
caca_putstr(x, y-3, "__");
caca_set_color(EE_WHITE);
caca_putstr(x-2, y-2, "-'");
caca_putstr(x+2, y-2, "`-");
break;
case 22:
ee_set_color(EE_CYAN);
ee_putstr(x, y-3, "__");
ee_putchar(x-1, y-2, '\'');
ee_putchar(x+2, y-2, '`');
ee_set_color(EE_WHITE);
ee_putstr(x-3, y-2, ",-");
ee_putstr(x+3, y-2, "-.");
caca_set_color(EE_CYAN);
caca_putstr(x, y-3, "__");
caca_putchar(x-1, y-2, '\'');
caca_putchar(x+2, y-2, '`');
caca_set_color(EE_WHITE);
caca_putstr(x-3, y-2, ",-");
caca_putstr(x+3, y-2, "-.");
break;
case 21:
ee_set_color(EE_CYAN);
ee_putstr(x-1, y-3, "____");
ee_putchar(x-2, y-2, '\'');
ee_putchar(x+3, y-2, '`');
ee_set_color(EE_WHITE);
ee_putstr(x-4, y-2, ",-");
ee_putstr(x+4, y-2, "-.");
caca_set_color(EE_CYAN);
caca_putstr(x-1, y-3, "____");
caca_putchar(x-2, y-2, '\'');
caca_putchar(x+3, y-2, '`');
caca_set_color(EE_WHITE);
caca_putstr(x-4, y-2, ",-");
caca_putstr(x+4, y-2, "-.");
break;
case 20:
ee_set_color(EE_WHITE);
ee_putstr(x, y-3, "%%");
ee_putchar(x-4, y-2, ',');
ee_putchar(x+5, y-2, '.');
ee_set_color(EE_CYAN);
ee_putchar(x-1, y-3, ':');
ee_putchar(x+2, y-3, ':');
ee_putstr(x-3, y-2, "-'");
ee_putstr(x+3, y-2, "`-");
caca_set_color(EE_WHITE);
caca_putstr(x, y-3, "%%");
caca_putchar(x-4, y-2, ',');
caca_putchar(x+5, y-2, '.');
caca_set_color(EE_CYAN);
caca_putchar(x-1, y-3, ':');
caca_putchar(x+2, y-3, ':');
caca_putstr(x-3, y-2, "-'");
caca_putstr(x+3, y-2, "`-");
break;
case 19:
ee_set_color(EE_WHITE);
ee_putstr(x, y-4, "%%");
ee_putstr(x, y-3, "##");
ee_set_color(EE_CYAN);
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_set_color(EE_BLUE);
ee_putchar(x-2, y-3, ':');
ee_putchar(x+3, y-3, ':');
caca_set_color(EE_WHITE);
caca_putstr(x, y-4, "%%");
caca_putstr(x, y-3, "##");
caca_set_color(EE_CYAN);
caca_putchar(x-1, y-4, ':');
caca_putchar(x+2, y-4, ':');
caca_putchar(x-1, y-3, '%');
caca_putchar(x+2, y-3, '%');
caca_putstr(x-4, y-2, ",-'");
caca_putstr(x+3, y-2, "`-.");
caca_set_color(EE_BLUE);
caca_putchar(x-2, y-3, ':');
caca_putchar(x+3, y-3, ':');
break;
case 18:
default:
r = (18 - frame) * (18 - frame);
ee_set_color(EE_WHITE);
ee_putstr(x-1, y-5-r, ":%%:");
ee_putstr(x-1, y-4-r, "%##%");
ee_set_color(EE_CYAN);
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_set_color(EE_BLUE);
ee_putchar(x-3, y-2, ':');
ee_putchar(x+4, y-2, ':');
caca_set_color(EE_WHITE);
caca_putstr(x-1, y-5-r, ":%%:");
caca_putstr(x-1, y-4-r, "%##%");
caca_set_color(EE_CYAN);
caca_putchar(x-2, y-4-r, ':');
caca_putchar(x+3, y-4-r, ':');
caca_putchar(x-2, y-2, '\'');
caca_putchar(x+3, y-2, '`');
caca_set_color(EE_BLUE);
caca_putchar(x-3, y-2, ':');
caca_putchar(x+4, y-2, ':');
for(i = 0; i <= r; i++)
{
ee_set_color(EE_WHITE);
ee_putstr(x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
ee_set_color(EE_CYAN);
ee_putchar(x-2, y-3-i, '%');
ee_putchar(x+3, y-3-i, '%');
ee_set_color(EE_BLUE);
ee_putchar(x-3, y-3-i, ':');
ee_putchar(x+4, y-3-i, ':');
caca_set_color(EE_WHITE);
caca_putstr(x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
caca_set_color(EE_CYAN);
caca_putchar(x-2, y-3-i, '%');
caca_putchar(x+3, y-3-i, '%');
caca_set_color(EE_BLUE);
caca_putchar(x-3, y-3-i, ':');
caca_putchar(x+4, y-3-i, ':');
}
break;
}
@@ -443,16 +443,16 @@ static void draw_nuke(int x, int y, int frame)
int r = (29 - frame) * (29 - frame) / 8;

/* Lots of duplicate pixels, but we don't care */
ee_set_color(EE_BLUE);
ee_draw_ellipse(x, y, r, r / 2, ':');
ee_draw_ellipse(x, y, r + 1, r / 2, ':');
ee_draw_ellipse(x, y, r + 2, r / 2, ':');
ee_set_color(EE_CYAN);
ee_draw_ellipse(x, y, r + 2, r / 2 + 1, '%');
ee_draw_ellipse(x, y, r + 3, r / 2 + 1, '%');
ee_set_color(EE_WHITE);
ee_draw_ellipse(x, y, r + 3, r / 2 + 2, '#');
ee_draw_ellipse(x, y, r + 4, r / 2 + 2, '#');
ee_draw_ellipse(x, y, r + 4, r / 2 + 3, '#');
caca_set_color(EE_BLUE);
caca_draw_ellipse(x, y, r, r / 2, ':');
caca_draw_ellipse(x, y, r + 1, r / 2, ':');
caca_draw_ellipse(x, y, r + 2, r / 2, ':');
caca_set_color(EE_CYAN);
caca_draw_ellipse(x, y, r + 2, r / 2 + 1, '%');
caca_draw_ellipse(x, y, r + 3, r / 2 + 1, '%');
caca_set_color(EE_WHITE);
caca_draw_ellipse(x, y, r + 3, r / 2 + 2, '#');
caca_draw_ellipse(x, y, r + 4, r / 2 + 2, '#');
caca_draw_ellipse(x, y, r + 4, r / 2 + 3, '#');
}


+ 4
- 4
test/Makefile.am Parādīt failu

@@ -1,8 +1,8 @@
###############################################################################
# Automake targets and declarations for libee tests
# Automake targets and declarations for libcaca tests
###############################################################################

AM_CPPFLAGS = -I$(top_srcdir)/libee
AM_CPPFLAGS = -I$(top_srcdir)/libcaca

if USE_SLANG
LDFLAGS_slang = -lslang
@@ -14,10 +14,10 @@ endif
bin_PROGRAMS = demo spritedit

demo_SOURCES = demo.c
demo_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
demo_LDADD = ../libcaca/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
demo_CFLAGS = `pkg-config --cflags gtk+-2.0`
demo_LDFLAGS = `pkg-config --libs gtk+-2.0`

spritedit_SOURCES = spritedit.c
spritedit_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
spritedit_LDADD = ../libcaca/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm


+ 151
- 151
test/demo.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* demo demo using libee
* demo demo using libcaca
* Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -29,7 +29,7 @@
#include <gdk/gdk.h>
#include <gdk/gdkpixbuf.h>

#include "ee.h"
#include "caca.h"

static void display_menu(void);

@@ -46,7 +46,7 @@ static void demo_blit(void);

int bounds = 0;
int outline = 0;
struct ee_sprite *sprite = NULL;
struct caca_sprite *sprite = NULL;

GdkPixbuf *pixbuf;
char *pixels;
@@ -57,15 +57,15 @@ int main(int argc, char **argv)
void (*demo)(void) = NULL;
int quit = 0;

if(ee_init())
if(caca_init())
{
return 1;
}

ee_set_delay(40000);
caca_set_delay(40000);

/* Initialize data */
sprite = ee_load_sprite("data/barboss.txt");
sprite = caca_load_sprite("data/barboss.txt");

gdk_init (&argc, &argv);
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gally4.jpeg", NULL);
@@ -82,17 +82,17 @@ fprintf(stderr, "w %i, h %i, stride %i\n", bufx, bufy, bufpitch);

/* Main menu */
display_menu();
ee_refresh();
caca_refresh();

/* Go ! */
while(!quit)
{
char key = ee_get_key();
char key = caca_get_key();

if(key && demo)
{
display_menu();
ee_refresh();
caca_refresh();
demo = NULL;
}
else if(key)
@@ -148,65 +148,65 @@ fprintf(stderr, "w %i, h %i, stride %i\n", bufx, bufy, bufpitch);
}

if(demo)
ee_clear();
caca_clear();

key = ee_get_key();
key = caca_get_key();
if(key)
goto handle_key;

ee_refresh();
caca_refresh();
}

if(demo)
{
demo();

ee_set_color(EE_WHITE);
ee_draw_thin_box(1, 1, ee_get_width() - 2, ee_get_height() - 2);
ee_printf(4, 1, "[%i.%i fps]----",
1000000 / ee_get_rendertime(),
(10000000 / ee_get_rendertime()) % 10);
ee_refresh();
caca_set_color(EE_WHITE);
caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2);
caca_printf(4, 1, "[%i.%i fps]----",
1000000 / caca_get_rendertime(),
(10000000 / caca_get_rendertime()) % 10);
caca_refresh();
}
}

/* Clean up */
ee_free_sprite(sprite);
ee_end();
caca_free_sprite(sprite);
caca_end();

return 0;
}

static void display_menu(void)
{
int xo = ee_get_width() - 2;
int yo = ee_get_height() - 2;
ee_clear();
ee_set_color(EE_WHITE);
ee_draw_thin_box(1, 1, xo, yo);
ee_putstr((xo - strlen("libee demo")) / 2, 3, "libee demo");
ee_putstr((xo - strlen("============")) / 2, 4, "============");
ee_putstr(4, 6, "demos:");
ee_putstr(4, 7, "'f': full");
ee_putstr(4, 8, "'1': dots");
ee_putstr(4, 9, "'2': lines");
ee_putstr(4, 10, "'3': boxes");
ee_putstr(4, 11, "'4': triangles");
ee_putstr(4, 12, "'5': ellipses");
ee_putstr(4, 13, "'s': sprites");
ee_putstr(4, 14, "'c': color");
ee_putstr(4, 15, "'i': image blit");
ee_putstr(4, 17, "settings:");
ee_printf(4, 18, "'o': outline: %s",
int xo = caca_get_width() - 2;
int yo = caca_get_height() - 2;
caca_clear();
caca_set_color(EE_WHITE);
caca_draw_thin_box(1, 1, xo, yo);
caca_putstr((xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
caca_putstr((xo - strlen("==============")) / 2, 4, "==============");
caca_putstr(4, 6, "demos:");
caca_putstr(4, 7, "'f': full");
caca_putstr(4, 8, "'1': dots");
caca_putstr(4, 9, "'2': lines");
caca_putstr(4, 10, "'3': boxes");
caca_putstr(4, 11, "'4': triangles");
caca_putstr(4, 12, "'5': ellipses");
caca_putstr(4, 13, "'s': sprites");
caca_putstr(4, 14, "'c': color");
caca_putstr(4, 15, "'i': image blit");
caca_putstr(4, 17, "settings:");
caca_printf(4, 18, "'o': outline: %s",
outline == 0 ? "none" : outline == 1 ? "solid" : "thin");
ee_printf(4, 19, "'b': drawing boundaries: %s",
caca_printf(4, 19, "'b': drawing boundaries: %s",
bounds == 0 ? "screen" : "infinite");

ee_putstr(4, yo - 2, "'q': quit");
caca_putstr(4, yo - 2, "'q': quit");
}

static void demo_all(void)
@@ -217,106 +217,106 @@ static void demo_all(void)

i++;

ee_clear();
caca_clear();

/* Draw the sun */
ee_set_color(EE_YELLOW);
xo = ee_get_width() / 4;
yo = ee_get_height() / 4 + 5 * sin(0.03*i);
caca_set_color(EE_YELLOW);
xo = caca_get_width() / 4;
yo = caca_get_height() / 4 + 5 * sin(0.03*i);

for(j = 0; j < 16; j++)
{
xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
ee_draw_thin_line(xo, yo, xa, ya);
caca_draw_thin_line(xo, yo, xa, ya);
}

j = 15 + sin(0.03*i) * 8;
ee_set_color(EE_WHITE);
ee_fill_ellipse(xo, yo, j, j / 2, '#');
ee_set_color(EE_YELLOW);
ee_draw_ellipse(xo, yo, j, j / 2, '#');
caca_set_color(EE_WHITE);
caca_fill_ellipse(xo, yo, j, j / 2, '#');
caca_set_color(EE_YELLOW);
caca_draw_ellipse(xo, yo, j, j / 2, '#');

/* Draw the pyramid */
xo = ee_get_width() * 5 / 8;
xo = caca_get_width() * 5 / 8;
yo = 2;

xa = ee_get_width() / 8 + sin(0.03*i) * 5;
ya = ee_get_height() / 2 + cos(0.03*i) * 5;
xa = caca_get_width() / 8 + sin(0.03*i) * 5;
ya = caca_get_height() / 2 + cos(0.03*i) * 5;

xb = ee_get_width() - 10 - cos(0.02*i) * 10;
yb = ee_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;
xb = caca_get_width() - 10 - cos(0.02*i) * 10;
yb = caca_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;

xc = ee_get_width() / 4 - sin(0.02*i) * 5;
yc = ee_get_height() * 3 / 4 + cos(0.02*i) * 5;
xc = caca_get_width() / 4 - sin(0.02*i) * 5;
yc = caca_get_height() * 3 / 4 + cos(0.02*i) * 5;

ee_set_color(EE_GREEN);
ee_fill_triangle(xo, yo, xb, yb, xa, ya, '%');
ee_set_color(EE_YELLOW);
ee_draw_thin_triangle(xo, yo, xb, yb, xa, ya);
caca_set_color(EE_GREEN);
caca_fill_triangle(xo, yo, xb, yb, xa, ya, '%');
caca_set_color(EE_YELLOW);
caca_draw_thin_triangle(xo, yo, xb, yb, xa, ya);

ee_set_color(EE_RED);
ee_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
ee_set_color(EE_YELLOW);
ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
caca_set_color(EE_RED);
caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
caca_set_color(EE_YELLOW);
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);

ee_set_color(EE_BLUE);
ee_fill_triangle(xo, yo, xb, yb, xc, yc, '%');
ee_set_color(EE_YELLOW);
ee_draw_thin_triangle(xo, yo, xb, yb, xc, yc);
caca_set_color(EE_BLUE);
caca_fill_triangle(xo, yo, xb, yb, xc, yc, '%');
caca_set_color(EE_YELLOW);
caca_draw_thin_triangle(xo, yo, xb, yb, xc, yc);

/* Draw a background triangle */
xa = 2;
ya = 2;

xb = ee_get_width() - 3;
yb = ee_get_height() / 2;
xb = caca_get_width() - 3;
yb = caca_get_height() / 2;

xc = ee_get_width() / 3;
yc = ee_get_height() - 3;
xc = caca_get_width() / 3;
yc = caca_get_height() - 3;

ee_set_color(EE_CYAN);
ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
caca_set_color(EE_CYAN);
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);

xo = ee_get_width() / 2 + cos(0.027*i) * ee_get_width() / 3;
yo = ee_get_height() / 2 - sin(0.027*i) * ee_get_height() / 2;
xo = caca_get_width() / 2 + cos(0.027*i) * caca_get_width() / 3;
yo = caca_get_height() / 2 - sin(0.027*i) * caca_get_height() / 2;

ee_draw_thin_line(xa, ya, xo, yo);
ee_draw_thin_line(xb, yb, xo, yo);
ee_draw_thin_line(xc, yc, xo, yo);
caca_draw_thin_line(xa, ya, xo, yo);
caca_draw_thin_line(xb, yb, xo, yo);
caca_draw_thin_line(xc, yc, xo, yo);

/* Draw a sprite on the pyramid */
ee_draw_sprite(xo, yo, sprite, 0);
caca_draw_sprite(xo, yo, sprite, 0);

/* Draw a trail behind the foreground sprite */
for(j = i - 60; j < i; j++)
{
int delta = ee_rand(-5, 5);
ee_set_color(ee_rand(0, 15));
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),
int delta = caca_rand(-5, 5);
caca_set_color(caca_rand(0, 15));
caca_putchar(caca_get_width() / 2
+ cos(0.02*j) * (delta + caca_get_width() / 4),
caca_get_height() / 2
+ sin(0.02*j) * (delta + caca_get_height() / 3),
'#');
}

/* Draw foreground sprite */
ee_draw_sprite(ee_get_width() / 2 + cos(0.02*i) * ee_get_width() / 4,
ee_get_height() / 2 + sin(0.02*i) * ee_get_height() / 3,
caca_draw_sprite(caca_get_width() / 2 + cos(0.02*i) * caca_get_width() / 4,
caca_get_height() / 2 + sin(0.02*i) * caca_get_height() / 3,
sprite, 0);
}

static void demo_dots(void)
{
int xmax = ee_get_width() - 1;
int ymax = ee_get_height() - 1;
int xmax = caca_get_width() - 1;
int ymax = caca_get_height() - 1;
int i;

for(i = 1000; i--;)
{
/* Putpixel */
ee_set_color(ee_rand(0, 15));
ee_putchar(ee_rand(0, xmax), ee_rand(0, ymax), '#');
caca_set_color(caca_rand(0, 15));
caca_putchar(caca_rand(0, xmax), caca_rand(0, ymax), '#');
}
}

@@ -325,138 +325,138 @@ static void demo_color(void)
int i;
char buf[BUFSIZ];

ee_clear();
caca_clear();
for(i = 0; i < 16; i++)
{
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, ee_get_color_name(i));
ee_set_color(EE_WHITE);
ee_putstr(4, i + 3, buf);
ee_set_color(i);
ee_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------");
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, caca_get_color_name(i));
caca_set_color(EE_WHITE);
caca_putstr(4, i + 3, buf);
caca_set_color(i);
caca_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------");
}
}

static void demo_lines(void)
{
int w = ee_get_width();
int h = ee_get_height();
int w = caca_get_width();
int h = caca_get_height();
int xa, ya, xb, yb;

if(bounds)
{
xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
}
else
{
xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
xa = caca_rand(0, w - 1); ya = caca_rand(0, h - 1);
xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
}

ee_set_color(ee_rand(0, 15));
caca_set_color(caca_rand(0, 15));
if(outline > 1)
ee_draw_thin_line(xa, ya, xb, yb);
caca_draw_thin_line(xa, ya, xb, yb);
else
ee_draw_line(xa, ya, xb, yb, '#');
caca_draw_line(xa, ya, xb, yb, '#');
}

static void demo_boxes(void)
{
int w = ee_get_width();
int h = ee_get_height();
int w = caca_get_width();
int h = caca_get_height();
int xa, ya, xb, yb;

if(bounds)
{
xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
}
else
{
xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
xa = caca_rand(0, w - 1); ya = caca_rand(0, h - 1);
xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
}

ee_set_color(ee_rand(0, 15));
ee_fill_box(xa, ya, xb, yb, '#');
caca_set_color(caca_rand(0, 15));
caca_fill_box(xa, ya, xb, yb, '#');

ee_set_color(ee_rand(0, 15));
caca_set_color(caca_rand(0, 15));
if(outline == 2)
ee_draw_thin_box(xa, ya, xb, yb);
caca_draw_thin_box(xa, ya, xb, yb);
else if(outline == 1)
ee_draw_box(xa, ya, xb, yb, '#');
caca_draw_box(xa, ya, xb, yb, '#');
}

static void demo_ellipses(void)
{
int w = ee_get_width();
int h = ee_get_height();
int w = caca_get_width();
int h = caca_get_height();
int x, y, a, b;

if(bounds)
{
x = ee_rand(- w, 2 * w); y = ee_rand(- h, 2 * h);
a = ee_rand(0, w); b = ee_rand(0, h);
x = caca_rand(- w, 2 * w); y = caca_rand(- h, 2 * h);
a = caca_rand(0, w); b = caca_rand(0, h);
}
else
{
do
{
x = ee_rand(0, w); y = ee_rand(0, h);
a = ee_rand(0, w); b = ee_rand(0, h);
x = caca_rand(0, w); y = caca_rand(0, h);
a = caca_rand(0, w); b = caca_rand(0, h);

} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
}

ee_set_color(ee_rand(0, 15));
ee_fill_ellipse(x, y, a, b, '#');
caca_set_color(caca_rand(0, 15));
caca_fill_ellipse(x, y, a, b, '#');

ee_set_color(ee_rand(0, 15));
caca_set_color(caca_rand(0, 15));
if(outline == 2)
ee_draw_thin_ellipse(x, y, a, b);
caca_draw_thin_ellipse(x, y, a, b);
else if(outline == 1)
ee_draw_ellipse(x, y, a, b, '#');
caca_draw_ellipse(x, y, a, b, '#');
}

static void demo_triangles(void)
{
int w = ee_get_width();
int h = ee_get_height();
int w = caca_get_width();
int h = caca_get_height();
int xa, ya, xb, yb, xc, yc;

if(bounds)
{
xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
xc = ee_rand(- w, 2 * w); yc = ee_rand(- h, 2 * h);
xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
xc = caca_rand(- w, 2 * w); yc = caca_rand(- h, 2 * h);
}
else
{

xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
xc = ee_rand(0, w - 1); yc = ee_rand(0, h - 1);
xa = caca_rand(0, w - 1); ya = caca_rand(0, h - 1);
xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
xc = caca_rand(0, w - 1); yc = caca_rand(0, h - 1);
}

ee_set_color(ee_rand(0, 15));
ee_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
caca_set_color(caca_rand(0, 15));
caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#');

ee_set_color(ee_rand(0, 15));
caca_set_color(caca_rand(0, 15));
if(outline == 2)
ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
else if(outline == 1)
ee_draw_triangle(xa, ya, xb, yb, xc, yc, '#');
caca_draw_triangle(xa, ya, xb, yb, xc, yc, '#');
}

static void demo_sprites(void)
{
ee_draw_sprite(ee_rand(0, ee_get_width() - 1),
ee_rand(0, ee_get_height() - 1), sprite, 0);
caca_draw_sprite(caca_rand(0, caca_get_width() - 1),
caca_rand(0, caca_get_height() - 1), sprite, 0);
}

static void demo_blit(void)
{
ee_set_color(EE_LIGHTGRAY);
ee_blit(6, 4, ee_get_width() - 6, ee_get_height() - 4, pixels, bufx, bufy);
caca_set_color(EE_LIGHTGRAY);
caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4, pixels, bufx, bufy);
}


+ 30
- 30
test/spritedit.c Parādīt failu

@@ -1,5 +1,5 @@
/*
* spritedit sprite editor using libee
* spritedit sprite editor using libcaca
* Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
@@ -24,12 +24,12 @@

#include <stdio.h>

#include "ee.h"
#include "caca.h"

int main(int argc, char **argv)
{
int quit = 0;
struct ee_sprite *sprite;
struct caca_sprite *sprite;
int frame = 0;

if(argc < 2)
@@ -38,14 +38,14 @@ int main(int argc, char **argv)
return 1;
}

if(ee_init())
if(caca_init())
return 1;

sprite = ee_load_sprite(argv[1]);
sprite = caca_load_sprite(argv[1]);

if(!sprite)
{
ee_end();
caca_end();
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
return 1;
}
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
int xa, ya, xb, yb;
char buf[BUFSIZ];

switch(ee_get_key())
switch(caca_get_key())
{
case 0:
break;
@@ -68,47 +68,47 @@ int main(int argc, char **argv)
frame--;
break;
case '+':
if(frame < ee_get_sprite_frames(sprite) - 1)
if(frame < caca_get_sprite_frames(sprite) - 1)
frame++;
break;
}

ee_clear();
caca_clear();

ee_set_color(EE_WHITE);
ee_draw_thin_box(0, 0, ee_get_width() - 1, ee_get_height() - 1);
caca_set_color(EE_WHITE);
caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);

ee_putstr(3, 0, "[ Sprite editor for libee ]");
caca_putstr(3, 0, "[ Sprite editor for libcaca ]");

sprintf(buf, "sprite `%s'", argv[1]);
ee_putstr(3, 2, buf);
sprintf(buf, "frame %i/%i", frame, ee_get_sprite_frames(sprite) - 1);
ee_putstr(3, 3, buf);
caca_putstr(3, 2, buf);
sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1);
caca_putstr(3, 3, buf);

/* Crosshair */
ee_draw_thin_line(57, 2, 57, 18);
ee_draw_thin_line(37, 10, 77, 10);
ee_putchar(57, 10, '+');
caca_draw_thin_line(57, 2, 57, 18);
caca_draw_thin_line(37, 10, 77, 10);
caca_putchar(57, 10, '+');

/* Boxed sprite */
xa = -1 - ee_get_sprite_dx(sprite, frame);
ya = -1 - ee_get_sprite_dy(sprite, frame);
xb = xa + 1 + ee_get_sprite_width(sprite, frame);
yb = ya + 1 + ee_get_sprite_height(sprite, frame);
ee_set_color(EE_BLACK);
ee_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
ee_set_color(EE_WHITE);
ee_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
ee_draw_sprite(57, 10, sprite, frame);
xa = -1 - caca_get_sprite_dx(sprite, frame);
ya = -1 - caca_get_sprite_dy(sprite, frame);
xb = xa + 1 + caca_get_sprite_width(sprite, frame);
yb = ya + 1 + caca_get_sprite_height(sprite, frame);
caca_set_color(EE_BLACK);
caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
caca_set_color(EE_WHITE);
caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
caca_draw_sprite(57, 10, sprite, frame);

/* Free sprite */
ee_draw_sprite(20, 10, sprite, frame);
caca_draw_sprite(20, 10, sprite, frame);

ee_refresh();
caca_refresh();
}

/* Clean up */
ee_end();
caca_end();

return 0;
}


Notiek ielāde…
Atcelt
Saglabāt