Skip to content

Commit

Permalink
Merge pull request #21 from ashleyhuxley/fen/limit-bombs
Browse files Browse the repository at this point in the history
feat: player starts with one bomb
  • Loading branch information
ashleyhuxley authored Aug 17, 2024
2 parents f8775b3 + 805e817 commit 5ad8fd4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 15 additions & 8 deletions bomber_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ static bool handle_game_direction(BomberAppState* state, InputEvent input) {
state->level[ix(newPoint.x, newPoint.y)] = BlockType_Empty;
} else if (block == BlockType_PuExtraBomb) {
player->bomb_count++;
if (player->bomb_count == MAX_BOMBS) {
player->bomb_count = MAX_BOMBS;
}
state->level[ix(newPoint.x, newPoint.y)] = BlockType_Empty;
}

Expand Down Expand Up @@ -138,16 +141,20 @@ static bool handle_game_input(BomberAppState* state, InputEvent input) {
case InputKeyOk:
FURI_LOG_I(TAG, "Drop Bomb");

Bomb bomb;
bomb.x = player->x;
bomb.y = player->y;
bomb.state = BombState_Planted;
bomb.planted = furi_get_tick();
player->bombs[player->bomb_ix] = bomb;
for (int i = 0; i < player->bomb_count; i++) {
if (player->bombs[i].state == BombState_None) {
Bomb bomb;
bomb.x = player->x;
bomb.y = player->y;
bomb.state = BombState_Planted;
bomb.planted = furi_get_tick();

player->bomb_ix = (player->bomb_ix + 1) % 10;
player->bombs[i] = bomb;

tx_bomb_placement(state, bomb.x, bomb.y);
tx_bomb_placement(state, bomb.x, bomb.y);
break;
}
}

return true;
case InputKeyUp:
Expand Down
6 changes: 4 additions & 2 deletions helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Player bomber_app_get_block(uint8_t level[], BlockType blockType)
.x = x,
.y = y,
.bombs = { [0 ... 9] = {0, 0, 0, BombState_None} }, // All elements initialized the same way
.bomb_power = 1
.bomb_power = 1,
.bomb_count = 1
};
return player;
}
Expand All @@ -83,7 +84,8 @@ Player bomber_app_get_block(uint8_t level[], BlockType blockType)
.x = 0,
.y = 0,
.bombs = { [0 ... 9] = {0, 0, 0, BombState_None} }, // All elements initialized the same way
.bomb_power = 1
.bomb_power = 1,
.bomb_count = 1
};
return def;
}
Expand Down

0 comments on commit 5ad8fd4

Please sign in to comment.