|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: field.c,v 1.23 2003/06/01 22:57:10 stpohle Exp $ */
|
|
|
|
/* $Id: field.c,v 1.24 2003/06/01 23:08:34 stpohle Exp $ */
|
|
|
|
/* field.c - procedures which are needed to control the field */
|
|
|
|
/* field.c - procedures which are needed to control the field */
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
@ -41,15 +41,7 @@ draw_stone (int x, int y)
|
|
|
|
|
|
|
|
|
|
|
|
/* animate the stone if needed only for exploding stone */
|
|
|
|
/* animate the stone if needed only for exploding stone */
|
|
|
|
if (stone->type == FT_stone && stone->frame > 0) {
|
|
|
|
if (stone->type == FT_stone && stone->frame > 0) {
|
|
|
|
field_animation_add (x, y);
|
|
|
|
field_animation_add (x, y);
|
|
|
|
if (stone->frameto == 0)
|
|
|
|
|
|
|
|
if (stone->frame < gfx.field[stone->type].frames) {
|
|
|
|
|
|
|
|
stone->frame++;
|
|
|
|
|
|
|
|
stone->frameto = ANI_STONETIMEOUT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->frameto > 0)
|
|
|
|
|
|
|
|
stone->frameto--;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->frame < gfx.field[FT_stone].frames) {
|
|
|
|
if (stone->frame < gfx.field[FT_stone].frames) {
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
@ -59,46 +51,38 @@ draw_stone (int x, int y)
|
|
|
|
src.y = 0;
|
|
|
|
src.y = 0;
|
|
|
|
srcimg = gfx.field[FT_nothing].image;
|
|
|
|
srcimg = gfx.field[FT_nothing].image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (stone->type == FT_stone || stone->type == FT_block) {
|
|
|
|
else if (stone->type == FT_stone || stone->type == FT_block) {
|
|
|
|
src.y = 0;
|
|
|
|
src.y = 0;
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* some powerup so we need to animate this too */
|
|
|
|
/* some powerup so we need to animate this too */
|
|
|
|
else if (stone->type >= FT_death) {
|
|
|
|
else if (stone->type >= FT_death) {
|
|
|
|
field_animation_add (x, y);
|
|
|
|
field_animation_add (x, y);
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->frameto-- <= 0 || stone->frameto > ANI_STONETIMEOUT) {
|
|
|
|
srcimg = gfx.powerup.image;
|
|
|
|
stone->frameto = ANI_STONETIMEOUT;
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
|
stone->frame++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (srcimg != NULL)
|
|
|
|
if (stone->frame >= gfx.powerup.frames)
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
stone->frame = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->type >= FT_death) { /* draw now the powerup itself */
|
|
|
|
srcimg = gfx.powerup.image;
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
src.y = stone->frame * gfx.block.y;
|
|
|
|
src.y = 0;
|
|
|
|
}
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (srcimg != NULL)
|
|
|
|
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stone->type >= FT_death) { /* draw now the powerup itself */
|
|
|
|
|
|
|
|
srcimg = gfx.field[stone->type].image;
|
|
|
|
|
|
|
|
src.y = 0;
|
|
|
|
|
|
|
|
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// draw explosions if there is any
|
|
|
|
// draw explosions if there is any
|
|
|
|
for (d = 0, i = 0; d < 4; d++)
|
|
|
|
for (d = 0, i = 0; d < 4; d++)
|
|
|
|
if (stone->ex[d].count > 0) {
|
|
|
|
if (stone->ex[d].count > 0) {
|
|
|
|
i = 1; // mark that there is already an explosion
|
|
|
|
i = 1; // mark that there is already an explosion
|
|
|
|
draw_fire (x, y, d, -1);
|
|
|
|
draw_fire (x, y, d, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -441,45 +425,73 @@ field_new (char *filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* run this to every game cycle for the animations on the field */
|
|
|
|
/* run this to every game cycle for the animations on the field */
|
|
|
|
void field_animation () {
|
|
|
|
void
|
|
|
|
int i;
|
|
|
|
field_animation ()
|
|
|
|
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_FILEDANIMATION; i++)
|
|
|
|
int i;
|
|
|
|
if (fieldani[i].x >= 0 && fieldani[i].x < bman.fieldsize.x && fieldani[i].y >= 0 && fieldani[i].y < bman.fieldsize.y) {
|
|
|
|
|
|
|
|
/* check if there is a need to animate this */
|
|
|
|
for (i = 0; i < MAX_FILEDANIMATION; i++)
|
|
|
|
if ((bman.field[fieldani[i].x][fieldani[i].y].type == FT_stone && bman.field[fieldani[i].x][fieldani[i].y].frame > 0) ||
|
|
|
|
if (fieldani[i].x >= 0 && fieldani[i].x < bman.fieldsize.x && fieldani[i].y >= 0
|
|
|
|
(bman.field[fieldani[i].x][fieldani[i].y].type >= FT_death)) {
|
|
|
|
&& fieldani[i].y < bman.fieldsize.y) {
|
|
|
|
/* animate this stone */
|
|
|
|
/* check if there is a need to animate this */
|
|
|
|
draw_stone (fieldani[i].x, fieldani[i].y);
|
|
|
|
if ((bman.field[fieldani[i].x][fieldani[i].y].type == FT_stone
|
|
|
|
field_update (fieldani[i].x, fieldani[i].y);
|
|
|
|
&& bman.field[fieldani[i].x][fieldani[i].y].frame > 0)
|
|
|
|
}
|
|
|
|
|| (bman.field[fieldani[i].x][fieldani[i].y].type >= FT_death)) {
|
|
|
|
else /* delete this entry */
|
|
|
|
/* animate this stone */
|
|
|
|
fieldani[i].y = fieldani[i].x = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (bman.field[fieldani[i].x][fieldani[i].y].type == FT_stone) {
|
|
|
|
else /* delete this entry */
|
|
|
|
if (bman.field[fieldani[i].x][fieldani[i].y].frameto == 0)
|
|
|
|
fieldani[i].y = fieldani[i].x = -1;
|
|
|
|
if (bman.field[fieldani[i].x][fieldani[i].y].frame < gfx.field[FT_stone].frames) {
|
|
|
|
|
|
|
|
bman.field[fieldani[i].x][fieldani[i].y].frame++;
|
|
|
|
|
|
|
|
bman.field[fieldani[i].x][fieldani[i].y].frameto = ANI_STONETIMEOUT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bman.field[fieldani[i].x][fieldani[i].y].frameto > 0)
|
|
|
|
|
|
|
|
bman.field[fieldani[i].x][fieldani[i].y].frameto--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (bman.field[fieldani[i].x][fieldani[i].y].frameto-- <= 0 || bman.field[fieldani[i].x][fieldani[i].y].frameto > ANI_STONETIMEOUT) {
|
|
|
|
|
|
|
|
bman.field[fieldani[i].x][fieldani[i].y].frameto = ANI_STONETIMEOUT;
|
|
|
|
|
|
|
|
bman.field[fieldani[i].x][fieldani[i].y].frame++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bman.field[fieldani[i].x][fieldani[i].y].frame >= gfx.powerup.frames)
|
|
|
|
|
|
|
|
bman.field[fieldani[i].x][fieldani[i].y].frame = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_stone (fieldani[i].x, fieldani[i].y);
|
|
|
|
|
|
|
|
field_update (fieldani[i].x, fieldani[i].y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else /* delete this entry */
|
|
|
|
|
|
|
|
fieldani[i].y = fieldani[i].x = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else /* delete this entry */
|
|
|
|
|
|
|
|
fieldani[i].y = fieldani[i].x = -1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* add a new field to the animation data */
|
|
|
|
/* add a new field to the animation data */
|
|
|
|
void field_animation_add (int x, int y) {
|
|
|
|
void
|
|
|
|
int i, j = -1, d = -1;
|
|
|
|
field_animation_add (int x, int y)
|
|
|
|
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAX_FILEDANIMATION; i++) {
|
|
|
|
int i,
|
|
|
|
if (fieldani[i].x == x && fieldani[i].y == y)
|
|
|
|
j = -1,
|
|
|
|
d = i;
|
|
|
|
d = -1;
|
|
|
|
if (fieldani[i].x == -1 || fieldani[i].y == -1)
|
|
|
|
|
|
|
|
j = i;
|
|
|
|
for (i = 0; i < MAX_FILEDANIMATION; i++) {
|
|
|
|
}
|
|
|
|
if (fieldani[i].x == x && fieldani[i].y == y)
|
|
|
|
|
|
|
|
d = i;
|
|
|
|
if (j == -1) { /* nothing anymore free */
|
|
|
|
if (fieldani[i].x == -1 || fieldani[i].y == -1)
|
|
|
|
d_printf ("field_animation_add: animation data line too full\n");
|
|
|
|
j = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (j == -1) { /* nothing anymore free */
|
|
|
|
if (d != -1) /* this stone is already in the list */
|
|
|
|
d_printf ("field_animation_add: animation data line too full\n");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
fieldani[j].x = x;
|
|
|
|
|
|
|
|
fieldani[j].y = y;
|
|
|
|
if (d != -1) /* this stone is already in the list */
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldani[j].x = x;
|
|
|
|
|
|
|
|
fieldani[j].y = y;
|
|
|
|
};
|
|
|
|
};
|
|
|
|