diff --git a/data/Makefile.am b/data/Makefile.am index bc36072..ccb1e39 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1 +1,10 @@ -EXTRA_DIST = foo_fighter bar_fighter bar_boss baz_fighter item_gem item_heart +EXTRA_DIST = \ + foo_fighter \ + bar_fighter \ + bar_boss \ + baz_fighter \ + explosion_medium \ + explosion_small \ + item_gem \ + item_heart \ + $(NULL) diff --git a/data/explosion_medium b/data/explosion_medium new file mode 100644 index 0000000..722876b --- /dev/null +++ b/data/explosion_medium @@ -0,0 +1,60 @@ +1 1 0 0 ++ +d +1 1 0 0 +o +d +3 2 1 1 + _ +)_( + d +ddd +3 3 1 1 +._, +)_( +' ` +ddd +ddd +ddd +3 3 1 1 +.v, +> < +'^` +ddd +ddd +ddd +5 3 2 1 +_\~/_ +> < +~/_\~ +fffff +fffff +fffff +5 3 2 1 +_\~/_ +> < +~/_\~ +ddddd +ddddd +ddddd +5 3 2 1 +_\ /_ + +~/ \~ +fffff +fffff +fffff +5 3 2 1 +_\ /_ + +~/ \~ +ddddd +ddddd +ddddd +5 3 2 1 +. ' , + +' . ` +eeeee +eeeee +eeeee diff --git a/data/explosion_small b/data/explosion_small new file mode 100644 index 0000000..6829ebe --- /dev/null +++ b/data/explosion_small @@ -0,0 +1,32 @@ +1 1 0 0 ++ +d +1 1 0 0 +o +d +3 2 1 1 + _ +)_( + d +ddd +3 3 1 1 +._, +)_( +' ` +ddd +ddd +ddd +3 3 1 1 +.v, +> < +'^` +ddd +ddd +ddd +3 3 1 1 +. , + +' ` +ddd +ddd +ddd diff --git a/libee/sprite.c b/libee/sprite.c index 78fcb4f..0befb36 100644 --- a/libee/sprite.c +++ b/libee/sprite.c @@ -88,24 +88,26 @@ 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; - for(x = 0; x < w; x++) + for(x = 0; x < w && buf[x] && buf[x] != '\r' && buf[x] != '\n'; x++) frame->chars[w * y + x] = buf[x]; + + for(; x < w; x++) + frame->chars[w * y + x] = ' '; } for(y = 0; y < h; y++) { - memset(buf, ' ', w); - buf[w] = '\0'; if(!fgets(buf, BUFSIZ, fd)) goto failed; - for(x = 0; x < w; x++) + for(x = 0; x < w && buf[x] && buf[x] != '\r' && buf[x] != '\n'; x++) frame->color[w * y + x] = buf[x] - 'a'; + + for(; x < w; x++) + frame->color[w * y + x] = ' ' - 'a'; } continue; diff --git a/src/explosions.c b/src/explosions.c index 03ea3c5..9081f25 100644 --- a/src/explosions.c +++ b/src/explosions.c @@ -29,6 +29,9 @@ static void draw_small_explosion(int x, int y, int frame); static void draw_medium_explosion(int x, int y, int frame); +struct ee_sprite *medium_sprite; +struct ee_sprite *small_sprite; + void init_explosions(game *g, explosions *ex) { int i; @@ -37,6 +40,9 @@ void init_explosions(game *g, explosions *ex) { ex->type[i] = EXPLOSION_NONE; } + + medium_sprite = ee_load_sprite("data/explosion_medium"); + small_sprite = ee_load_sprite("data/explosion_small"); } void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type) @@ -137,120 +143,13 @@ void update_explosions(game *g, explosions *ex) static void draw_small_explosion(int x, int y, int frame) { - switch(frame) - { - case 6: - ee_color(EE_YELLOW); - ee_goto(x, y); - ee_putchar('+'); - break; - case 5: - ee_color(EE_YELLOW); - ee_goto(x, y); - ee_putchar('o'); - break; - case 4: - ee_color(EE_YELLOW); - ee_goto(x, y-1); - ee_putchar('_'); - ee_goto(x-1, y); - ee_putstr(")_("); - break; - case 3: - ee_color(EE_YELLOW); - ee_goto(x-1, y-1); - ee_putstr("._,"); - ee_goto(x-1, y); - ee_putstr(")_("); - ee_goto(x-1, y+1); - ee_putstr("\' `"); - break; - case 2: - ee_color(EE_YELLOW); - ee_goto(x-1, y-1); - ee_putstr(".v,"); - ee_goto(x-1, y); - ee_putstr("> <"); - ee_goto(x-1, y+1); - ee_putstr("\'^`"); - break; - case 1: - ee_color(EE_WHITE); - ee_goto(x-1, y-1); - ee_putstr(". ,"); - ee_goto(x-1, y); - ee_putstr(" "); - ee_goto(x-1, y+1); - ee_putstr("\' `"); - break; - } + ee_set_sprite_frame(small_sprite, 6 - frame); + ee_draw_sprite(x, y, small_sprite); } static void draw_medium_explosion(int x, int y, int frame) { - ee_color(EE_YELLOW); - - switch(frame) - { - case 10: - ee_goto(x, y); - ee_putchar('+'); - break; - case 9: - ee_goto(x, y); - ee_putchar('o'); - break; - case 8: - ee_goto(x, y-1); - ee_putchar('_'); - ee_goto(x-1, y); - ee_putstr(")_("); - break; - case 7: - ee_goto(x-1, y-1); - ee_putstr("._,"); - ee_goto(x-1, y); - ee_putstr(")_("); - ee_goto(x-1, y+1); - ee_putstr("\' `"); - break; - case 6: - ee_goto(x-1, y-1); - ee_putstr(".v,"); - ee_goto(x-1, y); - ee_putstr("> <"); - ee_goto(x-1, y+1); - ee_putstr("\'^`"); - break; - case 5: - ee_color(EE_RED); - case 4: - ee_goto(x-2, y-1); - ee_putstr("_\\~/_"); - ee_goto(x-2, y); - ee_putstr("> <"); - ee_goto(x-2, y+1); - ee_putstr("~/_\\~"); - break; - case 3: - ee_color(EE_RED); - case 2: - ee_goto(x-2, y-1); - ee_putstr("_\\ /_"); - ee_goto(x-2, y); - ee_putstr("_ _"); - ee_goto(x-2, y+1); - ee_putstr(" / \\ "); - break; - case 1: - ee_color(EE_WHITE); - ee_goto(x-2, y-1); - ee_putstr(". \' ,"); - ee_goto(x-2, y); - ee_putstr(" "); - ee_goto(x-2, y+1); - ee_putstr("\' . `"); - break; - } + ee_set_sprite_frame(medium_sprite, 10 - frame); + ee_draw_sprite(x, y, medium_sprite); }