|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: bomb.c,v 1.40 2003/08/25 15:07:25 stpohle Exp $ */
|
|
|
|
|
/* $Id: bomb.c,v 1.41 2003/08/27 21:14:50 stpohle Exp $ */
|
|
|
|
|
/* everything what have to do with the bombs */
|
|
|
|
|
|
|
|
|
|
#include "bomberclone.h"
|
|
|
|
@ -36,7 +36,7 @@ draw_bomb (_bomb * bomb)
|
|
|
|
|
src.x = 0;
|
|
|
|
|
src.y = src.h * bomb->frame;
|
|
|
|
|
stonelist_add (x>>8, y>>8);
|
|
|
|
|
if (bomb->moves) {
|
|
|
|
|
if (bomb->mode != BM_normal) {
|
|
|
|
|
stonelist_add ((x>>8)+1, y>>8);
|
|
|
|
|
stonelist_add (x>>8, (y>>8)+1);
|
|
|
|
|
stonelist_add ((x>>8)+1, (y>>8)+1);
|
|
|
|
@ -73,76 +73,60 @@ bomb_explode (int p, int b, int net)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* moves the bomb with it's speed,
|
|
|
|
|
dest.x|y = dx, dy of the current move */
|
|
|
|
|
void
|
|
|
|
|
bomb_move (_bomb * bomb)
|
|
|
|
|
{
|
|
|
|
|
_point npos;
|
|
|
|
|
int dx = 0,
|
|
|
|
|
dy = 0;
|
|
|
|
|
float vec;
|
|
|
|
|
int step = 0, dist = 0, keepdir = 0;
|
|
|
|
|
_point fpos, rpos;
|
|
|
|
|
|
|
|
|
|
if (bomb->moveto.x < 0) {
|
|
|
|
|
switch (bomb->moveto.x) {
|
|
|
|
|
case -1:
|
|
|
|
|
case -2:
|
|
|
|
|
dx = -bomb->moves; //move bomb left
|
|
|
|
|
case -3:
|
|
|
|
|
case -4:
|
|
|
|
|
dx = bomb->moves; //move bomb right
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dx = bomb->moveto.x - bomb->pos.x; //move bomb to field
|
|
|
|
|
}
|
|
|
|
|
if (bomb->moveto.y < 0) {
|
|
|
|
|
switch (bomb->moveto.y) {
|
|
|
|
|
case -1:
|
|
|
|
|
case -2:
|
|
|
|
|
dy = -bomb->moves; //move bomb up
|
|
|
|
|
case -3:
|
|
|
|
|
case -4:
|
|
|
|
|
dy = bomb->moves; //move bomb down
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dy = bomb->moveto.y - bomb->pos.y; //move bomb to field
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dx && !dy) { // bomb has reached its final position
|
|
|
|
|
bomb->moves = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// calculate movement
|
|
|
|
|
if (abs(dx)>bomb->moves || abs(dy)>bomb->moves) {
|
|
|
|
|
vec=sqrt(dx*dx+dy*dy);
|
|
|
|
|
dx=dx*bomb->moves/vec;
|
|
|
|
|
dy=dy*bomb->moves/vec;
|
|
|
|
|
}
|
|
|
|
|
npos.x=bomb->pos.x+dx;
|
|
|
|
|
npos.y=bomb->pos.y+dy;
|
|
|
|
|
|
|
|
|
|
// check if field is used
|
|
|
|
|
/*
|
|
|
|
|
if (!(dx && dy)) {
|
|
|
|
|
fpos.x=npos.x>>8;
|
|
|
|
|
fpos.y=npos.y>>8;
|
|
|
|
|
if (((npos.x & 0xff ) >0) && (dx>0)) fpos.x++;
|
|
|
|
|
if (((npos.y & 0xff ) >0) && (dy>0)) fpos.y++;
|
|
|
|
|
if (bman.bfield[fpos.x][fpos.y] || bman.field[fpos.x][fpos.y].type != FT_nothing) {
|
|
|
|
|
npos.x &= 0xff00;
|
|
|
|
|
npos.y &= 0xff00;
|
|
|
|
|
if (dx<0) npos.x+=0x100;
|
|
|
|
|
if (dy<0) npos.y+=0x100;
|
|
|
|
|
}
|
|
|
|
|
/* do this once, and again if the direction is still ok */
|
|
|
|
|
do {
|
|
|
|
|
/* get the current position of the bomb */
|
|
|
|
|
fpos.x = bomb->pos.x >> 8;
|
|
|
|
|
fpos.y = bomb->pos.y >> 8;
|
|
|
|
|
rpos.x = bomb->pos.x & 0xFF;
|
|
|
|
|
rpos.y = bomb->pos.y & 0xFF;
|
|
|
|
|
|
|
|
|
|
/* calculate the next step speed or next full field..
|
|
|
|
|
depend on what is the smaler one */
|
|
|
|
|
if (bomb->dest.x < 0)
|
|
|
|
|
step = rpos.x;
|
|
|
|
|
else if (bomb->dest.x > 0)
|
|
|
|
|
step = 0x100 - rpos.x;
|
|
|
|
|
else if (bomb->dest.y < 0)
|
|
|
|
|
step = rpos.y;
|
|
|
|
|
else if (bomb->dest.y > 0)
|
|
|
|
|
step = 0x100 - rpos.y;
|
|
|
|
|
|
|
|
|
|
if (step > bomb->speed || step == 0)
|
|
|
|
|
step = bomb->speed;
|
|
|
|
|
|
|
|
|
|
/* move the bomb to the new position */
|
|
|
|
|
if (bomb->dest.x < 0)
|
|
|
|
|
bomb->pos.x -= step;
|
|
|
|
|
else if (bomb->dest.x > 0)
|
|
|
|
|
bomb->pos.x += step;
|
|
|
|
|
else if (bomb->dest.y < 0)
|
|
|
|
|
bomb->pos.y -= step;
|
|
|
|
|
else if (bomb->dest.y > 0)
|
|
|
|
|
bomb->pos.y += step;
|
|
|
|
|
|
|
|
|
|
/* if we are on a complete field, check if we
|
|
|
|
|
can move to the next one */
|
|
|
|
|
if (((bomb->pos.x & 0xFF) == 0) && ((bomb->pos.y & 0xFF) == 0)) {
|
|
|
|
|
if (bomb->mode == BM_pushed)
|
|
|
|
|
bomb->mode = BM_normal;
|
|
|
|
|
else if (bomb->mode == BM_moving) {
|
|
|
|
|
keepdir = 0;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
bomb->pos.x=npos.x;
|
|
|
|
|
bomb->pos.y=npos.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while (dist < bomb->speed && bomb->mode == BM_moving && keepdir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
bomb_loop ()
|
|
|
|
|
{
|
|
|
|
@ -177,9 +161,13 @@ bomb_loop ()
|
|
|
|
|
}
|
|
|
|
|
draw_bomb (bomb);
|
|
|
|
|
}
|
|
|
|
|
if (bomb->moves > 0 && bomb->state != BS_exploding) bomb_move(bomb);
|
|
|
|
|
|
|
|
|
|
if (bomb->mode != BM_normal)
|
|
|
|
|
bomb_action (bomb);
|
|
|
|
|
|
|
|
|
|
b++; // Count ticking Bombs for Return value
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BS_exploding:
|
|
|
|
|
if (bomb->to > 0) {
|
|
|
|
|
do_explosion (p, i);
|
|
|
|
@ -493,3 +481,16 @@ do_explosion (int p, int b)
|
|
|
|
|
if (bomb->state == BS_exploding)
|
|
|
|
|
draw_explosion (bomb);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void bomb_action (_bomb *bomb) {
|
|
|
|
|
switch (bomb->mode) {
|
|
|
|
|
case (BM_moving):
|
|
|
|
|
case (BM_pushed):
|
|
|
|
|
bomb_move (bomb);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
bomb->mode = BM_normal;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|