Skip to content

Commit

Permalink
fix: restart with jump does not auto start timer
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahkittyy committed Mar 29, 2023
1 parent 2ecb82d commit 7232f66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions game/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ input_state input_state::from_int(int i) {
return s;
}

bool input_state::operator==(const input_state& other) const {
return left == other.left && right == other.right && up == other.up && down == other.down && jump == other.jump && dash == other.dash;
}

input_state::operator int() const {
int ret = 0;
if (left) {
Expand Down
1 change: 1 addition & 0 deletions game/replay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct input_state {
bool down = false;
operator int() const;
static input_state from_int(int i);
bool operator==(const input_state& other) const;
};

class replay {
Expand Down
6 changes: 2 additions & 4 deletions game/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ bool world::update(sf::Time dt) {
m_this_frame.down = m_has_focus ? settings::get().key_down(key::DOWN) : false;
}

bool any_key = m_this_frame.left || m_this_frame.right || m_this_frame.jump || m_this_frame.dash || m_this_frame.down || m_this_frame.up;

if (settings::get().key_down(key::RESTART) && !ImGui::GetIO().WantCaptureKeyboard && resource::get().window().hasFocus()) {
if (!m_restarted)
m_restart_world();
Expand All @@ -582,7 +580,7 @@ bool world::update(sf::Time dt) {
m_space_to_retry.setColor(opacity);
m_game_clear.setColor(opacity);
m_fadeout.setFillColor(sf::Color(220, 220, 220, m_end_alpha / 2.f));
if (m_just_jumped() && !ImGui::GetIO().WantCaptureKeyboard) {
if (m_last_frame.jump && !m_this_frame.jump && !ImGui::GetIO().WantCaptureKeyboard) {
m_restart_world();
return false;
} else {
Expand All @@ -597,7 +595,7 @@ bool world::update(sf::Time dt) {
m_space_to_retry.setColor(opacity);
m_game_over.setColor(opacity);
m_fadeout.setFillColor(sf::Color(0, 0, 0, m_end_alpha / 2.f));
if (m_just_jumped()) {
if (m_last_frame.jump && !m_this_frame.jump) {
m_restart_world();
return false;
} else {
Expand Down

0 comments on commit 7232f66

Please sign in to comment.