Added win and loss conditions along with their respective screens
This commit is contained in:
@@ -10,12 +10,23 @@ static Vector2 drag_start_pos;
|
||||
void handle_mouse_input(GameState_t *game_state) {
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
||||
drag_start_pos = GetMousePosition();
|
||||
if (drag_start_pos.x >= 500 && drag_start_pos.x <= 775 && drag_start_pos.y >= 455 && drag_start_pos.y <= 479) {
|
||||
reset_board(game_state);
|
||||
return;
|
||||
|
||||
// Check for the normal reset button
|
||||
if (game_state->status == PLAYING) {
|
||||
if (drag_start_pos.x >= 500 && drag_start_pos.x <= 775 && drag_start_pos.y >= 455 && drag_start_pos.y <= 479) {
|
||||
reset_board(game_state);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Check for the "Play again" button
|
||||
if (drag_start_pos.x >= 300 && drag_start_pos.x <= 500 && drag_start_pos.y >= 450 && drag_start_pos.y <= 490) {
|
||||
reset_board(game_state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
is_dragging = true;
|
||||
if (game_state->status == PLAYING)
|
||||
is_dragging = true;
|
||||
} else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && is_dragging) {
|
||||
Vector2 current_pos = GetMousePosition();
|
||||
|
||||
@@ -39,7 +50,20 @@ void handle_mouse_input(GameState_t *game_state) {
|
||||
move(game_state, UP);
|
||||
}
|
||||
}
|
||||
spawn_tile(game_state);
|
||||
if (!spawn_tile(game_state) && !can_move(game_state)) {
|
||||
game_state->status = LOST;
|
||||
return;
|
||||
}
|
||||
// TODO: Allow for infinite play
|
||||
for(int y = 0; y < BOARD_HEIGHT; y++) {
|
||||
for(int x = 0; x < BOARD_WIDTH; x++) {
|
||||
if(game_state->board[y][x] == 2048) {
|
||||
game_state->status = WON;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
is_dragging = false;
|
||||
|
||||
Reference in New Issue
Block a user