Skip to content

Commit

Permalink
fix mouse position for mining
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Feb 13, 2024
1 parent 617acc7 commit 32e033a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/core/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ void smooth_rect(Rectangle *box, Rectangle target, float move) {
}

Vector2 get_mouse_block_center(Camera2D *camera) {
return Vector2Subtract(GetScreenToWorld2D(GetMousePosition(), *camera),
(Vector2){(CUBE_W / 2), (CUBE_H / 2)});
Vector2 mouse = GetMousePosition();

mouse.x = (mouse.x / GetScreenWidth()) * RENDER_W;
mouse.y = (mouse.y / GetScreenHeight()) * RENDER_H;

mouse.x += camera->target.x;
mouse.y += camera->target.y;

return Vector2Subtract(mouse, (Vector2){(CUBE_W / 2), (CUBE_H / 2)});
}

Vector2 vec_block_round(Vector2 vec) {
Expand Down
8 changes: 1 addition & 7 deletions src/screen/game.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "game.h"

void game_screen(w_state *state) {
#ifndef _DEBUG
HideCursor();
#endif // !_DEBUG

Texture block_textures[6] = {
get_texture_by_id(state, "blocks\\grass.png"),
get_texture_by_id(state, "blocks\\dirt.png"),
Expand Down Expand Up @@ -75,8 +73,4 @@ void game_screen(w_state *state) {
}
destroy_blockbreaker(bb);
destroy_bridge(td);

#ifndef _DEBUG
ShowCursor();
#endif // !_DEBUG
}
2 changes: 1 addition & 1 deletion src/terrain/break.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ w_breakstate update_blockbreaker(w_blockbreaker *bb, Vector2 player, float dt) {
}

Vector2 bmouse = vec_block_round(mouse);

DrawRectangleLines(bmouse.x, bmouse.y, CUBE_W, CUBE_H, RED);
w_block *block = get_chunkview_block(bb->chunk_view, bmouse);
if (block == NULL || block->type == BLOCK_AIR) {
bb->time = 0;
Expand Down

0 comments on commit 32e033a

Please sign in to comment.