Minor refactorings
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 16s

This commit is contained in:
Stephen Seo 2023-08-15 15:44:11 +09:00
parent 761c5c462c
commit 623308cd67
3 changed files with 34 additions and 16 deletions

View file

@ -241,29 +241,38 @@ bool TRunnerScreen::update(float dt) {
if (controlled_walker_idx.has_value() && IsMouseButtonDown(0)) {
// Check if clicked on button.
if (GetTouchX() >= 0 && GetTouchX() <= left_text_width &&
if (!walkers[controlled_walker_idx.value()].player_is_turning_left() &&
GetTouchX() >= 0 && GetTouchX() <= left_text_width &&
GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE &&
GetTouchY() <= GetScreenHeight()) {
walkers[controlled_walker_idx.value()].player_turn_left();
goto post_check_click;
} else if (GetTouchX() >= left_text_width &&
} else if (!walkers[controlled_walker_idx.value()]
.player_is_turning_right() &&
GetTouchX() >= left_text_width &&
GetTouchX() <= left_text_width + right_text_width &&
GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE &&
GetTouchY() <= GetScreenHeight()) {
walkers[controlled_walker_idx.value()].player_turn_right();
goto post_check_click;
} else if (int width_mid = (left_text_width + right_text_width) / 2 -
forward_text_width / 2;
GetTouchX() >= width_mid &&
GetTouchX() <= width_mid + forward_text_width &&
GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE * 2 &&
GetTouchY() <= GetScreenHeight() - BUTTON_FONT_SIZE) {
walkers[controlled_walker_idx.value()].player_go_forward();
} else if (!walkers[controlled_walker_idx.value()]
.player_is_going_forward()) {
if (int width_mid =
(left_text_width + right_text_width) / 2 - forward_text_width / 2;
GetTouchX() >= width_mid &&
GetTouchX() <= width_mid + forward_text_width &&
GetTouchY() >= GetScreenHeight() - BUTTON_FONT_SIZE * 2 &&
GetTouchY() <= GetScreenHeight() - BUTTON_FONT_SIZE) {
walkers[controlled_walker_idx.value()].player_go_forward();
goto post_check_click;
}
}
} else if (IsMouseButtonReleased(0)) {
if (controlled_walker_idx.has_value()) {
walkers[controlled_walker_idx.value()].player_idle();
goto post_check_click;
}
}
if (IsMouseButtonPressed(0)) {
} else if (IsMouseButtonPressed(0)) {
float press_x = GetTouchX();
float press_y = GetTouchY();
Ray ray = GetMouseRay(Vector2{press_x, press_y}, camera);
@ -347,10 +356,6 @@ bool TRunnerScreen::update(float dt) {
}
}
}
} else if (IsMouseButtonReleased(0)) {
if (controlled_walker_idx.has_value()) {
walkers[controlled_walker_idx.value()].player_idle();
}
}
post_check_click:

View file

@ -185,6 +185,14 @@ void Walker::player_turn_right() {
void Walker::player_go_forward() { flags |= 0x30; }
bool Walker::player_is_idle() const { return (flags & 0x30) == 0; }
bool Walker::player_is_turning_left() const { return (flags & 0x30) == 0x10; }
bool Walker::player_is_turning_right() const { return (flags & 0x30) == 0x20; }
bool Walker::player_is_going_forward() const { return (flags & 0x30) == 0x30; }
BoundingBox Walker::get_body_bb() const {
return BoundingBox{
.min = body_pos - Vector3{0.5F,

View file

@ -49,6 +49,11 @@ class Walker {
void player_turn_right();
void player_go_forward();
bool player_is_idle() const;
bool player_is_turning_left() const;
bool player_is_turning_right() const;
bool player_is_going_forward() const;
BoundingBox get_body_bb() const;
float get_rotation() const;
Vector3 get_body_pos() const;