-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
145 additions
and
84 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "break.h" | ||
|
||
w_blockbreaker *create_blockbreaker(w_state *state, w_chunkview *chunk_view, | ||
Camera2D *camera) { | ||
w_blockbreaker *bb = malloc(sizeof(w_blockbreaker)); | ||
if (bb == NULL) { | ||
return NULL; | ||
} | ||
memset(bb, 0, sizeof(w_blockbreaker)); | ||
|
||
bb->textures = malloc(sizeof(Texture) * BREAKER_STAGES); | ||
for (size_t i = 0; i < BREAKER_STAGES; i++) { | ||
bb->textures[i] = | ||
get_texture_by_id(state, (char *)TextFormat("blocks\\break_%i.png", i)); | ||
} | ||
|
||
bb->time = 0; | ||
bb->stage = 0; | ||
bb->position = VEC_ZERO; | ||
bb->chunk_view = chunk_view; | ||
bb->camera = camera; | ||
|
||
return bb; | ||
} | ||
|
||
w_breakstate update_blockbreaker(w_blockbreaker *bb, Vector2 player, float dt) { | ||
Vector2 mouse = get_mouse_block_center(bb->camera); | ||
if (Vector2Distance(mouse, player) >= BREAKER_DISTANCE || | ||
!IsMouseButtonDown(MOUSE_LEFT_BUTTON)) { | ||
bb->time = 0; | ||
return BS_NONE; | ||
} | ||
|
||
Vector2 bmouse = vec_block_round(mouse); | ||
|
||
w_block *block = get_chunkview_block(bb->chunk_view, bmouse); | ||
if (block == NULL || block->type == BLOCK_AIR) { | ||
bb->time = 0; | ||
return BS_NONE; | ||
} | ||
|
||
if (bb->time > 0) { | ||
if (!Vector2Equals(bb->position, bmouse)) { | ||
bb->time = 0; | ||
return false; | ||
} | ||
bb->time -= dt; | ||
bb->stage = | ||
(BREAKER_STAGES - 1) - ((bb->time) / (BREAKER_TIME / BREAKER_STAGES)); | ||
|
||
if (bb->stage >= BREAKER_STAGES - 1 || bb->time <= 0) { | ||
bb->time = 0; | ||
bb->stage = 0; | ||
if (block != NULL && block->type != BLOCK_AIR) { | ||
block->type = BLOCK_AIR; | ||
} | ||
return BS_BROKEN; | ||
} | ||
|
||
return BS_BREAKING; | ||
} | ||
bb->time = BREAKER_TIME; | ||
bb->stage = BREAKER_STAGES - 1; | ||
bb->position = bmouse; | ||
return BS_NONE; | ||
} | ||
|
||
void draw_blockbreaker(w_blockbreaker *bb) { | ||
DrawTexturePro(bb->textures[bb->stage], CUBE_SRC_RECT, | ||
(Rectangle){.x = bb->position.x, | ||
.y = bb->position.y, | ||
.width = CUBE_W, | ||
.height = CUBE_H}, | ||
VEC_ZERO, 0, Fade(WHITE, 0.5)); | ||
} | ||
|
||
void destroy_blockbreaker(w_blockbreaker *bb) { | ||
free(bb->textures); | ||
free(bb); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
#include "../core/state.h" | ||
#include "../stdafx.h" | ||
#include "chunk_view.h" | ||
|
||
#define BREAKER_TIME .8f | ||
#define BREAKER_STAGES 6 | ||
#define BREAKER_DISTANCE (3 * CUBE_W) | ||
|
||
typedef enum w_breakstate { | ||
BS_NONE, | ||
BS_BREAKING, | ||
BS_BROKEN, | ||
} w_breakstate; | ||
|
||
typedef struct w_blockbreaker { | ||
float time; | ||
int stage; | ||
Vector2 position; | ||
|
||
w_chunkview *chunk_view; | ||
Camera2D *camera; | ||
|
||
Texture *textures; | ||
} w_blockbreaker; | ||
|
||
w_blockbreaker *create_blockbreaker(w_state *state, w_chunkview *chunk_view, | ||
Camera2D *camera); | ||
|
||
w_breakstate update_blockbreaker(w_blockbreaker *bb, Vector2 player, float dt); | ||
|
||
void draw_blockbreaker(w_blockbreaker *bb); | ||
|
||
void destroy_blockbreaker(w_blockbreaker *bb); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters