bomb push is now smooth

origin
patty21 23 years ago
parent ce2521ee1e
commit d1b81521eb

@ -11,7 +11,7 @@
#define GAME_SPECIAL_ITEMMIXED 10 #define GAME_SPECIAL_ITEMMIXED 10
#define GAME_SPECIAL_ITEMSTRIGGER 2 #define GAME_SPECIAL_ITEMSTRIGGER 2
#define GAME_SPECIAL_ITEMSROW 2 #define GAME_SPECIAL_ITEMSROW 2
#define GAME_SPECIAL_ITEMSPUSH 2 #define GAME_SPECIAL_ITEMSPUSH 50
#define GAME_SPECIAL_ITEMSKICK 0 #define GAME_SPECIAL_ITEMSKICK 0
#define GAME_SPECIAL_ITEMSLIQUID 0 #define GAME_SPECIAL_ITEMSLIQUID 0
#define GAME_SPECIAL_ITEMSDESTROY 0 #define GAME_SPECIAL_ITEMSDESTROY 0

@ -4,17 +4,17 @@
#include "network.h" #include "network.h"
#include "gfx.h" #include "gfx.h"
#include "sound.h" #include "sound.h"
#include <math.h>
void void
draw_bomb (_bomb * bomb) draw_bomb (_bomb * bomb)
{ {
SDL_Rect src, SDL_Rect src,
dest; dest;
int x = bomb->pos.x >> 8, int x = bomb->pos.x,
y = bomb->pos.y >> 8; y = bomb->pos.y;
if (x < 0 || y < 0 || x >= bman.fieldsize.x || y >= bman.fieldsize.y) { if (x < 0 || y < 0 || x>>8 >= bman.fieldsize.x || y>>8 >= bman.fieldsize.y) {
d_fatal ("Draw Bomb out of range [%d,%d]\n", x, y); d_fatal ("Draw Bomb out of range [%d,%d]\n", x, y);
return; return;
} }
@ -34,12 +34,12 @@ draw_bomb (_bomb * bomb)
dest.w = src.w = gfx.bomb.image->w; dest.w = src.w = gfx.bomb.image->w;
dest.h = src.h = gfx.block.y; dest.h = src.h = gfx.block.y;
dest.x = gfx.offset.x + (x * gfx.block.x); dest.x = gfx.offset.x + (x* gfx.block.x/0x100);
dest.y = gfx.offset.y + (y * gfx.block.y); dest.y = gfx.offset.y + (y* gfx.block.y/0x100);
src.x = 0; src.x = 0;
src.y = src.h * bomb->frame; src.y = src.h * bomb->frame;
draw_stone (x, y); draw_stone (x>>8, y>>8);
SDL_BlitSurface (gfx.bomb.image, &src, gfx.screen, &dest); SDL_BlitSurface (gfx.bomb.image, &src, gfx.screen, &dest);
gfx_AddUpdateRect (dest.x, dest.y, dest.w, dest.h); gfx_AddUpdateRect (dest.x, dest.y, dest.w, dest.h);
@ -74,33 +74,71 @@ bomb_explode (int p, int b, int net)
void void
bomb_move (_bomb * bomb) bomb_move (_bomb * bomb)
{ {
_point npos; _point npos,fpos;
if (bomb->pos.x == bomb->moveto.x) { int dx = 0,
if (bomb->pos.y == bomb->moveto.y) { dy = 0;
bomb->moves = 0; float vec;
return; 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
} }
if (bomb->pos.y > bomb->moveto.y) {
npos.y = bomb->pos.y - bomb->moves; //move bomb up
npos.x = bomb->pos.x;
} }
else { else {
npos.y = bomb->pos.y + bomb->moves; // move bomb down dx = bomb->moveto.x - bomb->pos.x; //move bomb to field
npos.x = bomb->pos.x;
} }
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 {
if (bomb->pos.x > bomb->moveto.x) {
npos.x = bomb->pos.x - bomb->moves; //move bomb left
npos.y = bomb->pos.y;
} }
else { else {
npos.x = bomb->pos.x + bomb->moves; // move bomb right dy = bomb->moveto.y - bomb->pos.y; //move bomb to field
npos.y = bomb->pos.y;
} }
d_printf("move bomb %d %d\n",dx,dy);
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;
d_printf("move bomb %d %d\n",dx,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;
}
}
*/
bomb->pos.x=npos.x;
bomb->pos.y=npos.y;
} }
int int
bomb_loop () bomb_loop ()
{ {
@ -135,7 +173,7 @@ bomb_loop ()
} }
draw_bomb (bomb); draw_bomb (bomb);
} }
// if (bomb->moves>0) bomb_move(bomb); if (bomb->moves>0) bomb_move(bomb);
b++; // Count ticking Bombs for Return value b++; // Count ticking Bombs for Return value
break; break;
case BS_exploding: case BS_exploding:

@ -117,13 +117,16 @@ special_push (int p_nr)
} }
x += dx; x += dx;
y += dy; y += dy;
// check that player is beside a bomb
if (!bman.bfield[x][y]) if (!bman.bfield[x][y])
return; return;
x1 = x + dx; x1 = x + dx;
y1 = y + dy; y1 = y + dy;
// check the field behind the bomb
if (bman.bfield[x1][y1] || bman.field[x1][y1].type != FT_nothing) if (bman.bfield[x1][y1] || bman.field[x1][y1].type != FT_nothing)
return; return;
get_bomb_on (x, y, bombs); get_bomb_on (x, y, bombs);
// move all bombs on that field (there should be only 1)
for (i = 0; bombs[i].x != -1; i++) { for (i = 0; bombs[i].x != -1; i++) {
b = &bman.players[bombs[i].x].bombs[bombs[i].y]; b = &bman.players[bombs[i].x].bombs[bombs[i].y];
if (b->state != BS_exploding) { if (b->state != BS_exploding) {

Loading…
Cancel
Save