Skip to content

Commit

Permalink
fix mining nearest block on android
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Feb 26, 2024
1 parent 0c25320 commit fd82296
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/core/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ bool check_collision_touch(Vector2 position, float size) {
return !Vector2Equals(get_collision_touch(position, size), VEC_ZERO);
}

Vector2 get_nearest_touch(Vector2 position)
{
const int touch_count = GetTouchPointCount();
Vector2 nearest = VEC_ZERO;
float distance = 0;
for (int i = 0; i < touch_count; i++) {
Vector2 point =
VEC(FORMAT_W(GetTouchPosition(i).x), FORMAT_H(GetTouchPosition(i).y));
float d = Vector2Distance(point, position);
if (d < distance || distance == 0) {
distance = d;
nearest = point;
}
}
return nearest;
}

Vector2 get_collision_touch(Vector2 position, float size) {
const int touch_count = GetTouchPointCount();
for (int i = 0; i < touch_count; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/core/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void clear_controls(w_controls *kb);

#ifdef __ANDROID__
bool check_collision_touch(Vector2 position, float size);
Vector2 get_nearest_touch(Vector2 position);
Vector2 get_collision_touch(Vector2 position, float size);

bool check_collision_touch_rect(Rectangle rect);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Vector2 update_joystick(w_guijoystick *js) {

#ifdef __ANDROID__
if (has_touch()) {
Vector2 mouse = VEC(FORMAT_W(GetMouseX()), FORMAT_H(GetMouseY()));
Vector2 mouse = get_nearest_touch(Vector2SubtractValue(js->position, js->size/2.f));
Vector2 touch = get_collision_touch(js->position, js->size);
#else
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
Expand Down

0 comments on commit fd82296

Please sign in to comment.