Changeset 153


Ignore:
Timestamp:
Nov 12, 2003, 2:48:58 AM (20 years ago)
Author:
Sam Hocevar
Message:
  • libee/graphics.c: + Renamed ee_color() to ee_set_color(), wrote ee_get_color().
  • libee/line.c: + Implemented draw_polyline() and draw_thin_polyline().
  • libee/sprite.c: + Removed the f member of struct ee_sprite. + Implemented ee_get_sprite_{width|height|dx|dy}(). + Restore the color fater ee_draw_sprite() is called.
  • libee/box.c: + Fixed a bug causing improper box clipping at the right and the bottom.
  • data/foo_fighter: + Fixed bugs in the sprite.
  • src/intro.c: + Test effects for the future game's intro.
  • test/spritedit.c: + Added stuff to the sprite editor. We can now navigate through frames.
Location:
libcaca/trunk
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/data/foo_fighter

    r121 r153  
    20209 2 4 0
    2121 ,-oXo-.
    22  V   `
     22`V'  `
    2323 ddededd
    24  d   d
     24ddd  d
    25257 2 3 0
    2626 ,oXo.
    27 /  V \
     27/ `V' \
    2828 deded
    29 d  d d
     29d ddd d
  • libcaca/trunk/libee/box.c

    r151 r153  
    6868            ee_putchar(x, y1, '-');
    6969
    70     if(y2 < ymax)
     70    if(y2 <= ymax)
    7171        for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
    7272            ee_putchar(x, y2, '-');
     
    7676            ee_putchar(x1, y, '|');
    7777
    78     if(x2 < xmax)
     78    if(x2 <= xmax)
    7979        for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
    8080            ee_putchar(x2, y, '|');
  • libcaca/trunk/libee/ee.h

    r151 r153  
    2020 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2121 */
     22
     23#ifndef __EE_H__
     24#define __EE_H__
     25
     26#ifdef __cplusplus
     27extern "C"
     28{
     29#endif
    2230
    2331/*
     
    5260char ee_get_key(void);
    5361
    54 void ee_color(int);
     62void ee_set_color(int);
     63int ee_get_color(void);
    5564void ee_putchar(int, int, char);
    5665void ee_putstr(int, int, char *);
     
    5867
    5968void ee_draw_line(int, int, int, int, char);
     69void ee_draw_polyline(int[], int[], int, char);
    6070void ee_draw_thin_line(int, int, int, int);
     71void ee_draw_thin_polyline(int[], int[], int);
    6172
    6273void ee_draw_circle(int, int, int, char);
     
    7788
    7889struct ee_sprite * ee_load_sprite(const char *);
    79 void ee_set_sprite_frame(struct ee_sprite *, int);
    80 int ee_get_sprite_frame(struct ee_sprite *);
    81 void ee_draw_sprite(int, int, struct ee_sprite *);
     90int ee_get_sprite_frames(struct ee_sprite *);
     91int ee_get_sprite_width(struct ee_sprite *, int);
     92int ee_get_sprite_height(struct ee_sprite *, int);
     93int ee_get_sprite_dx(struct ee_sprite *, int);
     94int ee_get_sprite_dy(struct ee_sprite *, int);
     95void ee_draw_sprite(int, int, struct ee_sprite *, int);
    8296void ee_free_sprite(struct ee_sprite *);
    8397
     98#ifdef __cplusplus
     99}
     100#endif
     101
     102#endif /* __EE_H__ */
  • libcaca/trunk/libee/graphics.c

    r147 r153  
    3434#include "ee.h"
    3535
    36 void ee_color(int color)
     36static int ee_color = 0;
     37
     38void ee_set_color(int color)
    3739{
     40    ee_color = color;
    3841#ifdef USE_SLANG
    3942    SLsmg_set_color(color);
     
    4346    /* Use dummy driver */
    4447#endif
     48}
     49
     50int ee_get_color(void)
     51{
     52    return ee_color;
    4553}
    4654
  • libcaca/trunk/libee/line.c

    r147 r153  
    6969}
    7070
     71void ee_draw_polyline(int x[], int y[], int n, char c)
     72{
     73    int i;
     74    struct line s;
     75    s.c = c;
     76    s.draw = draw_solid_line;
     77
     78    for(i = 0; i < n; i++)
     79    {
     80        s.x1 = x[i];
     81        s.y1 = y[i];
     82        s.x2 = x[i+1];
     83        s.y2 = y[i+1];
     84        clip_line(&s);
     85    }
     86}
     87
    7188/**
    7289 * \brief Draw a thin line on the screen, using ASCII art.
     
    89106}
    90107
     108void ee_draw_thin_polyline(int x[], int y[], int n)
     109{
     110    int i;
     111    struct line s;
     112    s.draw = draw_thin_line;
     113
     114    for(i = 0; i < n; i++)
     115    {
     116        s.x1 = x[i];
     117        s.y1 = y[i];
     118        s.x2 = x[i+1];
     119        s.y2 = y[i+1];
     120        clip_line(&s);
     121    }
     122}
     123
    91124/*
    92125 * XXX: The following functions are local.
  • libcaca/trunk/libee/sprite.c

    r147 r153  
    4545struct ee_sprite
    4646{
    47     int f;
    4847    int nf;
    4948    struct ee_frame *frames;
     
    6160
    6261    sprite = malloc(sizeof(struct ee_sprite));
    63     sprite->f = 0;
    6462    sprite->nf = 0;
    6563    sprite->frames = NULL;
     
    137135}
    138136
    139 void ee_set_sprite_frame(struct ee_sprite *sprite, int f)
    140 {
     137int ee_get_sprite_frames(struct ee_sprite *sprite)
     138{
     139    if(sprite == NULL)
     140        return 0;
     141
     142    return sprite->nf;
     143}
     144
     145int ee_get_sprite_width(struct ee_sprite *sprite, int f)
     146{
     147    if(sprite == NULL)
     148        return 0;
     149
     150    if(f < 0 || f >= sprite->nf)
     151        return 0;
     152
     153    return sprite->frames[f].w;
     154}
     155
     156int ee_get_sprite_height(struct ee_sprite *sprite, int f)
     157{
     158    if(sprite == NULL)
     159        return 0;
     160
     161    if(f < 0 || f >= sprite->nf)
     162        return 0;
     163
     164    return sprite->frames[f].h;
     165}
     166
     167int ee_get_sprite_dx(struct ee_sprite *sprite, int f)
     168{
     169    if(sprite == NULL)
     170        return 0;
     171
     172    if(f < 0 || f >= sprite->nf)
     173        return 0;
     174
     175    return sprite->frames[f].dx;
     176}
     177
     178int ee_get_sprite_dy(struct ee_sprite *sprite, int f)
     179{
     180    if(sprite == NULL)
     181        return 0;
     182
     183    if(f < 0 || f >= sprite->nf)
     184        return 0;
     185
     186    return sprite->frames[f].dy;
     187}
     188
     189void ee_draw_sprite(int x, int y, struct ee_sprite *sprite, int f)
     190{
     191    int i, j, oldcol;
     192    struct ee_frame *frame;
     193
    141194    if(sprite == NULL)
    142195        return;
     
    145198        return;
    146199
    147     sprite->f = f;
    148 }
    149 
    150 int ee_get_sprite_frame(struct ee_sprite *sprite)
    151 {
    152     if(sprite == NULL)
    153         return -1;
    154 
    155     return sprite->f;
    156 }
    157 
    158 void ee_draw_sprite(int x, int y, struct ee_sprite *sprite)
    159 {
    160     int i, j;
    161     struct ee_frame *frame;
    162 
    163     if(sprite == NULL)
    164         return;
    165 
    166     frame = &sprite->frames[sprite->f];
     200    frame = &sprite->frames[f];
     201
     202    oldcol = ee_get_color();
    167203
    168204    for(j = 0; j < frame->h; j++)
     
    173209            if(col >= 0)
    174210            {
    175                 ee_color(col);
     211                ee_set_color(col);
    176212                ee_putchar(x + i - frame->dx, y + j - frame->dy,
    177213                           frame->chars[frame->w * j + i]);
     
    179215        }
    180216    }
     217
     218    ee_set_color(oldcol);
    181219}
    182220
  • libcaca/trunk/src/Makefile.am

    r145 r153  
    2222        common.h \
    2323        explosions.c \
     24        intro.c \
    2425        main.c \
    2526        overlay.c \
  • libcaca/trunk/src/aliens.c

    r121 r153  
    2727#include "common.h"
    2828
    29 static void draw_alien_foo(game *, int, int, int);
    30 static void draw_alien_bar(game *, int, int, int);
    31 static void draw_alien_baz(game *, int, int, int);
    32 
    3329struct ee_sprite *foo_sprite;
    3430struct ee_sprite *bar_sprite;
     
    5854        {
    5955            case ALIEN_FOO:
    60                 draw_alien_foo(g, al->x[i], al->y[i], al->img[i] % 8);
     56                ee_draw_sprite(al->x[i], al->y[i], foo_sprite, al->img[i] % 8);
    6157                break;
    6258            case ALIEN_BAR:
    63                 draw_alien_bar(g, al->x[i], al->y[i], al->img[i] % 2);
     59                ee_draw_sprite(al->x[i], al->y[i], bar_sprite, al->img[i] % 2);
    6460                break;
    6561            case ALIEN_BAZ:
    66                 draw_alien_baz(g, al->x[i], al->y[i], al->img[i] % 6);
     62                ee_draw_sprite(al->x[i], al->y[i], baz_sprite, al->img[i] % 6);
    6763                break;
    6864            case ALIEN_NONE:
     
    139135}
    140136
    141 static void draw_alien_bar(game *g, int x, int y, int frame)
    142 {
    143     ee_set_sprite_frame(bar_sprite, frame);
    144     ee_draw_sprite(x, y, bar_sprite);
    145 }
    146 
    147 static void draw_alien_baz(game *g, int x, int y, int frame)
    148 {
    149     ee_set_sprite_frame(baz_sprite, frame);
    150     ee_draw_sprite(x, y, baz_sprite);
    151 }
    152 
    153 static void draw_alien_foo(game *g, int x, int y, int frame)
    154 {
    155     ee_set_sprite_frame(foo_sprite, frame);
    156     ee_draw_sprite(x, y, foo_sprite);
    157 }
    158 
    159 
  • libcaca/trunk/src/bonus.c

    r121 r153  
    5252        {
    5353            case BONUS_GREEN:
    54                 ee_set_sprite_frame(gem_sprite, (bo->n[i]/2 % 3) ? 0 : 1);
    55                 ee_draw_sprite(bo->x[i], bo->y[i], gem_sprite);
     54                ee_draw_sprite(bo->x[i], bo->y[i], gem_sprite,
     55                               (bo->n[i]/2 % 3) ? 0 : 1);
    5656                break;
    5757            case BONUS_LIFE:
    58                 ee_set_sprite_frame(heart_sprite, (bo->n[i] % 3) ? 0 : 1);
    59                 ee_draw_sprite(bo->x[i], bo->y[i], heart_sprite);
     58                ee_draw_sprite(bo->x[i], bo->y[i], heart_sprite,
     59                               (bo->n[i] % 3) ? 0 : 1);
    6060                break;
    6161            case BONUS_NONE:
  • libcaca/trunk/src/box.c

    r147 r153  
    4444    int j, frame;
    4545
    46     ee_color(EE_YELLOW);
     46    ee_set_color(EE_YELLOW);
    4747
    4848    /* Draw the thin horizontal line */
     
    6767                 b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, 'X');
    6868
    69     ee_color(EE_BLACK);
     69    ee_set_color(EE_BLACK);
    7070
    7171    for(j = b->y - b->h * (frame - 8) / 8 + 1;
     
    8383
    8484    /* Draw the text inside the frame */
    85     ee_color(EE_YELLOW);
     85    ee_set_color(EE_YELLOW);
    8686
    8787    /* FIXME: use a font */
  • libcaca/trunk/src/common.h

    r89 r153  
    2020 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2121 */
     22
     23void intro(void);
    2224
    2325/*
  • libcaca/trunk/src/explosions.c

    r139 r153  
    2626
    2727#include "common.h"
    28 
    29 static void draw_small_explosion(int x, int y, int frame);
    30 static void draw_medium_explosion(int x, int y, int frame);
    3128
    3229struct ee_sprite *medium_sprite;
     
    8077    {
    8178#if 0
    82         ee_color(GREEN);
     79        ee_set_color(GREEN);
    8380        ee_goto(ex->x[i] + 3, ex->y[i]);
    8481        switch(ee_rand(0,2))
     
    107104        {
    108105            case EXPLOSION_MEDIUM:
    109                 draw_medium_explosion(ex->x[i], ex->y[i], ex->n[i]);
     106                ee_draw_sprite(ex->x[i], ex->y[i], medium_sprite,
     107                               10 - ex->n[i]);
    110108                break;
    111109            case EXPLOSION_SMALL:
    112                 draw_small_explosion(ex->x[i], ex->y[i], ex->n[i]);
     110                ee_draw_sprite(ex->x[i], ex->y[i], small_sprite,
     111                               6 - ex->n[i]);
    113112                break;
    114113            case EXPLOSION_NONE:
     
    142141}
    143142
    144 static void draw_small_explosion(int x, int y, int frame)
    145 {
    146     ee_set_sprite_frame(small_sprite, 6 - frame);
    147     ee_draw_sprite(x, y, small_sprite);
    148 }
    149 
    150 static void draw_medium_explosion(int x, int y, int frame)
    151 {
    152     ee_set_sprite_frame(medium_sprite, 10 - frame);
    153     ee_draw_sprite(x, y, medium_sprite);
    154 }
    155 
  • libcaca/trunk/src/main.c

    r149 r153  
    4848    g->w = ee_get_width();
    4949    g->h = ee_get_height();
     50
     51intro();
    5052
    5153    /* Go ! */
  • libcaca/trunk/src/overlay.c

    r147 r153  
    3333
    3434    /* Draw life jauge */
    35     ee_color(EE_GRAY);
     35    ee_set_color(EE_GRAY);
    3636    ee_putstr(4, 1, dots30);
    3737
    3838    if(g->p->life > MAX_LIFE * 7 / 10)
    3939    {
    40         ee_color(EE_GREEN);
     40        ee_set_color(EE_GREEN);
    4141    }
    4242    else if(g->p->life > MAX_LIFE * 3 / 10)
    4343    {
    44         ee_color(EE_YELLOW);
     44        ee_set_color(EE_YELLOW);
    4545    }
    4646    else
    4747    {
    48         ee_color(EE_RED);
     48        ee_set_color(EE_RED);
    4949    }
    5050
    5151    ee_putstr(4, 1, dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE);
    5252
    53     ee_color(EE_WHITE);
     53    ee_set_color(EE_WHITE);
    5454    ee_putstr(1, 1, "L |");
    5555    ee_putstr(34, 1, "|");
    5656
    5757    /* Draw weapon jauge */
    58     ee_color(EE_GRAY);
     58    ee_set_color(EE_GRAY);
    5959    ee_putstr(42, 1, dots30 + 10);
    6060
    6161    if(g->p->special > MAX_SPECIAL * 9 / 10)
    6262    {
    63         ee_color(EE_WHITE);
     63        ee_set_color(EE_WHITE);
    6464    }
    6565    else if(g->p->special > MAX_SPECIAL * 3 / 10)
    6666    {
    67         ee_color(EE_CYAN);
     67        ee_set_color(EE_CYAN);
    6868    }
    6969    else
    7070    {
    71         ee_color(EE_BLUE);
     71        ee_set_color(EE_BLUE);
    7272    }
    7373
     
    7575                       + (MAX_SPECIAL - g->p->special) * 20 / MAX_SPECIAL);
    7676
    77     ee_color(EE_WHITE);
     77    ee_set_color(EE_WHITE);
    7878    ee_putstr(39, 1, "S |");
    7979    ee_putstr(62, 1, "|");
  • libcaca/trunk/src/player.c

    r149 r153  
    5858        return;
    5959
    60     ee_draw_sprite(p->x, p->y, ship_sprite);
     60    ee_draw_sprite(p->x, p->y, ship_sprite, 0);
    6161}
    6262
  • libcaca/trunk/src/starfield.c

    r147 r153  
    5454        if(s[i].x >= 0)
    5555        {
    56             ee_color(s[i].c);
     56            ee_set_color(s[i].c);
    5757            ee_putchar(s[i].x, s[i].y, s[i].ch);
    5858        }
  • libcaca/trunk/src/tunnel.c

    r147 r153  
    7272    char c;
    7373
    74     ee_color(EE_GREEN);
     74    ee_set_color(EE_GREEN);
    7575
    7676    /* Left border */
     
    110110    }
    111111
    112     ee_color(EE_RED);
     112    ee_set_color(EE_RED);
    113113
    114114    /* Left concrete */
  • libcaca/trunk/src/weapons.c

    r149 r153  
    5757        {
    5858            case WEAPON_LASER:
    59                 ee_color(EE_WHITE);
     59                ee_set_color(EE_WHITE);
    6060                ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '|');
    61                 ee_color(EE_CYAN);
     61                ee_set_color(EE_CYAN);
    6262                ee_putchar(wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
    6363                break;
    6464            case WEAPON_SEEKER:
    65                 ee_color(EE_CYAN);
     65                ee_set_color(EE_CYAN);
    6666                ee_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
    6767                ee_putchar(wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
    68                 ee_color(EE_WHITE);
     68                ee_set_color(EE_WHITE);
    6969                ee_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '@');
    7070                break;
    7171            case WEAPON_BOMB:
    72                 ee_color(EE_GRAY);
     72                ee_set_color(EE_GRAY);
    7373                ee_putchar((wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.');
    7474                ee_putchar((wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.');
     
    334334    }
    335335
    336     ee_set_sprite_frame(bomb_sprite, frame);
    337     ee_draw_sprite(x, y, bomb_sprite);
     336    ee_draw_sprite(x, y, bomb_sprite, frame);
    338337}
    339338
     
    341340{
    342341    /* Draw the head */
    343     ee_set_sprite_frame(fragbomb_sprite, frame & 1);
    344     ee_draw_sprite(x, y, fragbomb_sprite);
     342    ee_draw_sprite(x, y, fragbomb_sprite, frame & 1);
    345343
    346344    /* Draw the tail */
    347     ee_set_sprite_frame(fragbomb_sprite, 2 + (frame % 4));
    348     ee_draw_sprite(x, y, fragbomb_sprite);
     345    ee_draw_sprite(x, y, fragbomb_sprite, 2 + (frame % 4));
    349346}
    350347
     
    357354    {
    358355        case 24:
    359             ee_color(EE_WHITE);
     356            ee_set_color(EE_WHITE);
    360357            ee_putstr(x, y-3, "__");
    361358            ee_putchar(x-1, y-2, '\'');
     
    363360            break;
    364361        case 23:
    365             ee_color(EE_CYAN);
     362            ee_set_color(EE_CYAN);
    366363            ee_putstr(x, y-3, "__");
    367             ee_color(EE_WHITE);
     364            ee_set_color(EE_WHITE);
    368365            ee_putstr(x-2, y-2, "-'");
    369366            ee_putstr(x+2, y-2, "`-");
    370367            break;
    371368        case 22:
    372             ee_color(EE_CYAN);
     369            ee_set_color(EE_CYAN);
    373370            ee_putstr(x, y-3, "__");
    374371            ee_putchar(x-1, y-2, '\'');
    375372            ee_putchar(x+2, y-2, '`');
    376             ee_color(EE_WHITE);
     373            ee_set_color(EE_WHITE);
    377374            ee_putstr(x-3, y-2, ",-");
    378375            ee_putstr(x+3, y-2, "-.");
    379376            break;
    380377        case 21:
    381             ee_color(EE_CYAN);
     378            ee_set_color(EE_CYAN);
    382379            ee_putstr(x-1, y-3, "____");
    383380            ee_putchar(x-2, y-2, '\'');
    384381            ee_putchar(x+3, y-2, '`');
    385             ee_color(EE_WHITE);
     382            ee_set_color(EE_WHITE);
    386383            ee_putstr(x-4, y-2, ",-");
    387384            ee_putstr(x+4, y-2, "-.");
    388385            break;
    389386        case 20:
    390             ee_color(EE_WHITE);
     387            ee_set_color(EE_WHITE);
    391388            ee_putstr(x, y-3, "%%");
    392389            ee_putchar(x-4, y-2, ',');
    393390            ee_putchar(x+5, y-2, '.');
    394             ee_color(EE_CYAN);
     391            ee_set_color(EE_CYAN);
    395392            ee_putchar(x-1, y-3, ':');
    396393            ee_putchar(x+2, y-3, ':');
     
    399396            break;
    400397        case 19:
    401             ee_color(EE_WHITE);
     398            ee_set_color(EE_WHITE);
    402399            ee_putstr(x, y-4, "%%");
    403400            ee_putstr(x, y-3, "##");
    404             ee_color(EE_CYAN);
     401            ee_set_color(EE_CYAN);
    405402            ee_putchar(x-1, y-4, ':');
    406403            ee_putchar(x+2, y-4, ':');
     
    409406            ee_putstr(x-4, y-2, ",-'");
    410407            ee_putstr(x+3, y-2, "`-.");
    411             ee_color(EE_BLUE);
     408            ee_set_color(EE_BLUE);
    412409            ee_putchar(x-2, y-3, ':');
    413410            ee_putchar(x+3, y-3, ':');
     
    416413        default:
    417414            r = (18 - frame) * (18 - frame);
    418             ee_color(EE_WHITE);
     415            ee_set_color(EE_WHITE);
    419416            ee_putstr(x-1, y-5-r, ":%%:");
    420417            ee_putstr(x-1, y-4-r, "%##%");
    421             ee_color(EE_CYAN);
     418            ee_set_color(EE_CYAN);
    422419            ee_putchar(x-2, y-4-r, ':');
    423420            ee_putchar(x+3, y-4-r, ':');
    424421            ee_putchar(x-2, y-2, '\'');
    425422            ee_putchar(x+3, y-2, '`');
    426             ee_color(EE_BLUE);
     423            ee_set_color(EE_BLUE);
    427424            ee_putchar(x-3, y-2, ':');
    428425            ee_putchar(x+4, y-2, ':');
    429426            for(i = 0; i <= r; i++)
    430427            {
    431                 ee_color(EE_WHITE);
     428                ee_set_color(EE_WHITE);
    432429                ee_putstr(x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
    433                 ee_color(EE_CYAN);
     430                ee_set_color(EE_CYAN);
    434431                ee_putchar(x-2, y-3-i, '%');
    435432                ee_putchar(x+3, y-3-i, '%');
    436                 ee_color(EE_BLUE);
     433                ee_set_color(EE_BLUE);
    437434                ee_putchar(x-3, y-3-i, ':');
    438435                ee_putchar(x+4, y-3-i, ':');
     
    447444
    448445    /* Lots of duplicate pixels, but we don't care */
    449     ee_color(EE_BLUE);
     446    ee_set_color(EE_BLUE);
    450447    ee_draw_ellipse(x, y, r, r / 2, ':');
    451448    ee_draw_ellipse(x, y, r + 1, r / 2, ':');
    452449    ee_draw_ellipse(x, y, r + 2, r / 2, ':');
    453     ee_color(EE_CYAN);
     450    ee_set_color(EE_CYAN);
    454451    ee_draw_ellipse(x, y, r + 2, r / 2 + 1, '%');
    455452    ee_draw_ellipse(x, y, r + 3, r / 2 + 1, '%');
    456     ee_color(EE_WHITE);
     453    ee_set_color(EE_WHITE);
    457454    ee_draw_ellipse(x, y, r + 3, r / 2 + 2, '#');
    458455    ee_draw_ellipse(x, y, r + 4, r / 2 + 2, '#');
  • libcaca/trunk/test/demo.c

    r151 r153  
    143143
    144144    ee_clear();
    145     ee_color(EE_WHITE);
     145    ee_set_color(EE_WHITE);
    146146    ee_draw_line(xo, yo, 1, yo, '.');
    147147    ee_draw_line(1, yo, 1, 1, ':');
     
    179179
    180180    /* Draw the sun */
    181     ee_color(EE_YELLOW);
     181    ee_set_color(EE_YELLOW);
    182182    xo = ee_get_width() / 4;
    183183    yo = ee_get_height() / 4 + 5 * sin(0.03*i);
     
    191191
    192192    j = 15 + sin(0.03*i) * 8;
    193     ee_color(EE_WHITE);
     193    ee_set_color(EE_WHITE);
    194194    ee_fill_ellipse(xo, yo, j, j / 2, '#');
    195     ee_color(EE_YELLOW);
     195    ee_set_color(EE_YELLOW);
    196196    ee_draw_ellipse(xo, yo, j, j / 2, '#');
    197197
     
    209209    y3 = ee_get_height() * 3 / 4 + cos(0.02*i) * 5;
    210210
    211     ee_color(EE_GREEN);
     211    ee_set_color(EE_GREEN);
    212212    ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');
    213     ee_color(EE_YELLOW);
     213    ee_set_color(EE_YELLOW);
    214214    ee_draw_thin_triangle(xo, yo, x2, y2, x1, y1);
    215215
    216     ee_color(EE_RED);
     216    ee_set_color(EE_RED);
    217217    ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
    218     ee_color(EE_YELLOW);
     218    ee_set_color(EE_YELLOW);
    219219    ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
    220220
    221     ee_color(EE_BLUE);
     221    ee_set_color(EE_BLUE);
    222222    ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');
    223     ee_color(EE_YELLOW);
     223    ee_set_color(EE_YELLOW);
    224224    ee_draw_thin_triangle(xo, yo, x2, y2, x3, y3);
    225225
     
    234234    y3 = ee_get_height() - 3;
    235235
    236     ee_color(EE_CYAN);
     236    ee_set_color(EE_CYAN);
    237237    ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
    238238
     
    245245
    246246    /* Draw a sprite on the pyramid */
    247     ee_draw_sprite(xo, yo, sprite);
     247    ee_draw_sprite(xo, yo, sprite, 0);
    248248
    249249    /* Draw a trail behind the foreground sprite */
     
    251251    {
    252252        int delta = ee_rand(-5, 5);
    253         ee_color(ee_rand(1, 10));
     253        ee_set_color(ee_rand(1, 10));
    254254        ee_putchar(ee_get_width() / 2
    255255                    + cos(0.02*j) * (delta + ee_get_width() / 4),
     
    262262    ee_draw_sprite(ee_get_width() / 2 + cos(0.02*i) * ee_get_width() / 4,
    263263                   ee_get_height() / 2 + sin(0.02*i) * ee_get_height() / 3,
    264                    sprite);
     264                   sprite, 0);
    265265
    266266    ee_refresh();
     
    276276    {
    277277        /* Putpixel */
    278         ee_color(ee_rand(1, 10));
     278        ee_set_color(ee_rand(1, 10));
    279279        ee_putchar(ee_rand(0, xmax), ee_rand(0, ymax), '#');
    280280    }
     
    299299    }
    300300
    301     ee_color(ee_rand(1, 10));
     301    ee_set_color(ee_rand(1, 10));
    302302    if(thin)
    303303        ee_draw_thin_line(x1, y1, x2, y2);
     
    325325    }
    326326
    327     ee_color(ee_rand(1, 10));
     327    ee_set_color(ee_rand(1, 10));
    328328    ee_fill_box(x1, y1, x2, y2, '#');
    329329
    330330    if(outline)
    331331    {
    332         ee_color(ee_rand(1, 10));
     332        ee_set_color(ee_rand(1, 10));
    333333        ee_draw_thin_box(x1, y1, x2, y2);
    334334    }
     
    358358    }
    359359
    360     ee_color(ee_rand(1, 10));
     360    ee_set_color(ee_rand(1, 10));
    361361    ee_fill_ellipse(x, y, a, b, '#');
    362362
    363363    if(outline)
    364364    {
    365         ee_color(ee_rand(1, 10));
     365        ee_set_color(ee_rand(1, 10));
    366366        ee_draw_thin_ellipse(x, y, a, b);
    367367    }
     
    390390    }
    391391
    392     ee_color(ee_rand(1, 10));
     392    ee_set_color(ee_rand(1, 10));
    393393    ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
    394394
    395395    if(outline)
    396396    {
    397         ee_color(ee_rand(1, 10));
     397        ee_set_color(ee_rand(1, 10));
    398398        ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
    399399    }
     
    405405{
    406406    ee_draw_sprite(ee_rand(0, ee_get_width() - 1),
    407                    ee_rand(0, ee_get_height() - 1), sprite);
    408     ee_refresh();
    409 }
    410 
     407                   ee_rand(0, ee_get_height() - 1), sprite, 0);
     408    ee_refresh();
     409}
     410
  • libcaca/trunk/test/spritedit.c

    r145 r153  
    2323#include "config.h"
    2424
    25 #include <math.h>
    26 #include <string.h>
     25#include <stdio.h>
    2726
    2827#include "ee.h"
     
    3130{
    3231    int quit = 0;
     32    struct ee_sprite *sprite;
     33    int frame = 0;
     34
     35    if(argc < 2)
     36    {
     37        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
     38        return 1;
     39    }
    3340
    3441    if(ee_init())
     42        return 1;
     43
     44    sprite = ee_load_sprite(argv[1]);
     45
     46    if(!sprite)
    3547    {
     48        ee_end();
     49        fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
    3650        return 1;
    3751    }
     
    4054    while(!quit)
    4155    {
    42         char key = ee_get_key();
    43         switch(key)
     56        int xa, ya, xb, yb;
     57        char buf[BUFSIZ];
     58
     59        switch(ee_get_key())
    4460        {
    4561        case 0:
     
    4864            quit = 1;
    4965            break;
     66        case '-':
     67            if(frame > 0)
     68                frame--;
     69            break;
     70        case '+':
     71            if(frame < ee_get_sprite_frames(sprite) - 1)
     72                frame++;
     73            break;
    5074        }
     75
     76        ee_clear();
     77
     78        ee_set_color(EE_WHITE);
     79        ee_draw_thin_box(0, 0, ee_get_width() - 1, ee_get_height() - 1);
     80
     81        ee_putstr(3, 0, "[ Sprite editor for libee ]");
     82
     83        sprintf(buf, "sprite `%s'", argv[1]);
     84        ee_putstr(3, 2, buf);
     85        sprintf(buf, "frame %i/%i", frame, ee_get_sprite_frames(sprite) - 1);
     86        ee_putstr(3, 3, buf);
     87
     88        /* Crosshair */
     89        ee_draw_thin_line(57, 2, 57, 18);
     90        ee_draw_thin_line(37, 10, 77, 10);
     91        ee_putchar(57, 10, '+');
     92
     93        /* Boxed sprite */
     94        xa = -1 - ee_get_sprite_dx(sprite, frame);
     95        ya = -1 - ee_get_sprite_dy(sprite, frame);
     96        xb = xa + 1 + ee_get_sprite_width(sprite, frame);
     97        yb = ya + 1 + ee_get_sprite_height(sprite, frame);
     98        ee_set_color(EE_BLACK);
     99        ee_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
     100        ee_set_color(EE_WHITE);
     101        ee_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
     102        ee_draw_sprite(57, 10, sprite, frame);
     103
     104        /* Free sprite */
     105        ee_draw_sprite(20, 10, sprite, frame);
     106
     107        ee_refresh();
    51108    }
    52109
Note: See TracChangeset for help on using the changeset viewer.