Ver código fonte

* libee/sprite.c:

+ More robust sprite loader.
    + Added ee_set_sprite_frame() and ee_get_sprite_frame().
    + Free all structures in ee_free_sprite().
  * src/aliens.c src/bonus.c:
    + Use ee_draw_sprite() instead of our manual sprite rendering.
  * src/box.c:
    + Use ee_draw_line() instead of the manual equivalent.
  * data/:
    + Added foo_fighter, baz_fighter, item_gem and item_heart sprites.
tags/v0.99.beta14
Sam Hocevar sam 21 anos atrás
pai
commit
4bb2c01265
10 arquivos alterados com 155 adições e 175 exclusões
  1. +1
    -1
      data/Makefile.am
  2. +28
    -0
      data/baz_fighter
  3. +29
    -0
      data/foo_fighter
  4. +14
    -0
      data/item_gem
  5. +14
    -0
      data/item_heart
  6. +2
    -0
      libee/ee.h
  7. +28
    -0
      libee/sprite.c
  8. +14
    -116
      src/aliens.c
  9. +10
    -22
      src/bonus.c
  10. +15
    -36
      src/box.c

+ 1
- 1
data/Makefile.am Ver arquivo

@@ -1 +1 @@
EXTRA_DIST = bar_fighter bar_boss
EXTRA_DIST = foo_fighter bar_fighter bar_boss baz_fighter item_gem item_heart

+ 28
- 0
data/baz_fighter Ver arquivo

@@ -0,0 +1,28 @@
6 3 2 1
__
/oo\
//'`\\
cc
ceec
cccccc
6 3 2 1
__
/oo\
/(~~)\
cc
ceec
cccccc
6 3 2 1
__
/oo\
((^^))
cc
ceec
cccccc
4 3 1 1
__
/oo\
\\//
cc
ceec
cccc

+ 29
- 0
data/foo_fighter Ver arquivo

@@ -0,0 +1,29 @@
7 3 3 1
. ,
\oXo/
`V'
d d
deded
ddd
9 3 4 1
. ,
`-oXo-'
`V'
d d
ddededd
ddd
9 2 4 0
`--oXo--'
`V'
dddededdd
ddd
9 2 4 0
,-oXo-.
' V `
ddededd
d d d
7 2 3 0
,oXo.
/ V \
deded
d d d

+ 14
- 0
data/item_gem Ver arquivo

@@ -0,0 +1,14 @@
3 2 1 1
_
/g\
\_/
c
cec
ccc
3 2 1 1
_
/g\
\_/
e
eee
eee

+ 14
- 0
data/item_heart Ver arquivo

@@ -0,0 +1,14 @@
5 3 2 1
_ _
( '^)
`v'
h h
hhheh
hhh
5 3 2 1
_ _
( '^)
`v'
e e
eeeee
eee

+ 2
- 0
libee/ee.h Ver arquivo

@@ -87,6 +87,8 @@ int ee_rand(int, int);
int ee_sqrt(int);

struct ee_sprite * ee_load_sprite(const char *);
void ee_set_sprite_frame(struct ee_sprite *, int);
int ee_get_sprite_frame(struct ee_sprite *);
void ee_draw_sprite(int, int, struct ee_sprite *);
void ee_free_sprite(struct ee_sprite *);


+ 28
- 0
libee/sprite.c Ver arquivo

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

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

#include "ee.h"

@@ -87,6 +88,8 @@ struct ee_sprite *ee_load_sprite(const char *file)

for(y = 0; y < h; y++)
{
memset(buf, ' ', w);
buf[w] = '\0';
if(!fgets(buf, BUFSIZ, fd))
goto failed;

@@ -96,6 +99,8 @@ struct ee_sprite *ee_load_sprite(const char *file)

for(y = 0; y < h; y++)
{
memset(buf, ' ', w);
buf[w] = '\0';
if(!fgets(buf, BUFSIZ, fd))
goto failed;

@@ -123,6 +128,19 @@ struct ee_sprite *ee_load_sprite(const char *file)
return sprite;
}

void ee_set_sprite_frame(struct ee_sprite *sprite, int f)
{
if(f < 0 || f >= sprite->nf)
return;

sprite->f = f;
}

int ee_get_sprite_frame(struct ee_sprite *sprite)
{
return sprite->f;
}

void ee_draw_sprite(int x, int y, struct ee_sprite *sprite)
{
int i, j;
@@ -145,6 +163,16 @@ void ee_draw_sprite(int x, int y, struct ee_sprite *sprite)

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

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

free(sprite->frames);
free(sprite);
}


+ 14
- 116
src/aliens.c Ver arquivo

@@ -30,6 +30,10 @@ static void draw_alien_foo(game *, int, int, int);
static void draw_alien_bar(game *, int, int, int);
static void draw_alien_baz(game *, int, int, int);

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

void init_aliens(game *g, aliens *al)
{
int i;
@@ -38,6 +42,10 @@ void init_aliens(game *g, aliens *al)
{
al->type[i] = ALIEN_NONE;
}

foo_sprite = ee_load_sprite("data/foo_fighter");
bar_sprite = ee_load_sprite("data/bar_fighter");
baz_sprite = ee_load_sprite("data/baz_fighter");
}

void draw_aliens(game *g, aliens *al)
@@ -132,130 +140,20 @@ void add_alien(game *g, aliens *al, int x, int y, int type)

static void draw_alien_bar(game *g, int x, int y, int frame)
{
switch(frame)
{
case 0:
ee_color(EE_MAGENTA);
ee_goto(x, y);
ee_putstr(",---.");
ee_goto(x, y+1);
ee_putchar('\\');
ee_color(EE_WHITE);
ee_putstr("o O");
ee_color(EE_MAGENTA);
ee_putchar('/');
ee_goto(x, y+2);
ee_putstr("^^^^^");
break;
case 1:
ee_color(EE_MAGENTA);
ee_goto(x, y);
ee_putstr(",---.");
ee_goto(x, y+1);
ee_putchar('\\');
ee_color(EE_WHITE);
ee_putstr("O o");
ee_color(EE_MAGENTA);
ee_putchar('/');
ee_goto(x, y+2);
ee_putstr("^^^^^");
break;
}
ee_set_sprite_frame(bar_sprite, frame);
ee_draw_sprite(x, y, bar_sprite);
}

static void draw_alien_baz(game *g, int x, int y, int frame)
{
ee_color(EE_GREEN);
ee_goto(x, y-1);
ee_putstr("__");

ee_goto(x-1, y);
ee_putchar('/');
ee_goto(x+2, y);
ee_putchar('\\');

switch(frame)
{
case 3:
ee_goto(x-2, y+1);
ee_putstr("//'`\\\\");
break;
case 4:
case 2:
ee_goto(x-2, y+1);
ee_putstr("/(~~)\\");
break;
case 5:
case 1:
ee_goto(x-2, y+1);
ee_putstr("((^^))");
break;
case 0:
ee_goto(x-1, y+1);
ee_putstr("\\\\//");
break;
}

ee_color(EE_WHITE);
ee_goto(x, y);
ee_putstr("oo");
ee_set_sprite_frame(baz_sprite, frame);
ee_draw_sprite(x, y, baz_sprite);
}

static void draw_alien_foo(game *g, int x, int y, int frame)
{
ee_color(EE_YELLOW);

switch(frame)
{
case 0:
ee_goto(x, y);
ee_putchar('.');
ee_goto(x+6, y);
ee_putchar(',');
ee_goto(x+1, y+1);
ee_putstr("\\ X /");
break;
case 7:
case 1:
ee_goto(x-1, y);
ee_putchar('.');
ee_goto(x+7, y);
ee_putchar(',');
ee_goto(x, y+1);
ee_putstr("`- X -'");
break;
case 6:
case 2:
ee_goto(x-1, y+1);
ee_putstr("`-- X --'");
break;
case 5:
case 3:
ee_goto(x, y+1);
ee_putstr(",- X -.");
ee_goto(x-1, y+2);
ee_putchar('\'');
ee_goto(x+7, y+2);
ee_putchar('`');
break;
case 4:
ee_goto(x+1, y+1);
ee_putstr(", X .");
ee_goto(x, y+2);
ee_putchar('/');
ee_goto(x+6, y+2);
ee_putchar('\\');
break;
}

ee_goto(x+2, y+2);
ee_putstr("`V'");

ee_color(EE_WHITE);
ee_goto(x+2, y+1);
ee_putchar('o');
ee_goto(x+4, y+1);
ee_putchar('o');
ee_set_sprite_frame(foo_sprite, frame);
ee_draw_sprite(x, y, foo_sprite);
}



+ 10
- 22
src/bonus.c Ver arquivo

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

#include "common.h"

struct ee_sprite *heart_sprite;
struct ee_sprite *gem_sprite;

void init_bonus(game *g, bonus *bo)
{
int i;
@@ -34,6 +37,9 @@ void init_bonus(game *g, bonus *bo)
{
bo->type[i] = BONUS_NONE;
}

heart_sprite = ee_load_sprite("data/heart");
gem_sprite = ee_load_sprite("data/gem");
}

void draw_bonus(game *g, bonus *bo)
@@ -45,30 +51,12 @@ void draw_bonus(game *g, bonus *bo)
switch(bo->type[i])
{
case BONUS_GREEN:
ee_color((bo->n[i]/2 % 3) ? EE_GREEN : EE_WHITE);
ee_goto(bo->x[i]+1, bo->y[i]-1);
ee_putchar('_');
ee_goto(bo->x[i], bo->y[i]);
ee_putstr("/ \\");
ee_goto(bo->x[i], bo->y[i]+1);
ee_putstr("\\_/");
ee_color(EE_WHITE);
ee_goto(bo->x[i]+1, bo->y[i]);
ee_putchar('g');
ee_set_sprite_frame(gem_sprite, (bo->n[i]/2 % 3) ? 0 : 1);
ee_draw_sprite(bo->x[i], bo->y[i], gem_sprite);
break;
case BONUS_LIFE:
ee_color((bo->n[i] % 3) ? EE_RED : EE_WHITE);
ee_goto(bo->x[i]+1, bo->y[i]-1);
ee_putchar('_');
ee_goto(bo->x[i]+3, bo->y[i]-1);
ee_putchar('_');
ee_goto(bo->x[i], bo->y[i]);
ee_putstr("( ' )");
ee_goto(bo->x[i]+1, bo->y[i]+1);
ee_putstr("`v'");
ee_color(EE_WHITE);
ee_goto(bo->x[i]+3, bo->y[i]);
ee_putchar('^');
ee_set_sprite_frame(heart_sprite, (bo->n[i] % 3) ? 0 : 1);
ee_draw_sprite(bo->x[i], bo->y[i], heart_sprite);
break;
case BONUS_NONE:
break;


+ 15
- 36
src/box.c Ver arquivo

@@ -41,60 +41,39 @@ box * create_box(game *g, int x, int y, int w, int h)

void draw_box(game *g, box *b)
{
int i, j, frame;
int j, frame;

ee_color(EE_YELLOW);

/* Draw the thin horizontal line */
if(b->frame < 8)
{
for(i = b->x - b->w * b->frame / 16 ;
i < b->x + b->w * b->frame / 16 ;
i++)
{
ee_goto(i, b->y);
ee_putchar('X');
}

ee_draw_line(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;

for(i = b->x - b->w / 2 ;
i < b->x + b->w / 2 ;
i++)
{
ee_goto(i, b->y - b->h * (frame - 8) / 8);
ee_putchar('X');
ee_goto(i, b->y + b->h * (frame - 8) / 8);
ee_putchar('X');
}
ee_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,
b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8, 'X');

for(j = b->y - b->h * (frame - 8) / 8 ;
j < b->y + b->h * (frame - 8) / 8 ;
j++)
{
ee_goto(b->x - b->w / 2, j);
ee_putchar('X');
ee_goto(b->x + b->w / 2 - 1, j);
ee_putchar('X');
}
ee_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,
b->x + b->w / 2 - 1, b->y + b->h * (frame - 8) / 8 - 1, 'X');

ee_color(EE_BLACK);

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

if(b->frame < 12)


Carregando…
Cancelar
Salvar