diff options
author | Jamie Mansfield <jmansfield@cadixdev.org> | 2021-07-15 15:25:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-15 20:11:22 +0200 |
commit | 0f9873475b8b2279f1cbddca3b5251cbbcfbb584 (patch) | |
tree | 3fdb8f875eff7ad4a2124cae201100ea85dfe997 /Userland/Games | |
parent | c0bc884295491cea629483521979fe578755c4b9 (diff) | |
download | serenity-0f9873475b8b2279f1cbddca3b5251cbbcfbb584.zip |
Spider: Reduce overdraw when drawing initial cards
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Spider/Game.cpp | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp index aa2393b5fa..b9939dfb6d 100644 --- a/Userland/Games/Spider/Game.cpp +++ b/Userland/Games/Spider/Game.cpp @@ -190,37 +190,6 @@ void Game::paint_event(GUI::PaintEvent& event) painter.add_clip_rect(frame_inner_rect()); painter.add_clip_rect(event.rect()); - if (m_new_game_animation) { - if (m_new_game_animation_delay < new_game_animation_delay) { - ++m_new_game_animation_delay; - } else { - m_new_game_animation_delay = 0; - auto& current_pile = stack(piles.at(m_new_game_animation_pile)); - - // for first 4 piles, draw 6 cards - // for last 6 piles, draw 5 cards - size_t cards_to_draw = m_new_game_animation_pile < 4 ? 6 : 5; - - if (current_pile.count() < (cards_to_draw - 1)) { - auto card = m_new_deck.take_last(); - card->set_upside_down(true); - current_pile.push(card); - } else { - current_pile.push(m_new_deck.take_last()); - ++m_new_game_animation_pile; - } - - if (m_new_game_animation_pile == piles.size()) { - VERIFY(m_new_deck.size() == 50); - while (!m_new_deck.is_empty()) - stack(Stock).push(m_new_deck.take_last()); - m_new_game_animation = false; - m_waiting_for_new_game = true; - stop_timer(); - } - } - } - if (!m_focused_cards.is_empty()) { for (auto& focused_card : m_focused_cards) focused_card.clear(painter, s_background_color); @@ -355,7 +324,41 @@ void Game::mousemove_event(GUI::MouseEvent& event) void Game::timer_event(Core::TimerEvent&) { if (m_new_game_animation) { - update(); + if (m_new_game_animation_delay < new_game_animation_delay) { + ++m_new_game_animation_delay; + } else { + m_new_game_animation_delay = 0; + auto& current_pile = stack(piles.at(m_new_game_animation_pile)); + + // for first 4 piles, draw 6 cards + // for last 6 piles, draw 5 cards + size_t cards_to_draw = m_new_game_animation_pile < 4 ? 6 : 5; + + if (current_pile.count() < (cards_to_draw - 1)) { + auto card = m_new_deck.take_last(); + card->set_upside_down(true); + current_pile.push(card); + } else { + current_pile.push(m_new_deck.take_last()); + ++m_new_game_animation_pile; + } + + update(current_pile.bounding_box()); + + if (m_new_game_animation_pile == piles.size()) { + VERIFY(m_new_deck.size() == 50); + + auto& stock_pile = stack(Stock); + while (!m_new_deck.is_empty()) + stock_pile.push(m_new_deck.take_last()); + + update(stock_pile.bounding_box()); + + m_new_game_animation = false; + m_waiting_for_new_game = true; + stop_timer(); + } + } } } |