mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:07:34 +00:00
Demos/CatDog: Refactor the main states
CatDog's state was previously handled by a bunch of booleans that all needed to be in sync pretty accurately, but some of these are exclusive (like alerted and sleeping). This commit introduces a simple enum for the main states of CatDog which exclude the roaming and direction states. The main state determines the standing image of CatDog and will have further effects in the future.
This commit is contained in:
parent
83d9a89275
commit
93bb943394
2 changed files with 55 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Richard Gráčik <r.gracik@gmail.com>
|
||||
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -85,13 +86,13 @@ void CatDog::timer_event(Core::TimerEvent&)
|
|||
}
|
||||
|
||||
if (!m_up && !m_down && !m_left && !m_right) {
|
||||
m_curr_bmp = m_still;
|
||||
if (m_timer.elapsed() > 5000) {
|
||||
m_curr_bmp = m_sleep1;
|
||||
if (m_curr_frame == 2)
|
||||
m_curr_bmp = m_sleep2;
|
||||
m_sleeping = true;
|
||||
}
|
||||
// Select the movement-free image based on the main state.
|
||||
if (m_timer.elapsed() > 5000)
|
||||
m_main_state = MainState::Sleeping;
|
||||
set_image_by_main_state();
|
||||
} else if (is_non_application_state(m_main_state)) {
|
||||
// If CatDog currently moves, it should be idle the next time it stops.
|
||||
m_main_state = MainState::Idle;
|
||||
}
|
||||
|
||||
update();
|
||||
|
@ -113,11 +114,11 @@ void CatDog::track_mouse_move(Gfx::IntPoint const& point)
|
|||
return;
|
||||
m_temp_pos = relative_point;
|
||||
m_timer.start();
|
||||
if (m_sleeping) {
|
||||
m_curr_bmp = m_alert;
|
||||
if (m_main_state == MainState::Sleeping) {
|
||||
m_main_state = MainState::Alerted;
|
||||
set_image_by_main_state();
|
||||
update();
|
||||
}
|
||||
m_sleeping = false;
|
||||
}
|
||||
|
||||
void CatDog::mousedown_event(GUI::MouseEvent& event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue