From 5beed9ff6e76101fff4a0912bfd2a0c47efb9c2e Mon Sep 17 00:00:00 2001 From: stpohle Date: Mon, 9 Jun 2003 22:56:40 +0000 Subject: [PATCH] pushing bombs is now working --- src/basic.h | 4 +- src/bomb.c | 10 ++-- src/bomberclone.h | 6 +-- src/player.c | 120 +++++++++++++++++++++++++++------------------- src/special.c | 9 +++- 5 files changed, 89 insertions(+), 60 deletions(-) diff --git a/src/basic.h b/src/basic.h index 13ae597..9c4bde8 100644 --- a/src/basic.h +++ b/src/basic.h @@ -27,8 +27,8 @@ #define SPECIAL_DESTROY_NUMUSE 5 #define SPECIAL_8WAY_NUMUSE 10 -#define START_BOMBS 1 -#define START_RANGE 2 +#define START_BOMBS 5 +#define START_RANGE 6 #define START_SPEED 16 #define SPEEDMUL 1.2 diff --git a/src/bomb.c b/src/bomb.c index 130206a..ef6d134 100644 --- a/src/bomb.c +++ b/src/bomb.c @@ -81,7 +81,7 @@ bomb_explode (int p, int b, int net) void bomb_move (_bomb * bomb) { - _point npos,fpos; + _point npos; int dx = 0, dy = 0; float vec; @@ -203,7 +203,7 @@ bomb_loop () }; void -get_bomb_on (int x, int y, _point bombs[]) +get_bomb_on (short int x, short int y, _point bombs[]) { int p, b, @@ -215,7 +215,7 @@ get_bomb_on (int x, int y, _point bombs[]) for (b = 0; b < MAX_BOMBS; b++) { bomb = &bman.players[p].bombs[b]; if (bomb->state == BS_ticking || bomb->state == BS_trigger) { - if (bomb->pos.x >> 8 == x && bomb->pos.y >> 8 == y) { + if (bomb->pos.x-0x100 < x && bomb->pos.x+0x100 > x && bomb->pos.y-0x100 < y && bomb->pos.y+0x100 > y) { bombs[i].x = p; bombs[i].y = b; i++; @@ -343,7 +343,7 @@ explosion_check_field (int x, int y, int p, int b) _bomb *bomb = &bman.players[p].bombs[b]; int pl[MAX_PLAYERS]; int i; - _point bo[MAX_PLAYERS * MAX_BOMBS]; + _point bo[MAX_PLAYERS * MAX_BOMBS], pos; _bomb *tmpbomb; _player *tmpplayer; @@ -351,7 +351,7 @@ explosion_check_field (int x, int y, int p, int b) return FT_block; get_player_on (x << 8, y << 8, pl); - get_bomb_on (x, y, bo); + get_bomb_on (x << 8, y << 8, bo); // check if any bomb have to explode.. for (i = 0; bo[i].x != -1; i++) { diff --git a/src/bomberclone.h b/src/bomberclone.h index 9bb3dec..825a0ee 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.38 2003/06/07 19:05:55 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.39 2003/06/09 22:56:40 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -218,7 +218,7 @@ extern void get_player_on (short int x, short int y, int pl_nr[]); extern void player_died (_player * player, signed char dead_by); extern void draw_players (); extern void player_animation (_player * player); -extern int check_field (short int fx, short int fy, _player * p); +extern int check_field (short int x, short int y); extern void player_calcstep (_player * pl); extern void player_calcpos (); extern void player_set_ilness (_player *p, int t); @@ -229,7 +229,7 @@ extern void player_set_gfx (_player *p, signed char gfx_nr); // for the bomb.. extern int bomb_loop (); -extern void get_bomb_on (int x, int y, _point bombs[]); +extern void get_bomb_on (short int x, short int y, _point bombs[]); extern void draw_fire (int x, int y, int d, int frame); extern void do_explosion (int p, int b); extern void restore_explosion (_bomb * bomb); diff --git a/src/player.c b/src/player.c index fd545fd..6a7f936 100644 --- a/src/player.c +++ b/src/player.c @@ -77,7 +77,6 @@ draw_player (_player * player) void restore_players_screen () { - int i, x, xs, @@ -216,78 +215,102 @@ player_check_powerup (int p_nr) fx,fy = position on the field */ int -check_field (short int fx, short int fy, _player * p) +check_field (short int x, short int y) { - _point bombs[MAX_PLAYERS * MAX_BOMBS]; int res = 0; - - if (bman.field[fx][fy].type != FT_stone && bman.field[fx][fy].type != FT_block) + + if (bman.field[x][y].type != FT_stone && bman.field[x][y].type != FT_block) res = 1; - get_bomb_on (fx, fy, bombs); - if (bombs[0].x != -1) - res = 0; + return res; } +/* make only a smal step until i can go around the corner + return the rest speed for this move */ int stepmove_player (int pl_nr) { + _point bomb1[MAX_PLAYERS * MAX_BOMBS], bomb2[MAX_PLAYERS * MAX_BOMBS]; _player *p = &bman.players[pl_nr]; - int _x, - _y, - dx = 0, - dy = 0, - fx, - fy, - speed = 0; - + int speed = 0, i, j, f; + _point fpos, // field position + _pos, // position inside the field + d; + if (p->m == 1) { - fx = p->pos.x >> 8; - fy = p->pos.y >> 8; - _x = p->pos.x & 255; - _y = p->pos.y & 255; + fpos.x = p->pos.x >> 8; + fpos.y = p->pos.y >> 8; + _pos.x = p->pos.x & 255; + _pos.y = p->pos.y & 255; + // do direction correction for going up/down - if (_x > 0 && _x <= 128 && (p->d == up || p->d == down)) + if (_pos.x > 0 && _pos.x <= 128 && (p->d == up || p->d == down)) p->d = left; - if (_x > 128 && _x < 256 && (p->d == up || p->d == down)) + if (_pos.x > 128 && _pos.x < 256 && (p->d == up || p->d == down)) p->d = right; // do direction correction for left/right - if (_y > 0 && _y <= 128 && (p->d == left || p->d == right)) + if (_pos.y > 0 && _pos.y <= 128 && (p->d == left || p->d == right)) p->d = up; - if (_y > 128 && _y < 256 && (p->d == left || p->d == right)) + if (_pos.y > 128 && _pos.y < 256 && (p->d == left || p->d == right)) p->d = down; - /* get the pos to the next field */ + + /* get the distance/speed until we reach the next position */ if (p->d == left) - speed = _x; + speed = _pos.x; else if (p->d == right) - speed = 256 - _x; + speed = 256 - _pos.x; else if (p->d == up) - speed = _y; + speed = _pos.y; else - speed = 256 - _y; + speed = 256 - _pos.y; + if (speed > p->speed || speed == 0) speed = p->speed; - // go left - if (p->d == left && _y == 0 && ((_x == 0 && check_field (fx - 1, fy, p)) || (_x > 0))) - dx = -speed; - // go right - if (p->d == right && _y == 0 && ((_x == 0 && check_field (fx + 1, fy, p)) || (_x > 0))) - dx = speed; - // go up - if (p->d == up && _x == 0 && ((_y == 0 && check_field (fx, fy - 1, p)) || (_y > 0))) - dy = -speed; - // go down - if (p->d == down && _x == 0 && ((_y == 0 && check_field (fx, fy + 1, p)) || (_y > 0))) - dy = speed; - p->pos.x = p->pos.x + dx; - p->pos.y = p->pos.y + dy; - player_check_powerup (pl_nr); - } - if (dx == 0 && dy == 0) - return 0; + // check the new field position + d.x = d.y = 0; + if (p->d == left && _pos.y == 0 && ((_pos.x == 0 && check_field (fpos.x - 1, fpos.y)) || (_pos.x > 0))) + d.x = -speed; + if (p->d == right && _pos.y == 0 && ((_pos.x == 0 && check_field (fpos.x + 1, fpos.y)) || (_pos.x > 0))) + d.x = speed; + if (p->d == up && _pos.x == 0 && ((_pos.y == 0 && check_field (fpos.x, fpos.y - 1)) || (_pos.y > 0))) + d.y = -speed; + if (p->d == down && _pos.x == 0 && ((_pos.y == 0 && check_field (fpos.x, fpos.y + 1)) || (_pos.y > 0))) + d.y = speed; + + // check if we can move and if there is any bomb + if (d.y != 0 || d.x != 0) { + get_bomb_on (p->pos.x, p->pos.y, bomb1); + get_bomb_on (p->pos.x + d.x, p->pos.y + d.y, bomb2); + + if (bomb1[0].x == -1 && bomb2[0].x != -1) + /* old pos no bomb, new pos no bomb */ + d.x = d.y = 0; + else if (bomb2[0].x != -1) { + /* new pos bomb, old pos bomb... check if it's the same + use f to save if we found the bomb or not + f == 0 no bomb found, f == 1 bomb found */ + for (i = 0, f = 1; (bomb2[i].x != -1 && f == 1); i++) + for (f = 0, j = 0; (bomb1[j].x != -1 && f == 0); j++) + if (bomb1[j].x == bomb2[i].x && bomb1[j].y == bomb2[i].y) + /* identical bomb found ... f = 1 */ + f = 1; + if (f == 0) + d.x = d.y = 0; + } + } + + p->pos.x += d.x; + p->pos.y += d.y; + + player_check_powerup (pl_nr); + } + + if (d.x == 0 && d.y == 0) + return 0; + return (p->speed - speed); }; @@ -336,7 +359,9 @@ player_drop_bomb (int pl_nr) _x, _y; _point bombs[MAX_PLAYERS * MAX_BOMBS]; + for (i = 0; ((i < player->bombs_n) && (player->bombs[i].state != BS_off)); i++); + if (i < player->bombs_n && PS_IS_alife (player->state)) { // free bomb found // get the best position for the bomb. bomb = &player->bombs[i]; @@ -358,7 +383,6 @@ player_drop_bomb (int pl_nr) _y = 0; } - get_bomb_on (bomb->pos.x, bomb->pos.y, bombs); if (bombs[0].x != -1) // is there already a bomb return; diff --git a/src/special.c b/src/special.c index f04b1e7..45329a1 100644 --- a/src/special.c +++ b/src/special.c @@ -92,7 +92,8 @@ special_push (int p_nr) { _bomb *b = NULL; _player *p = &bman.players[p_nr]; - _point bombs[MAX_PLAYERS * MAX_BOMBS]; + _point bombs[MAX_PLAYERS * MAX_BOMBS], + pos; int x = p->pos.x >> 8, y = p->pos.y >> 8, dx = 0, @@ -118,15 +119,19 @@ special_push (int p_nr) } x += dx; y += dy; + // check that player is beside a bomb if (!bman.bfield[x][y]) return; + x1 = x + dx; y1 = y + dy; + // check the field behind the bomb if (bman.bfield[x1][y1] || bman.field[x1][y1].type != FT_nothing) return; - get_bomb_on (x, y, bombs); + + get_bomb_on (x << 8, y << 8, bombs); // move all bombs on that field (there should be only 1) for (i = 0; bombs[i].x != -1; i++) { b = &bman.players[bombs[i].x].bombs[bombs[i].y];