Skip to content

Commit

Permalink
Merge pull request fogleman#8 from mbozada/US5-TNT
Browse files Browse the repository at this point in the history
US 5, Tasks: US 5.1.1, US 5.1.2, US 5.1.3
  • Loading branch information
alexreigle committed Mar 30, 2021
2 parents 424ac8c + 9914aa3 commit 6bf5ab9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/item.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const int items[] = {
SUN_FLOWER,
WHITE_FLOWER,
BLUE_FLOWER,
TNT,
COLOR_00,
COLOR_01,
COLOR_02,
Expand Down Expand Up @@ -87,7 +88,7 @@ const int blocks[256][6] = {
{0, 0, 0, 0, 0, 0}, // 21
{0, 0, 0, 0, 0, 0}, // 22
{0, 0, 0, 0, 0, 0}, // 23
{0, 0, 0, 0, 0, 0}, // 24
{80, 80, 96, 64, 80, 80}, // 24 - TNT
{0, 0, 0, 0, 0, 0}, // 25
{0, 0, 0, 0, 0, 0}, // 26
{0, 0, 0, 0, 0, 0}, // 27
Expand Down
1 change: 1 addition & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define SUN_FLOWER 21
#define WHITE_FLOWER 22
#define BLUE_FLOWER 23
#define TNT 24
#define COLOR_00 32
#define COLOR_01 33
#define COLOR_02 34
Expand Down
25 changes: 25 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2137,11 +2137,15 @@ void on_light() {
}
}

// Destroy Block
void on_left_click() {
State *s = &g->players->state;
int hx, hy, hz;
int hw = hit_test(0, s->x, s->y, s->z, s->rx, s->ry, &hx, &hy, &hz);
if (hy > 0 && hy < 256 && is_destructable(hw)) {
if (hw == TNT) {
explode(hx, hy, hz);
}
set_block(hx, hy, hz, 0);
record_block(hx, hy, hz, 0);
if (is_plant(get_block(hx, hy + 1, hz))) {
Expand All @@ -2150,6 +2154,27 @@ void on_left_click() {
}
}

// Destroy Blocks in 5 x 5 x 5 cube.
void explode(int x, int y, int z) {
x = x - 2;
y = y - 2;
z = z - 2;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
destroyBlock(x + i, y + j, z + k);
}
}
}
}

// Destroy block at given x, y, z.
void destroyBlock(int x, int y, int z) {
set_block(x, y, z, 0);
record_block(x, y, z, 0);
}

// Add block
void on_right_click() {
State *s = &g->players->state;
int hx, hy, hz;
Expand Down
2 changes: 1 addition & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void map_alloc(Map *map, int dx, int dy, int dz, int mask);
void map_free(Map *map);
void map_copy(Map *dst, Map *src);
void map_grow(Map *map);
int map_set(Map *map, int x, int y, int z, int w);
int map_set(Map *map, int x, int y, int z, int w); // w is block we want to put there
int map_get(Map *map, int x, int y, int z);

#endif
Binary file modified textures/texture.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6bf5ab9

Please sign in to comment.