|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: bomb.c,v 1.65 2006/12/15 18:51:01 stpohle Exp $ */
|
|
|
|
|
/* $Id: bomb.c,v 1.66 2007/01/12 11:15:44 stpohle Exp $ */
|
|
|
|
|
/* everything what have to do with the bombs */
|
|
|
|
|
|
|
|
|
|
#include "bomberclone.h"
|
|
|
|
@ -9,19 +9,11 @@
|
|
|
|
|
void
|
|
|
|
|
draw_bomb (_bomb * bomb)
|
|
|
|
|
{
|
|
|
|
|
SDL_Rect src,
|
|
|
|
|
dest;
|
|
|
|
|
int x = floorf (bomb->pos.x),
|
|
|
|
|
y = floorf (bomb->pos.y);
|
|
|
|
|
float w,
|
|
|
|
|
x1,
|
|
|
|
|
x2,
|
|
|
|
|
y1,
|
|
|
|
|
y2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (x < 0 || y < 0 || x >= map.size.x || y >= map.size.y) {
|
|
|
|
|
d_printf ("FATAL: Draw Bomb out of range [%f,%f]\n", x, y);
|
|
|
|
|
SDL_Rect src, dest;
|
|
|
|
|
int x = floorf (bomb->oldpos.x), y = floorf (bomb->oldpos.y);
|
|
|
|
|
|
|
|
|
|
if (bomb->pos.x < 0 || bomb->pos.y < 0 || bomb->pos.x >= map.size.x || bomb->pos.y >= map.size.y) {
|
|
|
|
|
d_printf ("FATAL: Draw Bomb out of range [%f,%f]\n", bomb->pos.x, bomb->pos.y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -36,59 +28,27 @@ draw_bomb (_bomb * bomb)
|
|
|
|
|
|
|
|
|
|
dest.w = src.w = gfx.bomb.image->w;
|
|
|
|
|
dest.h = src.h = gfx.block.y;
|
|
|
|
|
if (bomb->mode == BM_kicked) {
|
|
|
|
|
/*
|
|
|
|
|
* draw the kicked bomb
|
|
|
|
|
*/
|
|
|
|
|
w = sqrt (bomb->speed);
|
|
|
|
|
w *= absol (sin (w));
|
|
|
|
|
x1 = bomb->dest.x - bomb->pos.x;
|
|
|
|
|
y1 = bomb->dest.y - bomb->pos.y;
|
|
|
|
|
if (x1 > 0) {
|
|
|
|
|
x2 = bomb->pos.x + x1 * bomb->speed / 88 + y1 * w / 20;
|
|
|
|
|
y2 = bomb->pos.y + y1 * bomb->speed / 88 - x1 * w / 20;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
x2 = bomb->pos.x + x1 * bomb->speed / 88 - y1 * w / 20;
|
|
|
|
|
y2 = bomb->pos.y + y1 * bomb->speed / 88 + x1 * w / 20;
|
|
|
|
|
}
|
|
|
|
|
x = floorf (x2);
|
|
|
|
|
y = floorf (y2);
|
|
|
|
|
bomb->speed -= timediff * 100;
|
|
|
|
|
if (bomb->speed < 0) {
|
|
|
|
|
dest.x = gfx.offset.x + bomb->pos.x * gfx.block.x;
|
|
|
|
|
dest.y = gfx.offset.y + bomb->pos.y * gfx.block.y;
|
|
|
|
|
bomb->mode = BM_normal;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
w = sqrt (bomb->speed);
|
|
|
|
|
w *= absol (sin (w));
|
|
|
|
|
if (x1 > 0) {
|
|
|
|
|
x2 = bomb->pos.x + x1 * bomb->speed / 88 + y1 * w / 20;
|
|
|
|
|
y2 = bomb->pos.y + y1 * bomb->speed / 88 - x1 * w / 20;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
x2 = bomb->pos.x + x1 * bomb->speed / 88 - y1 * w / 20;
|
|
|
|
|
y2 = bomb->pos.y + y1 * bomb->speed / 88 + x1 * w / 20;
|
|
|
|
|
}
|
|
|
|
|
dest.x = gfx.offset.x + x2 * gfx.block.x;
|
|
|
|
|
dest.y = gfx.offset.y + y2 * gfx.block.y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
dest.x = gfx.offset.x + bomb->pos.x * gfx.block.x;
|
|
|
|
|
dest.y = gfx.offset.y + bomb->pos.y * gfx.block.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
src.x = 0;
|
|
|
|
|
src.y = src.h * (int) bomb->frame;
|
|
|
|
|
|
|
|
|
|
/* delete the old position of the bomb */
|
|
|
|
|
if (bomb->oldpos.x >= 0.0f && bomb->oldpos.y >= 0.0f) {
|
|
|
|
|
stonelist_add (x, y);
|
|
|
|
|
if (bomb->mode != BM_normal) {
|
|
|
|
|
stonelist_add (x + 1, y);
|
|
|
|
|
stonelist_add (x, y + 1);
|
|
|
|
|
stonelist_add (x + 1, y + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
stonelist_add (bomb->pos.x, bomb->pos.y);
|
|
|
|
|
|
|
|
|
|
/* save the current position */
|
|
|
|
|
bomb->oldpos = bomb->pos;
|
|
|
|
|
|
|
|
|
|
gfx_blit (gfx.bomb.image, &src, gfx.screen, &dest, (y * 256) + 2);
|
|
|
|
|
};
|
|
|
|
@ -172,8 +132,8 @@ bomb_move (_bomb * bomb)
|
|
|
|
|
fpos.y += 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (step > (timefactor * bomb->speed) || step == 0.0f)
|
|
|
|
|
step = (timefactor * bomb->speed);
|
|
|
|
|
if (step > (timefactor * bomb->fdata) || step == 0.0f)
|
|
|
|
|
step = (timefactor * bomb->fdata);
|
|
|
|
|
|
|
|
|
|
/* move the bomb to the new position */
|
|
|
|
|
if (bomb->dest.x < 0)
|
|
|
|
@ -235,7 +195,7 @@ bomb_move (_bomb * bomb)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dist += step;
|
|
|
|
|
} while (dist < (timefactor * bomb->speed)
|
|
|
|
|
} while (dist < (timefactor * bomb->fdata)
|
|
|
|
|
&& (bomb->mode == BM_liquid || bomb->mode == BM_moving) && keepdir);
|
|
|
|
|
|
|
|
|
|
map.bfield[(int) bomb->pos.x][(int) bomb->pos.y] = 1; /* set new bfield */
|
|
|
|
@ -278,10 +238,11 @@ bomb_loop ()
|
|
|
|
|
}
|
|
|
|
|
draw_bomb (bomb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* if the bomb is moving or something...
|
|
|
|
|
*/
|
|
|
|
|
if (bomb->mode != BM_normal)
|
|
|
|
|
bomb_action (bomb);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BS_exploding:
|
|
|
|
@ -292,6 +253,7 @@ bomb_loop ()
|
|
|
|
|
explosion_restore (bomb);
|
|
|
|
|
bomb->to = 0.0f;
|
|
|
|
|
bomb->state = BS_off;
|
|
|
|
|
bomb->oldpos.x = bomb->oldpos.y = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
bomb->to -= timediff;
|
|
|
|
|
break;
|
|
|
|
@ -305,9 +267,7 @@ bomb_loop ()
|
|
|
|
|
|
|
|
|
|
/* check if on the givin place is a bomb
|
|
|
|
|
bombs[].x = player, bombs[].y = bombnumber */
|
|
|
|
|
void
|
|
|
|
|
get_bomb_on (float x, float y, _point bombs[])
|
|
|
|
|
{
|
|
|
|
|
void get_bomb_on (float x, float y, _point bombs[]) {
|
|
|
|
|
int p,
|
|
|
|
|
b,
|
|
|
|
|
i;
|
|
|
|
@ -350,6 +310,7 @@ void explosion_restore (_bomb *bomb) {
|
|
|
|
|
if (map.field[_x][_y].ex[d].count > 0)
|
|
|
|
|
map.field[_x][_y].ex[d].count--;
|
|
|
|
|
map.field[_x][_y].ex[d].frame = 0.0f; // reset the framenumber
|
|
|
|
|
/* refresh the screen here.. */
|
|
|
|
|
if (d==3)
|
|
|
|
|
stonelist_add (_x, _y);
|
|
|
|
|
|
|
|
|
@ -391,7 +352,7 @@ void explosion_restore (_bomb *bomb) {
|
|
|
|
|
|
|
|
|
|
/* delete field from the bfield map */
|
|
|
|
|
if (bomb->mode == BM_moving || bomb->mode == BM_pushed || bomb->mode == BM_liquid)
|
|
|
|
|
map.bfield[(int) bomb->pos.x + bomb->dest.x][(int) bomb->pos.y + bomb->dest.y] = 0;
|
|
|
|
|
map.bfield[(int) bomb->pos.x + (int)bomb->dest.x][(int) bomb->pos.y + (int)bomb->dest.y] = 0;
|
|
|
|
|
|
|
|
|
|
map.bfield[(int) bomb->pos.x][(int) bomb->pos.y] = 0;
|
|
|
|
|
};
|
|
|
|
@ -426,7 +387,6 @@ explosion_draw (_bomb * bomb)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* calculate the explosion itself,
|
|
|
|
|
* check the direction of the explosion and and and
|
|
|
|
@ -457,7 +417,6 @@ void explosion_do (_bomb *bomb) {
|
|
|
|
|
step = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
bomb->firer[d] += step;
|
|
|
|
|
// printf ("d:%d, Cur_Range:%f New_Range:%f\n", d, bomb->firer[d], new_range);
|
|
|
|
|
|
|
|
|
|
dx = rintf(bomb->pos.x + dir_change[d].x * bomb->firer[d]);
|
|
|
|
|
dy = rintf(bomb->pos.y + dir_change[d].y * bomb->firer[d]);
|
|
|
|
@ -507,7 +466,8 @@ int explosion_check_field (int x, int y, _bomb *bomb)
|
|
|
|
|
/* check if any bomb have to explode.. */
|
|
|
|
|
for (i = 0; bo[i].x != -1; i++) {
|
|
|
|
|
tmpbomb = &players[bo[i].x].bombs[bo[i].y];
|
|
|
|
|
if (tmpbomb != bomb && tmpbomb->state != BS_exploding) {
|
|
|
|
|
if (tmpbomb != bomb && tmpbomb->state != BS_exploding
|
|
|
|
|
&& tmpbomb->mode != BM_kicked) {
|
|
|
|
|
tmpbomb->ex_nr = bomb->ex_nr; // set the ex_nr to identify explosions
|
|
|
|
|
bomb_explode (tmpbomb, 1);
|
|
|
|
|
}
|
|
|
|
@ -536,10 +496,38 @@ int explosion_check_field (int x, int y, _bomb *bomb)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* the bomb was kicked.. so move the bomb in the right way..
|
|
|
|
|
*/
|
|
|
|
|
void bomb_kicked (_bomb * bomb) {
|
|
|
|
|
float dist, dX, dY, pX, pY;
|
|
|
|
|
|
|
|
|
|
pX = dX = bomb->dest.x - bomb->source.x;
|
|
|
|
|
pY = dY = bomb->dest.y - bomb->source.y;
|
|
|
|
|
if (pX < 0.0f) pX = -dX;
|
|
|
|
|
if (pY < 0.0f) pY = -dY;
|
|
|
|
|
if (pX == 0.0f) dist = pY;
|
|
|
|
|
else if (pY == 0.0f) dist = pX;
|
|
|
|
|
else {
|
|
|
|
|
dist = sqrtf (powf (pX,2) + powf (pY,2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bomb->fdata += timediff; // * (SPECIAL_KICK_MAXDIST / dist);
|
|
|
|
|
if (bomb->fdata >= 1.0f) {
|
|
|
|
|
bomb->pos.x = bomb->dest.x;
|
|
|
|
|
bomb->pos.y = bomb->dest.y;
|
|
|
|
|
bomb->mode = BM_normal;
|
|
|
|
|
bomb->fdata = 0.0f;
|
|
|
|
|
map.bfield[(int)bomb->dest.x][(int)bomb->dest.y] = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bomb->pos.x = bomb->source.x + dX * bomb->fdata;
|
|
|
|
|
bomb->pos.y = (bomb->source.y + dY * bomb->fdata) - (4.0-(4.0 * powf ((-0.5+bomb->fdata)*2.0f, 2.0f)));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
|
|
|
|
bomb_action (_bomb * bomb)
|
|
|
|
|
inline void bomb_action (_bomb * bomb)
|
|
|
|
|
{
|
|
|
|
|
switch (bomb->mode) {
|
|
|
|
|
case (BM_moving):
|
|
|
|
@ -548,6 +536,7 @@ bomb_action (_bomb * bomb)
|
|
|
|
|
bomb_move (bomb);
|
|
|
|
|
break;
|
|
|
|
|
case (BM_kicked):
|
|
|
|
|
bomb_kicked (bomb);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
bomb->mode = BM_normal;
|
|
|
|
|