Parcourir la source

* libee/ee.h:

+ Added ee_color_names[] containing our 16 color names.
  * libee/ee.c:
    + Extended our color set to the full 16 instead of 10.
    + Precalculate ncurses attributes.
  * libee/graphics.c:
    + Clip color value in ee_set_color().
    + Clip characters in ee_putchar().
    + Partially clip characters in ee_putstr(), overflows aren't checked yet.
  * libee/ee_internals.h:
    + New file to share extern variables within libee.

  * test/demo.c:
    + Added a simple demo_color() to output all colors.
    + Replaced four ee_draw_line() with ee_draw_thin_box().
    + Replaced x1, y1, x2 etc. with xa, ya, xb etc. because <math.h> already
      defines y1.
    + Randomized colours from 0 to 15 instead of 1 to 10.

  * src/Makefiles.am:
    + Added -lm to the ttyvaders linking flags because of the intro.

  * README BUGS TODO:
    + Updated.
tags/v0.99.beta14
Sam Hocevar sam il y a 21 ans
Parent
révision
92f20d35aa
20 fichiers modifiés avec 339 ajouts et 234 suppressions
  1. +8
    -0
      BUGS
  2. +1
    -1
      Makefile.am
  3. +23
    -24
      README
  4. +27
    -24
      TODO
  5. +1
    -0
      libee/Makefile.am
  6. +1
    -6
      libee/box.c
  7. +1
    -6
      libee/conic.c
  8. +85
    -22
      libee/ee.c
  9. +21
    -10
      libee/ee.h
  10. +34
    -0
      libee/ee_internals.h
  11. +37
    -35
      libee/graphics.c
  12. +10
    -16
      libee/io.c
  13. +1
    -6
      libee/line.c
  14. +1
    -6
      libee/math.c
  15. +1
    -6
      libee/sprite.c
  16. +1
    -6
      libee/triangle.c
  17. +1
    -1
      src/Makefile.am
  18. +2
    -2
      src/overlay.c
  19. +1
    -1
      src/weapons.c
  20. +82
    -62
      test/demo.c

+ 8
- 0
BUGS Voir le fichier

@@ -0,0 +1,8 @@
$Id$

Video rendering

o Slang's and ncurses' hashmap scrolling optimization code cause the
screen to occasionally flicker because it tries to optimize the
vertical scrolling.


+ 1
- 1
Makefile.am Voir le fichier

@@ -5,6 +5,6 @@
SUBDIRS = libee test src
DIST_SUBDIRS = $(SUBDIRS) autotools data debian

EXTRA_DIST = doc/shapes.txt bootstrap
EXTRA_DIST = BUGS doc/shapes.txt bootstrap
AUTOMAKE_OPTIONS = foreign dist-bzip2


+ 23
- 24
README Voir le fichier

@@ -1,47 +1,46 @@
$Id$

Building ttyvaders
==================

Run configure then make. Configure flags are:
o Run configure then make. Useful configure flags are:

--enable-slang: use the SLang library (default)
--enable-ncurses: use the ncurses library
--enable-conio: use MS-DOS conio.h
--enable-slang: use the SLang library (default)
--enable-ncurses: use the ncurses library
--enable-conio: use MS-DOS conio.h

Cross-compilation example:
./configure --enable-conio --host=i386-pc-msdosdjgpp
o Cross-compilation example:
./configure --enable-conio --host=i386-pc-msdosdjgpp


History of textmode games
=========================

http://www.textmodegames.com/
o http://www.textmodegames.com/


Other terminal-based games
==========================

* moon-buggy: http://www.mathematik.uni-kl.de/~wwwstoch/voss/comp/moon-buggy.html
extremely simple, extremely addictive
o moon-buggy: extremely simple, extremely addictive
http://www.mathematik.uni-kl.de/~wwwstoch/voss/comp/moon-buggy.html

* 0verkill: http://artax.karlin.mff.cuni.cz/~brain/0verkill/
o 0verkill: http://artax.karlin.mff.cuni.cz/~brain/0verkill/

* nInvaders: http://dettus.dyndns.org/ninvaders/
real space invaders clone
o nInvaders: http://dettus.dyndns.org/ninvaders/
real space invaders clone

* Stardork: http://www.seekrut.com/rk/stardork.html
more strategy than arcade
o Stardork: http://www.seekrut.com/rk/stardork.html
more strategy than arcade

* Nethack: http://www.nethack.org/
o Nethack: http://www.nethack.org/

* Tetrinet: http://www.secret.com.au/games/tetrinet/
o Tetrinet: http://www.secret.com.au/games/tetrinet/

* MyMan: http://geocities.com/bsittler/
pacman clone
o MyMan: http://geocities.com/bsittler/
pacman clone

* Tornado: http://home.kcore.de/~kiza/linux/tornado/
o Tornado: http://home.kcore.de/~kiza/linux/tornado/

* David's Perl games: http://davidsperlgames.sourceforge.net/
o David's Perl games: http://davidsperlgames.sourceforge.net/

* ascii-invaders: http://www.ip9.org/munro/invaders/index.html
o ascii-invaders: http://www.ip9.org/munro/invaders/index.html


+ 27
- 24
TODO Voir le fichier

@@ -1,44 +1,47 @@
Things to do
$Id$

* let the ship pick up bonuses
TODO for libee

DONE 23 Dec 2002: handle life
o Sprite library

* alien swarms, programmed behaviour
o Clip graphics

* sprite library
o Fix the thin ellipse rendering

DONE 23 Dec 2002: mega ball
o Write a Linux console output for the drawing library
See also BUGS as to why it's very slow in console mode

* spiral weapon (vertical sine)
o DONE 12 Nov 2003: Port to conio.h

DONE 23 Dec 2002: fragmentation bomb (merge with mega-ball?)

* stick aliens to tunnel
TODO for ttyvaders

* change tunnel colour
o Let the ship pick up bonuses

DONE Dec 23 2002: fill holes in the tunnel when |step| > 2
o Alien swarms, programmed behaviour

DONE Dec 18 2002: draw a 3rd alien type
o Spiral weapon (vertical sine)

* draw bosses
o Stick aliens to tunnel

* port to conio.h
o Change tunnel colour

* clip graphics
o Draw bosses

* promote precision for all coordinates except screen
o Promote precision for all coordinates except screen

DONE Dec 19 2002: tunnel sometimes doesn't get drawn on the left
o Animate the ship

* write a generic drawing library with automatic clipping
o The nuke should break the tunnel
Or at least a bit

* write a linux console output for the drawing library
o The laser stays alive when the ship explodes

* animate the ship

* the nuke should break the tunnel

* the laser stays alive when the ship explodes
o DONE 12 Nov 2003: Write a generic drawing library with automatic clipping
o DONE 23 Dec 2002: Handle life
o DONE 23 Dec 2002: Mega ball
o DONE 23 Dec 2002: Fragmentation bomb (merge with mega-ball?)
o DONE 23 Dec 2002: Fill holes in the tunnel when |step| > 2
o DONE 19 Dec 2002: Tunnel sometimes doesn't get drawn on the left
o DONE 18 Dec 2002: Draw a 3rd alien type


+ 1
- 0
libee/Makefile.am Voir le fichier

@@ -6,6 +6,7 @@ lib_LIBRARIES = libee.a
libee_a_SOURCES = \
ee.c \
ee.h \
ee_internals.h \
graphics.c \
io.c \
math.c \


+ 1
- 6
libee/box.c Voir le fichier

@@ -22,15 +22,10 @@

#include "config.h"

#ifdef USE_SLANG
# include <slang.h>
#elif USE_NCURSES
# include <curses.h>
#endif

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"

void ee_draw_box(int x1, int y1, int x2, int y2, char c)
{


+ 1
- 6
libee/conic.c Voir le fichier

@@ -22,12 +22,6 @@

#include "config.h"

#ifdef USE_SLANG
# include <slang.h>
#elif USE_NCURSES
# include <curses.h>
#endif

#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#else
@@ -37,6 +31,7 @@ typedef unsigned char uint8_t;
#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"

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



+ 85
- 22
libee/ee.c Voir le fichier

@@ -43,18 +43,63 @@
#include <time.h>

#include "ee.h"
#include "ee_internals.h"

/* Global array with color names */
char *ee_color_names[16] =
{
"black",
"blue",
"green",
"cyan",
"red",
"magenta",
"brown",
"lightgray",
"darkgray",
"lightblue",
"lightgreen",
"lightcyan",
"lightred",
"lightmagenta",
"yellow",
"white",
};

static int _ee_delay;

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

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

int ee_init(void)
{
#if defined(USE_SLANG)
static char * colors[] = { "black", "green", "yellow", "white",
"red", "gray", "lightgray", "blue", "cyan", "magenta", NULL };
static char *slang_colors[16] =
{
"black",
"blue",
"green",
"cyan",
"red",
"magenta",
"brown",
"lightgray",
"gray",
"brightblue",
"brightgreen",
"brightcyan",
"brightred",
"brightmagenta",
"yellow",
"white",
};

int i;

/* Initialize slang library */
@@ -81,13 +126,12 @@ int ee_init(void)
SLtt_set_cursor_visibility(0);
SLsmg_refresh();

for(i = 0; colors[i]; i++)
{
SLtt_set_color(i + 1, NULL, colors[i], "black");
}
for(i = 0; i < 16; i++)
SLtt_set_color(i + 1, NULL, slang_colors[i], "black");

#elif defined(USE_NCURSES)
/* Initialize ncurses library */
int i;

initscr();
keypad(stdscr, TRUE);
nonl();
@@ -98,24 +142,40 @@ int ee_init(void)

start_color();

init_pair(EE_BLACK, COLOR_BLACK, COLOR_BLACK);
init_pair(EE_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(EE_YELLOW, COLOR_YELLOW, COLOR_BLACK);
init_pair(EE_WHITE, COLOR_WHITE, COLOR_BLACK);
init_pair(EE_RED, COLOR_RED, COLOR_BLACK);
init_pair(EE_GRAY, COLOR_WHITE, COLOR_BLACK); // XXX
init_pair(EE_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK); // XXX
init_pair(EE_BLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(1 + EE_BLACK, COLOR_BLACK, COLOR_BLACK);
init_pair(1 + EE_BLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(1 + EE_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(1 + EE_CYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(1 + EE_RED, COLOR_RED, COLOR_BLACK);
init_pair(1 + EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(1 + EE_BROWN, COLOR_YELLOW, COLOR_BLACK);
init_pair(1 + EE_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK);
init_pair(1 + EE_DARKGRAY, COLOR_BLACK, COLOR_BLACK);
init_pair(1 + EE_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(1 + EE_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(1 + EE_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(1 + EE_LIGHTRED, COLOR_RED, COLOR_BLACK);
init_pair(1 + EE_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(1 + EE_YELLOW, COLOR_YELLOW, COLOR_BLACK);
init_pair(1 + EE_WHITE, COLOR_WHITE, COLOR_BLACK);

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

#elif defined(USE_CONIO)
_wscroll = 0;
_setcursortype(_NOCURSOR);
clrscr();
gettextinfo(&ti);
_screen_buffer = malloc(ee_get_width() * ee_get_height() * 2);
ScreenRetrieve(_screen_buffer);
_ee_screen = malloc(2 * ti.screenwidth * ti.screenheight);
# if defined(SCREENUPDATE_IN_PC_H)
ScreenRetrieve(_ee_screen);
# else
/* FIXME */
# endif

#endif
_ee_delay = 0;
@@ -187,7 +247,11 @@ void ee_refresh(void)
#elif defined(USE_NCURSES)
refresh();
#elif defined(USE_CONIO)
ScreenUpdate(_screen_buffer);
# if defined(SCREENUPDATE_IN_PC_H)
ScreenUpdate(_ee_screen);
# else
/* FIXME */
# endif
#endif

#if !defined(USE_CONIO)
@@ -214,7 +278,6 @@ void ee_end(void)
curs_set(1);
endwin();
#elif defined(USE_CONIO)
ScreenUpdate(_screen_buffer);
_wscroll = 1;
textcolor((enum COLORS)WHITE);
textbackground((enum COLORS)BLACK);


+ 21
- 10
libee/ee.h Voir le fichier

@@ -31,16 +31,27 @@ extern "C"
/*
* Colors
*/
#define EE_BLACK 1
#define EE_GREEN 2
#define EE_YELLOW 3
#define EE_WHITE 4
#define EE_RED 5
#define EE_GRAY 6
#define EE_LIGHTGRAY 7
#define EE_BLUE 8
#define EE_CYAN 9
#define EE_MAGENTA 10
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
};

extern char *ee_color_names[16];

/*
* Types


+ 34
- 0
libee/ee_internals.h Voir le fichier

@@ -0,0 +1,34 @@
/*
* 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_INTERNALS_H__
#define __EE_INTERNALS_H__

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

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

#endif /* __EE_INTERNALS_H__ */

+ 37
- 35
libee/graphics.c Voir le fichier

@@ -36,34 +36,22 @@
#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"

static int ee_color = 0;
#if defined(USE_CONIO)
static enum COLORS dos_colors[] = {
0,
BLACK,
GREEN,
YELLOW,
WHITE,
RED,
DARKGRAY,
LIGHTGRAY,
BLUE,
CYAN,
MAGENTA
};
#endif

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

ee_color = color;
#if defined(USE_SLANG)
SLsmg_set_color(color);
SLsmg_set_color(color + 1);
#elif defined(USE_NCURSES)
attrset(COLOR_PAIR(color));
attrset(_ee_attr[color]);
#elif defined(USE_CONIO)
if(color >= 1 && color <= 10)
textcolor(dos_colors[color]);
textcolor(color);
#endif
}

@@ -72,44 +60,57 @@ int ee_get_color(void)
return ee_color;
}

extern char *_screen_buffer;

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

#if defined(USE_SLANG)
SLsmg_gotorc(y,x);
SLsmg_gotorc(y, x);
SLsmg_write_char(c);
#elif defined(USE_NCURSES)
move(y,x);
move(y, x);
addch(c);
#elif defined(USE_CONIO)
if(x<0 || x>=ee_get_width() || y<0 || y>=ee_get_height())
return;
_screen_buffer[2 * (x + y * ee_get_width())] = c;
_screen_buffer[2 * (x + y * ee_get_width()) + 1] = dos_colors[ee_color];
// gotoxy(x+1,y+1);
_ee_screen[2 * (x + y * ee_get_width())] = c;
_ee_screen[2 * (x + y * ee_get_width()) + 1] = ee_color;
// gotoxy(x + 1, y + 1);
// putch(c);
#endif
}

void ee_putstr(int x, int y, char *s)
{
if(y<0 || y>=ee_get_height())
int len;

if(y < 0 || y >= ee_get_height())
return;

len = strlen(s);

if(x < 0)
{
len -= -x;
if(len < 0)
return;
s += -x;
x = 0;
}

#if defined(USE_SLANG)
SLsmg_gotorc(y,x);
SLsmg_gotorc(y, x);
SLsmg_write_string(s);
#elif defined(USE_NCURSES)
move(y,x);
move(y, x);
addstr(s);
#elif defined(USE_CONIO)
char *buf = _screen_buffer + 2 * (x + y * ee_get_width());
char *buf = _ee_screen + 2 * (x + y * ee_get_width());
while(*s)
{
*buf++ = *s++;
*buf++ = dos_colors[ee_color];
*buf++ = ee_color;
}
// gotoxy(x+1,y+1);
// gotoxy(x + 1, y + 1);
// cputs(s);
#endif
}
@@ -117,7 +118,8 @@ void ee_putstr(int x, int y, char *s)
void ee_clear(void)
{
/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
int x = ee_get_width(), y = ee_get_height();
int x = ee_get_width();
int y = ee_get_height();
char *empty_line = malloc((x + 1) * sizeof(char));

memset(empty_line, ' ', x);


+ 10
- 16
libee/io.c Voir le fichier

@@ -22,37 +22,31 @@

#include "config.h"

#ifdef USE_SLANG
#if defined(USE_SLANG)
# include <slang.h>
#elif USE_NCURSES
#elif defined(USE_NCURSES)
# include <curses.h>
#elif USE_CONIO
#elif defined(USE_CONIO)
# include <conio.h>
#else
# error "no graphics library detected"
#endif

#include "ee.h"
#include "ee_internals.h"

char ee_get_key(void)
{
#ifdef USE_SLANG
if(SLang_input_pending(0))
{
return SLang_getkey();
}
#elif USE_NCURSES
#if defined(USE_SLANG)
return SLang_input_pending(0) ? SLang_getkey() : 0;

#elif defined(USE_NCURSES)
char key = getch();
return key != ERR ? key : 0;

if(key != ERR)
{
return key;
}
#elif USE_CONIO
#elif defined(USE_CONIO)
return _conio_kbhit() ? getch() : 0;

#endif

return 0;
}


+ 1
- 6
libee/line.c Voir le fichier

@@ -22,12 +22,6 @@

#include "config.h"

#ifdef USE_SLANG
# include <slang.h>
#elif USE_NCURSES
# include <curses.h>
#endif

#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#else
@@ -37,6 +31,7 @@ typedef unsigned char uint8_t;
#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"

struct line
{


+ 1
- 6
libee/math.c Voir le fichier

@@ -22,15 +22,10 @@

#include "config.h"

#ifdef USE_SLANG
# include <slang.h>
#elif USE_NCURSES
# include <curses.h>
#endif

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"

int ee_rand(int min, int max)
{


+ 1
- 6
libee/sprite.c Voir le fichier

@@ -22,17 +22,12 @@

#include "config.h"

#ifdef USE_SLANG
# include <slang.h>
#elif USE_NCURSES
# include <curses.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ee.h"
#include "ee_internals.h"

struct ee_frame
{


+ 1
- 6
libee/triangle.c Voir le fichier

@@ -22,15 +22,10 @@

#include "config.h"

#ifdef USE_SLANG
# include <slang.h>
#elif USE_NCURSES
# include <curses.h>
#endif

#include <stdlib.h>

#include "ee.h"
#include "ee_internals.h"

void ee_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
{


+ 1
- 1
src/Makefile.am Voir le fichier

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


+ 2
- 2
src/overlay.c Voir le fichier

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

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

if(g->p->life > MAX_LIFE * 7 / 10)
@@ -55,7 +55,7 @@ void draw_status(game *g)
ee_putstr(34, 1, "|");

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

if(g->p->special > MAX_SPECIAL * 9 / 10)


+ 1
- 1
src/weapons.c Voir le fichier

@@ -69,7 +69,7 @@ void draw_weapons(game *g, weapons *wp)
ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '@');
break;
case WEAPON_BOMB:
ee_set_color(EE_GRAY);
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, '.');


+ 82
- 62
test/demo.c Voir le fichier

@@ -24,6 +24,7 @@

#include <math.h>
#include <string.h>
#include <stdio.h>

#include "ee.h"

@@ -31,6 +32,7 @@ static void display_menu(void);

static void demo_all(void);

static void demo_color(void);
static void demo_dots(void);
static void demo_lines(void);
static void demo_boxes(void);
@@ -76,6 +78,10 @@ int main(int argc, char **argv)
demo = NULL;
quit = 1;
break;
case 'c':
ee_clear();
demo = demo_color;
break;
case '0':
ee_clear();
demo = demo_all;
@@ -143,10 +149,7 @@ static void display_menu(void)

ee_clear();
ee_set_color(EE_WHITE);
ee_draw_line(xo, yo, 1, yo, '.');
ee_draw_line(1, yo, 1, 1, ':');
ee_draw_line(xo, 1, xo, yo, ':');
ee_draw_line(1, 1, xo, 1, '.');
ee_draw_thin_box(1, 1, xo, yo);

ee_putstr((xo - strlen("libee demo")) / 2, 3, "libee demo");
ee_putstr((xo - strlen("============")) / 2, 4, "============");
@@ -171,7 +174,7 @@ static void demo_all(void)
{
static int i = 0;

int j, xo, yo, x1, y1, x2, y2, x3, y3;
int j, xo, yo, xa, ya, xb, yb, xc, yc;

i++;

@@ -184,9 +187,9 @@ static void demo_all(void)

for(j = 0; j < 16; j++)
{
x1 = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
y1 = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
ee_draw_thin_line(xo, yo, x1, y1);
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);
}

j = 15 + sin(0.03*i) * 8;
@@ -199,49 +202,49 @@ static void demo_all(void)
xo = ee_get_width() * 5 / 8;
yo = 2;

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

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

x3 = ee_get_width() / 4 - sin(0.02*i) * 5;
y3 = ee_get_height() * 3 / 4 + cos(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;

ee_set_color(EE_GREEN);
ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');
ee_fill_triangle(xo, yo, xb, yb, xa, ya, '%');
ee_set_color(EE_YELLOW);
ee_draw_thin_triangle(xo, yo, x2, y2, x1, y1);
ee_draw_thin_triangle(xo, yo, xb, yb, xa, ya);

ee_set_color(EE_RED);
ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
ee_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
ee_set_color(EE_YELLOW);
ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);

ee_set_color(EE_BLUE);
ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');
ee_fill_triangle(xo, yo, xb, yb, xc, yc, '%');
ee_set_color(EE_YELLOW);
ee_draw_thin_triangle(xo, yo, x2, y2, x3, y3);
ee_draw_thin_triangle(xo, yo, xb, yb, xc, yc);

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

x2 = ee_get_width() - 3;
y2 = ee_get_height() / 2;
xb = ee_get_width() - 3;
yb = ee_get_height() / 2;

x3 = ee_get_width() / 3;
y3 = ee_get_height() - 3;
xc = ee_get_width() / 3;
yc = ee_get_height() - 3;

ee_set_color(EE_CYAN);
ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
ee_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;

ee_draw_thin_line(x1, y1, xo, yo);
ee_draw_thin_line(x2, y2, xo, yo);
ee_draw_thin_line(x3, y3, xo, yo);
ee_draw_thin_line(xa, ya, xo, yo);
ee_draw_thin_line(xb, yb, xo, yo);
ee_draw_thin_line(xc, yc, xo, yo);

/* Draw a sprite on the pyramid */
ee_draw_sprite(xo, yo, sprite, 0);
@@ -250,7 +253,7 @@ static void demo_all(void)
for(j = i - 60; j < i; j++)
{
int delta = ee_rand(-5, 5);
ee_set_color(ee_rand(1, 10));
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
@@ -275,34 +278,51 @@ static void demo_dots(void)
for(i = 1000; i--;)
{
/* Putpixel */
ee_set_color(ee_rand(1, 10));
ee_set_color(ee_rand(0, 15));
ee_putchar(ee_rand(0, xmax), ee_rand(0, ymax), '#');
}
ee_refresh();
}

static void demo_color(void)
{
int i;
char buf[BUFSIZ];

ee_clear();
for(i = 0; i < 16; i++)
{
sprintf(buf, "color %i (%s)\n", i, ee_color_names[i]);
ee_set_color(EE_WHITE);
ee_putstr(4, i + 3, buf);
ee_set_color(i);
ee_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------");
}
ee_refresh();
}

static void demo_lines(void)
{
int w = ee_get_width();
int h = ee_get_height();
int x1, y1, x2, y2;
int xa, ya, xb, yb;

if(force_clipping)
{
x1 = ee_rand(- w, 2 * w); y1 = ee_rand(- h, 2 * h);
x2 = ee_rand(- w, 2 * w); y2 = ee_rand(- h, 2 * h);
xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
}
else
{
x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1);
x2 = ee_rand(0, w - 1); y2 = ee_rand(0, h - 1);
xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
}

ee_set_color(ee_rand(1, 10));
ee_set_color(ee_rand(0, 15));
if(thin)
ee_draw_thin_line(x1, y1, x2, y2);
ee_draw_thin_line(xa, ya, xb, yb);
else
ee_draw_line(x1, y1, x2, y2, '#');
ee_draw_line(xa, ya, xb, yb, '#');

ee_refresh();
}
@@ -311,26 +331,26 @@ static void demo_boxes(void)
{
int w = ee_get_width();
int h = ee_get_height();
int x1, y1, x2, y2;
int xa, ya, xb, yb;

if(force_clipping)
{
x1 = ee_rand(- w, 2 * w); y1 = ee_rand(- h, 2 * h);
x2 = ee_rand(- w, 2 * w); y2 = ee_rand(- h, 2 * h);
xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
}
else
{
x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1);
x2 = ee_rand(0, w - 1); y2 = ee_rand(0, h - 1);
xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
}

ee_set_color(ee_rand(1, 10));
ee_fill_box(x1, y1, x2, y2, '#');
ee_set_color(ee_rand(0, 15));
ee_fill_box(xa, ya, xb, yb, '#');

if(outline)
{
ee_set_color(ee_rand(1, 10));
ee_draw_thin_box(x1, y1, x2, y2);
ee_set_color(ee_rand(0, 15));
ee_draw_thin_box(xa, ya, xb, yb);
}

ee_refresh();
@@ -357,12 +377,12 @@ static void demo_ellipses(void)
} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
}

ee_set_color(ee_rand(1, 10));
ee_set_color(ee_rand(0, 15));
ee_fill_ellipse(x, y, a, b, '#');

if(outline)
{
ee_set_color(ee_rand(1, 10));
ee_set_color(ee_rand(0, 15));
ee_draw_thin_ellipse(x, y, a, b);
}

@@ -373,29 +393,29 @@ static void demo_triangles(void)
{
int w = ee_get_width();
int h = ee_get_height();
int x1, y1, x2, y2, x3, y3;
int xa, ya, xb, yb, xc, yc;

if(force_clipping)
{
x1 = ee_rand(- w, 2 * w); y1 = ee_rand(- h, 2 * h);
x2 = ee_rand(- w, 2 * w); y2 = ee_rand(- h, 2 * h);
x3 = ee_rand(- w, 2 * w); y3 = ee_rand(- h, 2 * h);
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);
}
else
{

x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1);
x2 = ee_rand(0, w - 1); y2 = ee_rand(0, h - 1);
x3 = ee_rand(0, w - 1); y3 = ee_rand(0, h - 1);
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);
}

ee_set_color(ee_rand(1, 10));
ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
ee_set_color(ee_rand(0, 15));
ee_fill_triangle(xa, ya, xb, yb, xc, yc, '#');

if(outline)
{
ee_set_color(ee_rand(1, 10));
ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
ee_set_color(ee_rand(0, 15));
ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
}

ee_refresh();


Chargement…
Annuler
Enregistrer