Просмотр исходного кода

* Ported to new libcaca/libcucul API.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@544 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 18 лет назад
Родитель
Сommit
d90d02cdf7
14 измененных файлов: 269 добавлений и 262 удалений
  1. +10
    -10
      src/aliens.c
  2. +8
    -8
      src/bonus.c
  3. +25
    -25
      src/box.c
  4. +3
    -3
      src/ceo.c
  5. +2
    -2
      src/collide.c
  6. +5
    -2
      src/common.h
  7. +22
    -22
      src/explosions.c
  8. +20
    -20
      src/intro.c
  9. +17
    -13
      src/main.c
  10. +18
    -18
      src/overlay.c
  11. +3
    -3
      src/player.c
  12. +11
    -11
      src/starfield.c
  13. +10
    -10
      src/tunnel.c
  14. +115
    -115
      src/weapons.c

+ 10
- 10
src/aliens.c Просмотреть файл

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

#include "common.h"

struct caca_sprite *foo_sprite;
struct caca_sprite *bar_sprite;
struct caca_sprite *baz_sprite;
struct cucul_sprite *foo_sprite;
struct cucul_sprite *bar_sprite;
struct cucul_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 = caca_load_sprite("data/foofight.txt");
bar_sprite = caca_load_sprite("data/barfight.txt");
baz_sprite = caca_load_sprite("data/bazfight.txt");
foo_sprite = cucul_load_sprite(g->qq, "data/foofight.txt");
bar_sprite = cucul_load_sprite(g->qq, "data/barfight.txt");
baz_sprite = cucul_load_sprite(g->qq, "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:
caca_draw_sprite(al->x[i], al->y[i], foo_sprite, al->img[i] % 5);
cucul_draw_sprite(g->qq, al->x[i], al->y[i], foo_sprite, al->img[i] % 5);
break;
case ALIEN_BAR:
caca_draw_sprite(al->x[i], al->y[i], bar_sprite, al->img[i] % 2);
cucul_draw_sprite(g->qq, al->x[i], al->y[i], bar_sprite, al->img[i] % 2);
break;
case ALIEN_BAZ:
caca_draw_sprite(al->x[i], al->y[i], baz_sprite, al->img[i] % 4);
cucul_draw_sprite(g->qq, al->x[i], al->y[i], baz_sprite, al->img[i] % 4);
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], caca_rand(0,4) ? BONUS_GREEN : BONUS_LIFE);
add_bonus(g, g->bo, al->x[i], al->y[i], cucul_rand(0,4) ? BONUS_GREEN : BONUS_LIFE);
}

/* Update coordinates */


+ 8
- 8
src/bonus.c Просмотреть файл

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

#include "common.h"

struct caca_sprite *heart_sprite;
struct caca_sprite *gem_sprite;
struct cucul_sprite *heart_sprite;
struct cucul_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 = caca_load_sprite("data/bonheart.txt");
gem_sprite = caca_load_sprite("data/bongem.txt");
heart_sprite = cucul_load_sprite(g->qq, "data/bonheart.txt");
gem_sprite = cucul_load_sprite(g->qq, "data/bongem.txt");
}

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


+ 25
- 25
src/box.c Просмотреть файл

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

caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);

/* Draw the thin horizontal line */
if(b->frame < 8)
{
caca_draw_line(b->x - b->w * b->frame / 16, b->y,
b->x + b->w * b->frame / 16 - 1, b->y, 'X');
cucul_draw_line(g->qq, b->x - b->w * b->frame / 16, b->y,
b->x + b->w * b->frame / 16 - 1, b->y, 'X');
return;
}

/* Draw the frame */
frame = b->frame < 12 ? b->frame : 12;

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');
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');
cucul_draw_line(g->qq, 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');
cucul_draw_line(g->qq, 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');

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');
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');
cucul_draw_line(g->qq, 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');
cucul_draw_line(g->qq, 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');

caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);

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

if(b->frame < 12)
@@ -84,19 +84,19 @@ void draw_box(game *g, box *b)
}

/* Draw the text inside the frame */
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);

/* FIXME: use a font */
caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2,
"XXXX. .XXXX X X .XXXX .XXXX XXXX.");
caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3,
"X `X X' X X X X' X' X `X");
caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4,
"XXXX' XXXXX X X `XXX XXXX X X");
caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5,
"X' X' `X X. ,X `X X' X ,X");
caca_putstr(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6,
"X X X `XXXX XXXX' `XXXX XXXX'");
cucul_putstr(g->qq, b->x - b->w / 2 + 12, b->y - b->h / 2 + 2,
"XXXX. .XXXX X X .XXXX .XXXX XXXX.");
cucul_putstr(g->qq, b->x - b->w / 2 + 12, b->y - b->h / 2 + 3,
"X `X X' X X X X' X' X `X");
cucul_putstr(g->qq, b->x - b->w / 2 + 12, b->y - b->h / 2 + 4,
"XXXX' XXXXX X X `XXX XXXX X X");
cucul_putstr(g->qq, b->x - b->w / 2 + 12, b->y - b->h / 2 + 5,
"X' X' `X X. ,X `X X' X ,X");
cucul_putstr(g->qq, b->x - b->w / 2 + 12, b->y - b->h / 2 + 6,
"X X X `XXXX XXXX' `XXXX XXXX'");
}

void free_box(box *b)


+ 3
- 3
src/ceo.c Просмотреть файл

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

while(!end)
{
caca_clear();
cucul_clear(g->qq);

if(caca_get_event(CACA_EVENT_KEY_PRESS)
if(caca_get_event(g->kk, CACA_EVENT_KEY_PRESS)
== (CACA_EVENT_KEY_PRESS | '\t'))
{
end = 1;
@@ -43,7 +43,7 @@ void ceo_alert(game *g)

fprintf(stderr, "foo\n");

caca_refresh();
caca_display(g->qq);

usleep(40000);
}


+ 2
- 2
src/collide.c Просмотреть файл

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


+ 5
- 2
src/common.h Просмотреть файл

@@ -20,8 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

void intro(void);

/*
* Compile-time limits
*/
@@ -134,6 +132,9 @@ typedef struct
{
int w, h;

cucul_t *qq;
caca_t *kk;

starfield *sf;
weapons *wp;
explosions *ex;
@@ -144,6 +145,8 @@ typedef struct

} game;

void intro(game *g);

/*
* From aliens.c
*/


+ 22
- 22
src/explosions.c Просмотреть файл

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

#include "common.h"

struct caca_sprite *medium_sprite;
struct caca_sprite *small_sprite;
struct cucul_sprite *medium_sprite;
struct cucul_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 = caca_load_sprite("data/xplmed.txt");
small_sprite = caca_load_sprite("data/xplsmall.txt");
medium_sprite = cucul_load_sprite(g->qq, "data/xplmed.txt");
small_sprite = cucul_load_sprite(g->qq, "data/xplsmall.txt");
}

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

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


+ 20
- 20
src/intro.c Просмотреть файл

@@ -28,29 +28,29 @@

#include "common.h"

void intro(void)
void intro(game *g)
{
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");
struct cucul_sprite *foo_sprite = cucul_load_sprite(g->qq, "data/foofight.txt");
struct cucul_sprite *bar_sprite = cucul_load_sprite(g->qq, "data/barfight.txt");
struct cucul_sprite *baz_sprite = cucul_load_sprite(g->qq, "data/bazfight.txt");

int frame = 0;

while(caca_get_event(CACA_EVENT_KEY_PRESS) == 0)
while(caca_get_event(g->kk, CACA_EVENT_KEY_PRESS) == 0)
{
int i, xo, yo, x[5], y[5];

frame++;

caca_clear();
cucul_clear(g->qq);

xo = caca_get_width() / 2;
yo = caca_get_height() / 2;
xo = cucul_get_width(g->qq) / 2;
yo = cucul_get_height(g->qq) / 2;

caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
caca_fill_ellipse(xo, yo, 16, 8, '#');
caca_set_color(CACA_COLOR_GREEN, CACA_COLOR_BLACK);
caca_draw_thin_ellipse(xo, yo, 16, 8);
cucul_set_color(g->qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
cucul_fill_ellipse(g->qq, xo, yo, 16, 8, '#');
cucul_set_color(g->qq, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
cucul_draw_thin_ellipse(g->qq, 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];

caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_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(CACA_COLOR_GREEN, CACA_COLOR_BLACK);
caca_draw_thin_polyline(x, y, 4);
cucul_set_color(g->qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
cucul_fill_triangle(g->qq, x[0], y[0], x[1], y[1], x[2], y[2], ' ');
cucul_fill_triangle(g->qq, x[0], y[0], x[3], y[3], x[2], y[2], ' ');
cucul_draw_line(g->qq, x[0], y[0], x[2], y[2], ' ');
cucul_set_color(g->qq, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
cucul_draw_thin_polyline(g->qq, x, y, 4);

caca_draw_sprite(xo, yo, foo_sprite, frame % 5);
cucul_draw_sprite(g->qq, xo, yo, foo_sprite, frame % 5);

caca_refresh();
caca_display(g->kk);

usleep(40000);
}


+ 17
- 13
src/main.c Просмотреть файл

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

srand(time(NULL));

if(caca_init())
{
g->qq = cucul_init();
if(!g->qq)
return 1;

g->kk = caca_attach(g->qq);
if(!g->kk)
return 1;
}

caca_set_delay(40000);
caca_set_delay(g->kk, 40000);

/* Initialize our program */
g->w = caca_get_width();
g->h = caca_get_height();
g->w = cucul_get_width(g->qq);
g->h = cucul_get_height(g->qq);

intro();
intro(g);

/* Go ! */
start_game(g);

/* Clean up */
caca_end();
caca_detach(g->kk);
cucul_end(g->qq);

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

while((event = caca_get_event(CACA_EVENT_KEY_PRESS)))
while((event = caca_get_event(g->kk, CACA_EVENT_KEY_PRESS)))
{
key = event & 0xffffff;

@@ -200,11 +204,11 @@ static void start_game (game *g)
skip = 0;

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

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

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

/* Clear screen */
caca_clear();
cucul_clear(g->qq);

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

/* Refresh */
caca_refresh();
caca_display(g->kk);

purcompteur++;
}


+ 18
- 18
src/overlay.c Просмотреть файл

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

/* Draw life jauge */
caca_set_color(CACA_COLOR_DARKGRAY, CACA_COLOR_BLACK);
caca_putstr(4, 1, dots30);
cucul_set_color(g->qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, 4, 1, dots30);

if(g->p->life > MAX_LIFE * 7 / 10)
{
caca_set_color(CACA_COLOR_GREEN, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
}
else if(g->p->life > MAX_LIFE * 3 / 10)
{
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
}
else
{
caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
}

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

caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(1, 1, "L |");
caca_putstr(34, 1, "|");
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, 1, 1, "L |");
cucul_putstr(g->qq, 34, 1, "|");

/* Draw weapon jauge */
caca_set_color(CACA_COLOR_DARKGRAY, CACA_COLOR_BLACK);
caca_putstr(42, 1, dots30 + 10);
cucul_set_color(g->qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, 42, 1, dots30 + 10);

if(g->p->special > MAX_SPECIAL * 9 / 10)
{
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
}
else if(g->p->special > MAX_SPECIAL * 3 / 10)
{
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
}
else
{
caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
}

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

caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(39, 1, "S |");
caca_putstr(62, 1, "|");
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, 39, 1, "S |");
cucul_putstr(g->qq, 62, 1, "|");
}


+ 3
- 3
src/player.c Просмотреть файл

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

#include "common.h"

struct caca_sprite *ship_sprite;
struct cucul_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 = caca_load_sprite("data/ship.txt");
ship_sprite = cucul_load_sprite(g->qq, "data/ship.txt");

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

caca_draw_sprite(p->x, p->y, ship_sprite, 0);
cucul_draw_sprite(g->qq, p->x, p->y, ship_sprite, 0);
}

void update_player(game *g, player *p)


+ 11
- 11
src/starfield.c Просмотреть файл

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

for(i = 0; i < STARS; i++)
{
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) ? CACA_COLOR_LIGHTGRAY : CACA_COLOR_DARKGRAY;
s[i].ch = caca_rand(0, 1) ? '.' : '\'';
s[i].x = cucul_rand(0, g->w - 1);
s[i].y = cucul_rand(0, g->h - 1);
s[i].z = cucul_rand(1, 3);
s[i].c = cucul_rand(0, 1) ? CUCUL_COLOR_LIGHTGRAY : CUCUL_COLOR_DARKGRAY;
s[i].ch = cucul_rand(0, 1) ? '.' : '\'';
}

return s;
@@ -55,8 +55,8 @@ void draw_starfield(game *g, starfield *s)
{
if(s[i].x >= 0)
{
caca_set_color(s[i].c, CACA_COLOR_BLACK);
caca_putchar(s[i].x, s[i].y, s[i].ch);
cucul_set_color(g->qq, s[i].c, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, 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 = caca_rand(0, g->w - 1);
s[i].x = cucul_rand(0, g->w - 1);
s[i].y = 0;
s[i].z = caca_rand(1, 2);
s[i].c = caca_rand(0, 1) ? CACA_COLOR_LIGHTGRAY : CACA_COLOR_DARKGRAY;
s[i].ch = caca_rand(0, 1) ? '.' : '\'';
s[i].z = cucul_rand(1, 2);
s[i].c = cucul_rand(0, 1) ? CUCUL_COLOR_LIGHTGRAY : CUCUL_COLOR_DARKGRAY;
s[i].ch = cucul_rand(0, 1) ? '.' : '\'';
}
else if(s[i].y < g->h-1)
{


+ 10
- 10
src/tunnel.c Просмотреть файл

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

caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
cucul_set_color(g->qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);

/* 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]) ? '\\' : '<';

caca_putchar(t->left[i] + 1, i, c);
cucul_putchar(g->qq, t->left[i] + 1, i, c);

if(i + 1 < g->h)
for(j = 1; j < t->left[i+1] - t->left[i]; j++)
caca_putchar(t->left[i] + j + 1, i, '_');
cucul_putchar(g->qq, 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++)
caca_putchar(t->right[i+1] + j - 1, i, '_');
cucul_putchar(g->qq, t->right[i+1] + j - 1, i, '_');

caca_putchar(t->right[i] - 1, i, c);
cucul_putchar(g->qq, t->right[i] - 1, i, c);
}

caca_set_color(CACA_COLOR_LIGHTRED, CACA_COLOR_RED);
cucul_set_color(g->qq, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_RED);

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

/* Right concrete */
for(i = 0; i < g->h ; i++)
for(j = t->right[i] ; j < g->w ; j++)
caca_putchar(j, i, '#');
cucul_putchar(g->qq, 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[caca_rand(0,5)];
j = delta[caca_rand(0,5)];
i = delta[cucul_rand(0,5)];
j = delta[cucul_rand(0,5)];

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


+ 115
- 115
src/weapons.c Просмотреть файл

@@ -26,13 +26,13 @@

#include "common.h"

static void draw_bomb(int x, int y, int vx, int vy);
static void draw_nuke(int x, int y, int frame);
static void draw_beam(int x, int y, int frame);
static void draw_fragbomb(int x, int y, int frame);
static void draw_bomb(game *g, int x, int y, int vx, int vy);
static void draw_nuke(game *g, int x, int y, int frame);
static void draw_beam(game *g, int x, int y, int frame);
static void draw_fragbomb(game *g, int x, int y, int frame);

struct caca_sprite *bomb_sprite;
struct caca_sprite *fragbomb_sprite;
struct cucul_sprite *bomb_sprite;
struct cucul_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 = caca_load_sprite("data/wpnbomb.txt");
fragbomb_sprite = caca_load_sprite("data/wpnfrag.txt");
bomb_sprite = cucul_load_sprite(g->qq, "data/wpnbomb.txt");
fragbomb_sprite = cucul_load_sprite(g->qq, "data/wpnfrag.txt");
}

void draw_weapons(game *g, weapons *wp)
@@ -56,35 +56,35 @@ void draw_weapons(game *g, weapons *wp)
switch(wp->type[i])
{
case WEAPON_LASER:
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '|');
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putchar(wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, wp->x[i] >> 4, wp->y[i] >> 4, '|');
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, wp->x[i] >> 4, (wp->y[i] >> 4) + 1, '|');
break;
case WEAPON_SEEKER:
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putchar(wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
caca_putchar(wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putchar(wp->x[i] >> 4, wp->y[i] >> 4, '@');
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
cucul_putchar(g->qq, wp->x2[i] >> 4, wp->y2[i] >> 4, 'o');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, wp->x[i] >> 4, wp->y[i] >> 4, '@');
break;
case WEAPON_BOMB:
caca_set_color(CACA_COLOR_DARKGRAY, CACA_COLOR_BLACK);
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]);
cucul_set_color(g->qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, (wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.');
cucul_putchar(g->qq, (wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.');
cucul_putchar(g->qq, (wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4, '.');
cucul_putchar(g->qq, wp->x3[i] >> 4, wp->y3[i] >> 4, '.');
cucul_putchar(g->qq, wp->x2[i] >> 4, wp->y2[i] >> 4, '.');
draw_bomb(g, wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i]);
break;
case WEAPON_FRAGBOMB:
draw_fragbomb(wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);
draw_fragbomb(g, wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);
break;
case WEAPON_BEAM:
draw_beam(wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);
draw_beam(g, wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);
break;
case WEAPON_NUKE:
draw_nuke(wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);
draw_nuke(g, wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);
break;
case WEAPON_LIGHTNING:
case WEAPON_NONE:
@@ -170,7 +170,7 @@ void update_weapons(game *g, weapons *wp)
/* Normalize direction */
if(dx | dy)
{
unsigned int norm = caca_sqrt(dx * dx + 4 * dy * dy);
unsigned int norm = cucul_sqrt(dx * dx + 4 * dy * dy);
dx = dx * 32 / norm;
dy = dy * 32 / norm;
}
@@ -182,7 +182,7 @@ void update_weapons(game *g, weapons *wp)
/* Normalize speed */
if(dx | dy)
{
unsigned int norm = caca_sqrt(dx * dx + 4 * dy * dy);
unsigned int norm = cucul_sqrt(dx * dx + 4 * dy * dy);
wp->vx[i] = dx * 32 / norm;
wp->vy[i] = dy * 32 / norm;
}
@@ -284,7 +284,7 @@ void add_weapon(game *g, weapons *wp, int x, int y, int vx, int vy, int type)
}
}

static void draw_bomb(int x, int y, int vx, int vy)
static void draw_bomb(game *g, int x, int y, int vx, int vy)
{
int frame;

@@ -334,19 +334,19 @@ static void draw_bomb(int x, int y, int vx, int vy)
}
}

caca_draw_sprite(x, y, bomb_sprite, frame);
cucul_draw_sprite(g->qq, x, y, bomb_sprite, frame);
}

static void draw_fragbomb(int x, int y, int frame)
static void draw_fragbomb(game *g, int x, int y, int frame)
{
/* Draw the head */
caca_draw_sprite(x, y, fragbomb_sprite, frame & 1);
cucul_draw_sprite(g->qq, x, y, fragbomb_sprite, frame & 1);

/* Draw the tail */
caca_draw_sprite(x, y, fragbomb_sprite, 2 + (frame % 4));
cucul_draw_sprite(g->qq, x, y, fragbomb_sprite, 2 + (frame % 4));
}

static void draw_beam(int x, int y, int frame)
static void draw_beam(game *g, int x, int y, int frame)
{
int r = (29 - frame) * (29 - frame) / 8;
int i;
@@ -354,110 +354,110 @@ static void draw_beam(int x, int y, int frame)
switch(frame)
{
case 24:
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x, y-3, "__");
caca_putchar(x-1, y-2, '\'');
caca_putchar(x+2, y-2, '`');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x, y-3, "__");
cucul_putchar(g->qq, x-1, y-2, '\'');
cucul_putchar(g->qq, x+2, y-2, '`');
break;
case 23:
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putstr(x, y-3, "__");
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x-2, y-2, "-'");
caca_putstr(x+2, y-2, "`-");
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x, y-3, "__");
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x-2, y-2, "-'");
cucul_putstr(g->qq, x+2, y-2, "`-");
break;
case 22:
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putstr(x, y-3, "__");
caca_putchar(x-1, y-2, '\'');
caca_putchar(x+2, y-2, '`');
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x-3, y-2, ",-");
caca_putstr(x+3, y-2, "-.");
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x, y-3, "__");
cucul_putchar(g->qq, x-1, y-2, '\'');
cucul_putchar(g->qq, x+2, y-2, '`');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x-3, y-2, ",-");
cucul_putstr(g->qq, x+3, y-2, "-.");
break;
case 21:
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putstr(x-1, y-3, "____");
caca_putchar(x-2, y-2, '\'');
caca_putchar(x+3, y-2, '`');
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x-4, y-2, ",-");
caca_putstr(x+4, y-2, "-.");
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x-1, y-3, "____");
cucul_putchar(g->qq, x-2, y-2, '\'');
cucul_putchar(g->qq, x+3, y-2, '`');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x-4, y-2, ",-");
cucul_putstr(g->qq, x+4, y-2, "-.");
break;
case 20:
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x, y-3, "%%");
caca_putchar(x-4, y-2, ',');
caca_putchar(x+5, y-2, '.');
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putchar(x-1, y-3, ':');
caca_putchar(x+2, y-3, ':');
caca_putstr(x-3, y-2, "-'");
caca_putstr(x+3, y-2, "`-");
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x, y-3, "%%");
cucul_putchar(g->qq, x-4, y-2, ',');
cucul_putchar(g->qq, x+5, y-2, '.');
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-1, y-3, ':');
cucul_putchar(g->qq, x+2, y-3, ':');
cucul_putstr(g->qq, x-3, y-2, "-'");
cucul_putstr(g->qq, x+3, y-2, "`-");
break;
case 19:
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x, y-4, "%%");
caca_putstr(x, y-3, "##");
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
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(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
caca_putchar(x-2, y-3, ':');
caca_putchar(x+3, y-3, ':');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x, y-4, "%%");
cucul_putstr(g->qq, x, y-3, "##");
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-1, y-4, ':');
cucul_putchar(g->qq, x+2, y-4, ':');
cucul_putchar(g->qq, x-1, y-3, '%');
cucul_putchar(g->qq, x+2, y-3, '%');
cucul_putstr(g->qq, x-4, y-2, ",-'");
cucul_putstr(g->qq, x+3, y-2, "`-.");
cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-2, y-3, ':');
cucul_putchar(g->qq, x+3, y-3, ':');
break;
case 18:
default:
r = (18 - frame) * (18 - frame);
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x-1, y-5-r, ":%%:");
caca_putstr(x-1, y-4-r, "%##%");
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
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(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
caca_putchar(x-3, y-2, ':');
caca_putchar(x+4, y-2, ':');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x-1, y-5-r, ":%%:");
cucul_putstr(g->qq, x-1, y-4-r, "%##%");
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-2, y-4-r, ':');
cucul_putchar(g->qq, x+3, y-4-r, ':');
cucul_putchar(g->qq, x-2, y-2, '\'');
cucul_putchar(g->qq, x+3, y-2, '`');
cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-3, y-2, ':');
cucul_putchar(g->qq, x+4, y-2, ':');
for(i = 0; i <= r; i++)
{
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_putstr(x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_putchar(x-2, y-3-i, '%');
caca_putchar(x+3, y-3-i, '%');
caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
caca_putchar(x-3, y-3-i, ':');
caca_putchar(x+4, y-3-i, ':');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(g->qq, x-1, y-3-i, ((i+frame) % 5) ? "####" : "%%%%");
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-2, y-3-i, '%');
cucul_putchar(g->qq, x+3, y-3-i, '%');
cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
cucul_putchar(g->qq, x-3, y-3-i, ':');
cucul_putchar(g->qq, x+4, y-3-i, ':');
}
break;
}
}

static void draw_nuke(int x, int y, int frame)
static void draw_nuke(game *g, int x, int y, int frame)
{
int r = (29 - frame) * (29 - frame) / 8;

/* Lots of duplicate pixels, but we don't care */
caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
caca_draw_ellipse(x, y, r, r / 2, ':');
caca_set_color(CACA_COLOR_LIGHTBLUE, CACA_COLOR_BLUE);
caca_draw_ellipse(x, y, r + 1, r / 2, '#');
caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_LIGHTBLUE);
caca_draw_ellipse(x, y, r + 2, r / 2, '#');
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_LIGHTBLUE);
caca_draw_ellipse(x, y, r + 2, r / 2 + 1, '#');
caca_set_color(CACA_COLOR_LIGHTBLUE, CACA_COLOR_CYAN);
caca_draw_ellipse(x, y, r + 3, r / 2 + 1, '#');
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_CYAN);
caca_draw_ellipse(x, y, r + 3, r / 2 + 2, '#');
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_WHITE);
caca_draw_ellipse(x, y, r + 4, r / 2 + 2, '#');
caca_draw_ellipse(x, y, r + 4, r / 2 + 3, ' ');
cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
cucul_draw_ellipse(g->qq, x, y, r, r / 2, ':');
cucul_set_color(g->qq, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLUE);
cucul_draw_ellipse(g->qq, x, y, r + 1, r / 2, '#');
cucul_set_color(g->qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE);
cucul_draw_ellipse(g->qq, x, y, r + 2, r / 2, '#');
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_LIGHTBLUE);
cucul_draw_ellipse(g->qq, x, y, r + 2, r / 2 + 1, '#');
cucul_set_color(g->qq, CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_CYAN);
cucul_draw_ellipse(g->qq, x, y, r + 3, r / 2 + 1, '#');
cucul_set_color(g->qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_CYAN);
cucul_draw_ellipse(g->qq, x, y, r + 3, r / 2 + 2, '#');
cucul_set_color(g->qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_WHITE);
cucul_draw_ellipse(g->qq, x, y, r + 4, r / 2 + 2, '#');
cucul_draw_ellipse(g->qq, x, y, r + 4, r / 2 + 3, ' ');
}


Загрузка…
Отмена
Сохранить