From 47dc1f61b9afd6bbc6651012077e8b1937a8aecf Mon Sep 17 00:00:00 2001 From: Joshua Joseph Date: Thu, 7 Nov 2024 19:17:07 -0500 Subject: [PATCH 1/5] :pencil2: experimenting with an input chord class --- src/engine/Chord.cpp | 103 ++++++++++++++++++++++++++++ src/engine/EventManager.cpp | 2 +- src/engine/Input.cpp | 82 +++++----------------- src/engine/includes/Chord.hpp | 29 ++++++++ src/engine/includes/Input.hpp | 9 +-- src/games/hw4_joshua/hw4_joshua.cpp | 6 +- 6 files changed, 157 insertions(+), 74 deletions(-) create mode 100644 src/engine/Chord.cpp create mode 100644 src/engine/includes/Chord.hpp diff --git a/src/engine/Chord.cpp b/src/engine/Chord.cpp new file mode 100644 index 0000000..0100854 --- /dev/null +++ b/src/engine/Chord.cpp @@ -0,0 +1,103 @@ +#include "Chord.hpp" +#include "EventManager.hpp" +#include "Types.hpp" +#include "Utils.hpp" + +Chord::Chord(int chord_id, std::unordered_set keys) { + if (chord_id == 0) { + Log(LogLevel::Error, "The chord_id should be greater than 0!"); + app->quit.store(true); + return; + } + + this->chord_id = chord_id; + this->keys = keys; + this->buffer = std::vector>(); + this->start = std::chrono::steady_clock::now(); + this->timeout = 50; +} + +void Chord::Process() { + auto now = std::chrono::steady_clock::now(); + this->elapsed = + std::chrono::duration_cast(now - this->start).count(); + + if (this->elapsed >= this->timeout) { + this->Reset(); + } +} + +void Chord::ProcessKeyPress(SDL_Scancode key, bool pressed) { + if (!this->IsKeyInChord(key)) { + return; + } + + this->buffer.push_back({key, pressed}); + this->LogBuffer(); + + if (this->BufferContainsChord()) { + this->Trigger(); + } +} + +bool Chord::BufferContainsChord() { + std::vector> matched_entries; + + for (const auto &key : this->keys) { + auto buffer_iterator = std::find_if(this->buffer.begin(), this->buffer.end(), + [&key](const std::pair &entry) { + return entry.first == key && entry.second; + }); + + if (buffer_iterator == this->buffer.end()) { + return false; + } + + matched_entries.push_back(*buffer_iterator); + } + + for (const auto &entry : matched_entries) { + auto iterator = std::find(this->buffer.begin(), this->buffer.end(), entry); + if (iterator != this->buffer.end()) { + this->buffer.erase(iterator); + } + } + + return true; +} + +void Chord::FlushBuffer() { + for (const auto &entry : this->buffer) { + SDL_Scancode key = entry.first; + bool pressed = entry.second; + + EventManager::GetInstance().RaiseInputEvent( + InputEvent{InputEventType::Single, key, 0, pressed}); + } + this->buffer.clear(); +} + +void Chord::LogBuffer() { + std::string log_buffer = ""; + for (const auto &entry : this->buffer) { + SDL_Scancode key = entry.first; + bool pressed = entry.second; + + log_buffer += std::to_string(key) + "_" + std::to_string(pressed) + " , "; + } + Log(LogLevel::Info, "buffer: %s", log_buffer.c_str()); +} + +void Chord::Reset() { + this->start = std::chrono::steady_clock::now(); + this->FlushBuffer(); +} + +void Chord::Trigger() { + this->Reset(); + + EventManager::GetInstance().RaiseInputEvent( + InputEvent{InputEventType::Chord, SDL_SCANCODE_UNKNOWN, this->chord_id, true}); +} + +bool Chord::IsKeyInChord(SDL_Scancode key) { return this->keys.count(key) > 0; } \ No newline at end of file diff --git a/src/engine/EventManager.cpp b/src/engine/EventManager.cpp index b273fd0..84b7459 100644 --- a/src/engine/EventManager.cpp +++ b/src/engine/EventManager.cpp @@ -154,7 +154,7 @@ void EventManager::ProfileEventQueue() { void EventManager::RaiseInputEvent(InputEvent event) { Event input_event = Event(EventType::Input, event); - input_event.SetDelay(0); + input_event.SetDelay(-1); input_event.SetPriority(Priority::High); if (event.type == InputEventType::Single) { diff --git a/src/engine/Input.cpp b/src/engine/Input.cpp index e7f01ae..723b2f3 100644 --- a/src/engine/Input.cpp +++ b/src/engine/Input.cpp @@ -1,29 +1,19 @@ #include "Input.hpp" - -#include "Engine.hpp" +#include "Chord.hpp" #include "EventManager.hpp" #include "SDL_keyboard.h" #include "SDL_scancode.h" #include "Types.hpp" -#include "Utils.hpp" #include Input::Input() { this->keyboard_state = nullptr; - this->chords = std::unordered_map>(); - this->key_press_times = std::unordered_map(); - this->chord_delay = 100; -} - -// Event handler function to be called on key state change -void Input::RaiseEvent(SDL_Scancode key, bool is_pressed) { - EventManager::GetInstance().RaiseInputEvent( - InputEvent{InputEventType::Single, key, 0, is_pressed}); + this->chords = std::vector(); } bool Input::IsKeyInChords(SDL_Scancode key) { - for (const auto &[chord_id, chord_keys] : this->chords) { - if (chord_keys.count(key) > 0) { + for (Chord &chord : this->chords) { + if (chord.IsKeyInChord(key)) { return true; } } @@ -35,77 +25,37 @@ void Input::Process() { // If first call, initialize prevState to match the current state if (!this->keyboard_state) { - int num_keys; this->keyboard_state = new Uint8[SDL_NUM_SCANCODES]; memcpy((void *)this->keyboard_state, new_state, SDL_NUM_SCANCODES); } - // To ensure only changes to chords are raised - static std::unordered_map active_chords; - - int64_t current_time = Engine::GetInstance().EngineTimelineGetTime(); - - for (const auto &[chord_id, chord_keys] : this->chords) { - bool chord_detected = true; - - for (SDL_Scancode key : chord_keys) { - if (!new_state[key]) { - chord_detected = false; - break; - } - } - - if (chord_detected) { - if (!active_chords[chord_id]) { - EventManager::GetInstance().RaiseInputEvent( - InputEvent{InputEventType::Chord, SDL_SCANCODE_UNKNOWN, chord_id, true}); - active_chords[chord_id] = true; - } - } else { - if (active_chords[chord_id]) { - EventManager::GetInstance().RaiseInputEvent( - InputEvent{InputEventType::Chord, SDL_SCANCODE_UNKNOWN, chord_id, false}); - active_chords[chord_id] = false; - } - } - } - // Iterate over all scancodes and check for changes for (int i = 0; i < SDL_NUM_SCANCODES; ++i) { if (new_state[i] == this->keyboard_state[i]) { continue; } - bool is_pressed = new_state[i]; + bool pressed = new_state[i]; SDL_Scancode key = static_cast(i); - if (is_pressed) { - key_press_times[key] = current_time; - } else { - key_press_times.erase(key); + for (Chord &chord : this->chords) { + chord.ProcessKeyPress(key, pressed); } - if (this->IsKeyInChords(key)) { - int64_t delay = Engine::GetInstance().EngineTimelineGetTime() - key_press_times[key]; - - if (delay >= (this->chord_delay * 1'000'000)) { - this->RaiseEvent(key, is_pressed); - } - } else { - this->RaiseEvent(key, is_pressed); + if (!this->IsKeyInChords(key)) { + EventManager::GetInstance().RaiseInputEvent( + InputEvent{InputEventType::Single, key, 0, pressed}); } } + for (Chord &chord : this->chords) { + chord.Process(); + } + // Update the previous state memcpy((void *)this->keyboard_state, new_state, SDL_NUM_SCANCODES); } -void Input::RegisterInputChord(int chord_id, std::unordered_set chord) { - if (chord_id == 0) { - Log(LogLevel::Error, "The chord_id should be greater than 0!"); - app->quit.store(true); - return; - } - - this->chords[chord_id] = chord; +void Input::RegisterInputChord(int chord_id, std::unordered_set keys) { + this->chords.push_back(Chord(chord_id, keys)); } \ No newline at end of file diff --git a/src/engine/includes/Chord.hpp b/src/engine/includes/Chord.hpp new file mode 100644 index 0000000..e037f2d --- /dev/null +++ b/src/engine/includes/Chord.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "SDL_scancode.h" +#include +#include + +class Chord { + private: + int chord_id; + std::unordered_set keys; + + std::vector> buffer; + std::chrono::steady_clock::time_point start; + int64_t elapsed; + int timeout; + + void Reset(); + void Trigger(); + bool BufferContainsChord(); + void FlushBuffer(); + void LogBuffer(); + + public: + Chord(int chord_id, std::unordered_set keys); + + void Process(); + void ProcessKeyPress(SDL_Scancode key, bool pressed); + bool IsKeyInChord(SDL_Scancode key); +}; \ No newline at end of file diff --git a/src/engine/includes/Input.hpp b/src/engine/includes/Input.hpp index 4dd1191..d904988 100644 --- a/src/engine/includes/Input.hpp +++ b/src/engine/includes/Input.hpp @@ -1,22 +1,19 @@ #pragma once +#include "Chord.hpp" #include "SDL_scancode.h" #include "SDL_stdinc.h" -#include #include class Input { private: Uint8 *keyboard_state; - std::unordered_map> chords; - std::unordered_map key_press_times; - int64_t chord_delay; + std::vector chords; - void RaiseEvent(SDL_Scancode key, bool is_pressed); bool IsKeyInChords(SDL_Scancode key); public: Input(); void Process(); - void RegisterInputChord(int chord_id, std::unordered_set chord); + void RegisterInputChord(int chord_id, std::unordered_set keys); }; \ No newline at end of file diff --git a/src/games/hw4_joshua/hw4_joshua.cpp b/src/games/hw4_joshua/hw4_joshua.cpp index 75aa9da..15e4a31 100644 --- a/src/games/hw4_joshua/hw4_joshua.cpp +++ b/src/games/hw4_joshua/hw4_joshua.cpp @@ -64,6 +64,9 @@ void HandleAlienSingleInput(InputEvent *event) { void HandleAlienChordInput(Entity &alien, InputEvent *event) { bool pressed = event->pressed; + if (!pressed) { + return; + } switch (event->chord_id) { case 1: case 5: @@ -390,7 +393,8 @@ std::vector CreateEnemies() { enemy_index += 1; pos_x += 660; } - return enemies; + // return enemies; + return std::vector(); } std::vector CreateEntities() { From c2fee70c50b7d7a76c04ef81081db72ff5fc7cc2 Mon Sep 17 00:00:00 2001 From: Joshua Joseph Date: Thu, 7 Nov 2024 22:12:17 -0500 Subject: [PATCH 2/5] :pencil2: move chord buffers and timers to the input class --- src/engine/Chord.cpp | 87 +------------------------- src/engine/Input.cpp | 94 +++++++++++++++++++++++++++-- src/engine/includes/Chord.hpp | 16 +---- src/engine/includes/Input.hpp | 12 ++++ src/games/hw4_joshua/hw4_joshua.cpp | 36 ++++------- 5 files changed, 115 insertions(+), 130 deletions(-) diff --git a/src/engine/Chord.cpp b/src/engine/Chord.cpp index 0100854..0a3bbb1 100644 --- a/src/engine/Chord.cpp +++ b/src/engine/Chord.cpp @@ -1,5 +1,4 @@ #include "Chord.hpp" -#include "EventManager.hpp" #include "Types.hpp" #include "Utils.hpp" @@ -12,92 +11,10 @@ Chord::Chord(int chord_id, std::unordered_set keys) { this->chord_id = chord_id; this->keys = keys; - this->buffer = std::vector>(); - this->start = std::chrono::steady_clock::now(); - this->timeout = 50; } -void Chord::Process() { - auto now = std::chrono::steady_clock::now(); - this->elapsed = - std::chrono::duration_cast(now - this->start).count(); +int Chord::GetChordID() { return this->chord_id; } - if (this->elapsed >= this->timeout) { - this->Reset(); - } -} - -void Chord::ProcessKeyPress(SDL_Scancode key, bool pressed) { - if (!this->IsKeyInChord(key)) { - return; - } - - this->buffer.push_back({key, pressed}); - this->LogBuffer(); - - if (this->BufferContainsChord()) { - this->Trigger(); - } -} - -bool Chord::BufferContainsChord() { - std::vector> matched_entries; - - for (const auto &key : this->keys) { - auto buffer_iterator = std::find_if(this->buffer.begin(), this->buffer.end(), - [&key](const std::pair &entry) { - return entry.first == key && entry.second; - }); - - if (buffer_iterator == this->buffer.end()) { - return false; - } - - matched_entries.push_back(*buffer_iterator); - } - - for (const auto &entry : matched_entries) { - auto iterator = std::find(this->buffer.begin(), this->buffer.end(), entry); - if (iterator != this->buffer.end()) { - this->buffer.erase(iterator); - } - } - - return true; -} - -void Chord::FlushBuffer() { - for (const auto &entry : this->buffer) { - SDL_Scancode key = entry.first; - bool pressed = entry.second; - - EventManager::GetInstance().RaiseInputEvent( - InputEvent{InputEventType::Single, key, 0, pressed}); - } - this->buffer.clear(); -} - -void Chord::LogBuffer() { - std::string log_buffer = ""; - for (const auto &entry : this->buffer) { - SDL_Scancode key = entry.first; - bool pressed = entry.second; - - log_buffer += std::to_string(key) + "_" + std::to_string(pressed) + " , "; - } - Log(LogLevel::Info, "buffer: %s", log_buffer.c_str()); -} - -void Chord::Reset() { - this->start = std::chrono::steady_clock::now(); - this->FlushBuffer(); -} - -void Chord::Trigger() { - this->Reset(); - - EventManager::GetInstance().RaiseInputEvent( - InputEvent{InputEventType::Chord, SDL_SCANCODE_UNKNOWN, this->chord_id, true}); -} +std::unordered_set Chord::GetKeys() { return this->keys; } bool Chord::IsKeyInChord(SDL_Scancode key) { return this->keys.count(key) > 0; } \ No newline at end of file diff --git a/src/engine/Input.cpp b/src/engine/Input.cpp index 723b2f3..dd47f55 100644 --- a/src/engine/Input.cpp +++ b/src/engine/Input.cpp @@ -4,11 +4,18 @@ #include "SDL_keyboard.h" #include "SDL_scancode.h" #include "Types.hpp" +#include "Utils.hpp" +#include #include Input::Input() { this->keyboard_state = nullptr; this->chords = std::vector(); + + this->buffer = std::vector>(); + this->start = std::chrono::steady_clock::now(); + this->elapsed = 0; + this->timeout = 100; } bool Input::IsKeyInChords(SDL_Scancode key) { @@ -20,6 +27,28 @@ bool Input::IsKeyInChords(SDL_Scancode key) { return false; } +void Input::LogBuffer() { + std::string log_buffer = ""; + for (const auto &entry : this->buffer) { + SDL_Scancode key = entry.first; + bool pressed = entry.second; + + log_buffer += std::to_string(key) + "_" + std::to_string(pressed) + " , "; + } + Log(LogLevel::Info, "buffer: %s", log_buffer.c_str()); +} + +void Input::FlushBuffer() { + for (const auto &entry : this->buffer) { + SDL_Scancode key = entry.first; + bool pressed = entry.second; + + EventManager::GetInstance().RaiseInputEvent( + InputEvent{InputEventType::Single, key, 0, pressed}); + } + this->buffer.clear(); +} + void Input::Process() { const Uint8 *new_state = SDL_GetKeyboardState(NULL); @@ -38,24 +67,77 @@ void Input::Process() { bool pressed = new_state[i]; SDL_Scancode key = static_cast(i); - for (Chord &chord : this->chords) { - chord.ProcessKeyPress(key, pressed); - } - if (!this->IsKeyInChords(key)) { EventManager::GetInstance().RaiseInputEvent( InputEvent{InputEventType::Single, key, 0, pressed}); + continue; + } + + this->buffer.push_back({key, pressed}); + // this->LogBuffer(); + + int chord_id = this->BufferContainsChord(); + if (chord_id != 0) { + this->TriggerChord(chord_id); } } - for (Chord &chord : this->chords) { - chord.Process(); + auto now = std::chrono::steady_clock::now(); + this->elapsed = + std::chrono::duration_cast(now - this->start).count(); + + if (this->elapsed >= this->timeout) { + this->ResetChords(); } // Update the previous state memcpy((void *)this->keyboard_state, new_state, SDL_NUM_SCANCODES); } +int Input::BufferContainsChord() { + for (auto &chord : this->chords) { + bool chord_found = true; + + for (const auto &key : chord.GetKeys()) { + auto buffer_iterator = + std::find_if(this->buffer.begin(), this->buffer.end(), + [key](const std::pair &entry) { + return entry.first == key && entry.second == true; + }); + if (buffer_iterator == buffer.end()) { + chord_found = false; + break; + } + } + + if (chord_found) { + for (const auto &key : chord.GetKeys()) { + auto buffer_iterator = + std::remove_if(buffer.begin(), buffer.end(), + [key](const std::pair &entry) { + return entry.first == key && entry.second == true; + }); + buffer.erase(buffer_iterator, buffer.end()); + } + return chord.GetChordID(); + } + } + + return 0; +} + +void Input::TriggerChord(int chord_id) { + this->ResetChords(); + + EventManager::GetInstance().RaiseInputEvent( + InputEvent{InputEventType::Chord, SDL_SCANCODE_UNKNOWN, chord_id, true}); +} + +void Input::ResetChords() { + this->start = std::chrono::steady_clock::now(); + this->FlushBuffer(); +} + void Input::RegisterInputChord(int chord_id, std::unordered_set keys) { this->chords.push_back(Chord(chord_id, keys)); } \ No newline at end of file diff --git a/src/engine/includes/Chord.hpp b/src/engine/includes/Chord.hpp index e037f2d..7da9888 100644 --- a/src/engine/includes/Chord.hpp +++ b/src/engine/includes/Chord.hpp @@ -1,7 +1,6 @@ #pragma once #include "SDL_scancode.h" -#include #include class Chord { @@ -9,21 +8,10 @@ class Chord { int chord_id; std::unordered_set keys; - std::vector> buffer; - std::chrono::steady_clock::time_point start; - int64_t elapsed; - int timeout; - - void Reset(); - void Trigger(); - bool BufferContainsChord(); - void FlushBuffer(); - void LogBuffer(); - public: Chord(int chord_id, std::unordered_set keys); - void Process(); - void ProcessKeyPress(SDL_Scancode key, bool pressed); + int GetChordID(); + std::unordered_set GetKeys(); bool IsKeyInChord(SDL_Scancode key); }; \ No newline at end of file diff --git a/src/engine/includes/Input.hpp b/src/engine/includes/Input.hpp index d904988..371bf17 100644 --- a/src/engine/includes/Input.hpp +++ b/src/engine/includes/Input.hpp @@ -3,14 +3,26 @@ #include "Chord.hpp" #include "SDL_scancode.h" #include "SDL_stdinc.h" +#include #include +#include class Input { private: Uint8 *keyboard_state; std::vector chords; + std::vector> buffer; + std::chrono::steady_clock::time_point start; + int64_t elapsed; + int timeout; + bool IsKeyInChords(SDL_Scancode key); + int BufferContainsChord(); + void LogBuffer(); + void FlushBuffer(); + void TriggerChord(int chord_id); + void ResetChords(); public: Input(); diff --git a/src/games/hw4_joshua/hw4_joshua.cpp b/src/games/hw4_joshua/hw4_joshua.cpp index 15e4a31..adac064 100644 --- a/src/games/hw4_joshua/hw4_joshua.cpp +++ b/src/games/hw4_joshua/hw4_joshua.cpp @@ -37,22 +37,18 @@ void HandleAlienSingleInput(InputEvent *event) { SDL_Scancode key = event->key; switch (key) { case SDL_SCANCODE_W: - case SDL_SCANCODE_UP: key_state.up = pressed; break; case SDL_SCANCODE_S: - case SDL_SCANCODE_DOWN: key_state.down = pressed; break; case SDL_SCANCODE_A: - case SDL_SCANCODE_LEFT: key_state.left = pressed; break; case SDL_SCANCODE_D: - case SDL_SCANCODE_RIGHT: key_state.right = pressed; break; @@ -69,28 +65,24 @@ void HandleAlienChordInput(Entity &alien, InputEvent *event) { } switch (event->chord_id) { case 1: - case 5: key_state.power_up = pressed; alien.GetComponent()->SetVelocity( - {alien.GetComponent()->GetVelocity().x, -150}); + {alien.GetComponent()->GetVelocity().x, -200}); break; case 2: - case 6: key_state.power_down = pressed; alien.GetComponent()->SetVelocity( - {alien.GetComponent()->GetVelocity().x, 150}); + {alien.GetComponent()->GetVelocity().x, 200}); break; case 3: - case 7: key_state.power_left = pressed; alien.GetComponent()->SetVelocity( - {-150, alien.GetComponent()->GetVelocity().y}); + {-200, alien.GetComponent()->GetVelocity().y}); break; case 4: - case 8: key_state.power_right = pressed; alien.GetComponent()->SetVelocity( - {150, alien.GetComponent()->GetVelocity().y}); + {200, alien.GetComponent()->GetVelocity().y}); break; default: break; @@ -177,7 +169,8 @@ void UpdateAlien(Entity &alien) { } if (!key_state.left && !key_state.right) { alien.GetComponent()->SetVelocity( - {0, alien.GetComponent()->GetVelocity().y}); + {float(alien.GetComponent()->GetVelocity().x * 0.99), + alien.GetComponent()->GetVelocity().y}); } } @@ -393,8 +386,7 @@ std::vector CreateEnemies() { enemy_index += 1; pos_x += 660; } - // return enemies; - return std::vector(); + return enemies; } std::vector CreateEntities() { @@ -478,16 +470,10 @@ void BindEngineInputs() { } void RegisterInputChords() { - Engine::GetInstance().RegisterInputChord(1, {SDL_SCANCODE_A, SDL_SCANCODE_D}); - - // Engine::GetInstance().RegisterInputChord(1, {SDL_SCANCODE_W, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(2, {SDL_SCANCODE_S, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(3, {SDL_SCANCODE_A, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(4, {SDL_SCANCODE_D, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(5, {SDL_SCANCODE_UP, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(6, {SDL_SCANCODE_DOWN, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(7, {SDL_SCANCODE_LEFT, SDL_SCANCODE_SPACE}); - // Engine::GetInstance().RegisterInputChord(8, {SDL_SCANCODE_RIGHT, SDL_SCANCODE_SPACE}); + Engine::GetInstance().RegisterInputChord(1, {SDL_SCANCODE_W, SDL_SCANCODE_P}); + Engine::GetInstance().RegisterInputChord(2, {SDL_SCANCODE_S, SDL_SCANCODE_P}); + Engine::GetInstance().RegisterInputChord(3, {SDL_SCANCODE_A, SDL_SCANCODE_P}); + Engine::GetInstance().RegisterInputChord(4, {SDL_SCANCODE_D, SDL_SCANCODE_P}); } int main(int argc, char *args[]) { From d014f9f2e010e14442a87a42b564df2293293890 Mon Sep 17 00:00:00 2001 From: Joshua Joseph Date: Thu, 7 Nov 2024 23:41:47 -0500 Subject: [PATCH 3/5] :pencil2: make enemies death-zones and merge ground tiles --- src/engine/EventManager.cpp | 9 +--- src/engine/Input.cpp | 1 - src/games/hw4_joshua/assets/ground.png | Bin 3788 -> 32104 bytes src/games/hw4_joshua/hw4_joshua.cpp | 58 ++++++++----------------- 4 files changed, 20 insertions(+), 48 deletions(-) diff --git a/src/engine/EventManager.cpp b/src/engine/EventManager.cpp index 84b7459..e43e8b8 100644 --- a/src/engine/EventManager.cpp +++ b/src/engine/EventManager.cpp @@ -154,16 +154,9 @@ void EventManager::ProfileEventQueue() { void EventManager::RaiseInputEvent(InputEvent event) { Event input_event = Event(EventType::Input, event); - input_event.SetDelay(-1); + input_event.SetDelay(0); input_event.SetPriority(Priority::High); - if (event.type == InputEventType::Single) { - Log(LogLevel::Info, "Raising single input: [%d] [%d]", event.pressed, event.key); - } - if (event.type == InputEventType::Chord) { - Log(LogLevel::Info, "Raising chord input: [%d], [%d]", event.pressed, event.chord_id); - } - this->Raise(input_event); } diff --git a/src/engine/Input.cpp b/src/engine/Input.cpp index dd47f55..2d62294 100644 --- a/src/engine/Input.cpp +++ b/src/engine/Input.cpp @@ -74,7 +74,6 @@ void Input::Process() { } this->buffer.push_back({key, pressed}); - // this->LogBuffer(); int chord_id = this->BufferContainsChord(); if (chord_id != 0) { diff --git a/src/games/hw4_joshua/assets/ground.png b/src/games/hw4_joshua/assets/ground.png index acd03cd860c829c6179ef12a01e01f5671b54138..323ec060cb82e59bb0ca9dd53ac693789d0cbbad 100644 GIT binary patch literal 32104 zcmeIb3se(lw>}O?D^@F3>s^SqdatOc2qgrJn7QW#nbs9d7uCMre*f?NZH5R%Ny{_jb^@B7YKXRY5_|KmEIZ=Lln$jqCW zWMvul)L}4SIURa8obX=tKNJ)a((rqwl@J_Dj9g zl5vfCdgJw0e)Yx1!`oY`w}tK6bLf>aaN!yHezS{z~fJX8+OnB=Jf2zqgLLza((wlj=sM2tA8JtKFP!V z_gL?^jFQbWCtmFwIezll=C4}RGKMb>sF1fb++-Ulwkn|WxSoO0_~3W+&-hE%dcCy% zH7ybE>?@4MA6S{I?`mpjIAp1w{=4~SdOEjB%u2wA2`0tDFW=SI3|aara!Q&y3M%bQ z^tx9P25jvo@9v&{4(^w0`txtp5AW#N8;x&&IP8Gl)2U#j_pZhle#dFUaeCdSe`P*@ zH;*0%)iL`x6qSw2R!{HUeMiXTS9)n7*IES=-kGe9c5qo{=RB)xa04uf--4V^~lwY+)r z?L}y4X=#}N*4^qY1qB6BLTiGMG|P=uS0W=L8(+VE-AUR=c}l9G?G7lms`%owpjgu& zc>n>aw8;Gt1jN&_9r&W#GmWQ34ex1ZEE{F2*G;SBjaB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sdA~)FA#&uo>*ll7)j++ULXz z683B0it(VjKIwvLm$z}a+cQ?VwUp-EPD0tAwm?Mf1w-#x)FV)3tO(?M4Vt!ZdvDNq7u5TS`jiS|vW)crs6~xgRA|7^3;l#MxIICF&JXJHUBL#b*OUvj@zIrK=}ks>9}P}IO{EefCCQRJN8v5Wv% zK-?Xwe})=rwDke4)fay_+x3I{<9sHmWYmV9~JF18fZA(}PC z1OTl?5fy?`y{T>(NuaM=0RB8?6fD{&`ySjnT)lFsX~x3&!ld^8A4l zUEf?wvg?-ME88~g?>#2F3J=o`BJr~lm1)B9oQ?2kRVdOZ1;38@Vu4!Pj5+vuU&QX3;P;D*$1V#Sj2 zWMdFNa_QCDyUX>5Bo(yL6@AO0m&A8QVR}95;I!GHcEm0nXfg-HNYO9Ig~Bw@3ZkTU zpU@YK(5*tP)jUC5G9O(hlAs@uw@g3JnJ!%E>WopNV?7w}0A%Obpk)1Ze(n1<@p0KH zIK)*M90AGw1k@xEPe+2fJ;|X{AO<5LGAnahmK4??PjsdZC^BUQ@C)k*1R6#k%8n;}knQ`PQDru$g0$wZQ&JF)PB>TArQ}5pW0r9< zU!Oyp5U(0HuhaRXv#F?wZV&o9bw!9$B6o!!kZ9ZnmvN$UB_&V0_f z>W%O~hR3~9Xzt`V9{9Ol(w1bbe!9U9tjVjkPwvf^b;0IJ*l!hZC}*oiiNF{Ms^P*B}Jm{JK27bh=`~Uy| diff --git a/src/games/hw4_joshua/hw4_joshua.cpp b/src/games/hw4_joshua/hw4_joshua.cpp index adac064..bf53dd6 100644 --- a/src/games/hw4_joshua/hw4_joshua.cpp +++ b/src/games/hw4_joshua/hw4_joshua.cpp @@ -23,10 +23,6 @@ struct KeyState { bool down; bool left; bool right; - bool power_up; - bool power_down; - bool power_left; - bool power_right; } key_state; void Update(std::vector &entities) {} @@ -65,22 +61,18 @@ void HandleAlienChordInput(Entity &alien, InputEvent *event) { } switch (event->chord_id) { case 1: - key_state.power_up = pressed; alien.GetComponent()->SetVelocity( {alien.GetComponent()->GetVelocity().x, -200}); break; case 2: - key_state.power_down = pressed; alien.GetComponent()->SetVelocity( {alien.GetComponent()->GetVelocity().x, 200}); break; case 3: - key_state.power_left = pressed; alien.GetComponent()->SetVelocity( {-200, alien.GetComponent()->GetVelocity().y}); break; case 4: - key_state.power_right = pressed; alien.GetComponent()->SetVelocity( {200, alien.GetComponent()->GetVelocity().y}); break; @@ -123,12 +115,6 @@ void HandleAlienCollision(Entity &alien, Event &event) { return; } - if (collider->GetName().find("enemy") == 0) { - Log(LogLevel::Info, ""); - Log(LogLevel::Info, "You lost :("); - Log(LogLevel::Info, ""); - app->quit.store(true); - } if (collider->GetName().find("house") == 0) { Log(LogLevel::Info, ""); Log(LogLevel::Info, "You made it home!"); @@ -288,23 +274,19 @@ Entity *CreateSun() { return sun; } -std::vector CreateGround() { - std::vector ground; - for (int i = 0; i < (window_size.width / TILE_SIZE) * 2; i++) { - Entity *ground_tile = new Entity("ground_" + std::to_string(i), EntityCategory::Stationary); - ground_tile->AddComponent(); - ground_tile->AddComponent(); - ground_tile->AddComponent(); - ground_tile->AddComponent(); - - ground_tile->GetComponent()->SetColor(Color{0, 0, 0, 0}); - ground_tile->GetComponent()->SetPosition( - Position{float(i * TILE_SIZE), float(window_size.height - TILE_SIZE)}); - ground_tile->GetComponent()->SetSize(Size{TILE_SIZE, TILE_SIZE}); - ground_tile->GetComponent()->SetTexture("assets/ground.png"); - ground_tile->GetComponent()->SetOwner(NetworkRole::Client); - ground.push_back(ground_tile); - } +Entity *CreateGround() { + Entity *ground = new Entity("ground", EntityCategory::Stationary); + ground->AddComponent(); + ground->AddComponent(); + ground->AddComponent(); + ground->AddComponent(); + + ground->GetComponent()->SetColor(Color{0, 0, 0, 0}); + ground->GetComponent()->SetPosition( + Position{0, float(window_size.height - TILE_SIZE)}); + ground->GetComponent()->SetSize(Size{TILE_SIZE * 38, TILE_SIZE}); + ground->GetComponent()->SetTexture("assets/ground.png"); + ground->GetComponent()->SetOwner(NetworkRole::Client); return ground; } @@ -359,11 +341,12 @@ std::vector CreateClouds() { std::vector CreateEnemies() { std::vector enemies; int enemy_index = 0; - float pos_x = 220.0f; + float pos_x = 1540.0f; float pos_y = float(window_size.height - (TILE_SIZE * 2)); while (pos_x < 3000) { - Entity *enemy = new Entity("enemy_" + std::to_string(enemy_index), EntityCategory::Moving); + Entity *enemy = + new Entity("enemy_" + std::to_string(enemy_index), EntityCategory::DeathZone); enemy->AddComponent(); enemy->AddComponent(); enemy->AddComponent(); @@ -371,7 +354,7 @@ std::vector CreateEnemies() { enemy->AddComponent(); float pos_y_offset = enemy_index % 2 == 0 ? -(TILE_SIZE * 3) : 0; - float vel_y = enemy_index % 2 == 0 ? 30 : -30; + float vel_y = enemy_index % 2 == 0 ? 20 : -20; enemy->GetComponent()->SetPosition(Position{pos_x, pos_y + pos_y_offset}); enemy->GetComponent()->SetSize(Size{TILE_SIZE, TILE_SIZE}); @@ -394,14 +377,11 @@ std::vector CreateEntities() { Entity *platform = CreatePlatform(); Entity *house = CreateHouse(); Entity *sun = CreateSun(); - std::vector ground = CreateGround(); + Entity *ground = CreateGround(); std::vector clouds = CreateClouds(); std::vector enemies = CreateEnemies(); - std::vector entities = std::vector({alien, platform, house, sun}); - for (Entity *ground_tile : ground) { - entities.push_back(ground_tile); - } + std::vector entities = std::vector({alien, platform, house, sun, ground}); for (Entity *cloud : clouds) { entities.push_back(cloud); } From 3fff4dac3ebb1ac6f8c18f5d7176c7e6d100d068 Mon Sep 17 00:00:00 2001 From: Joshua Joseph Date: Thu, 7 Nov 2024 23:46:07 -0500 Subject: [PATCH 4/5] :pencil2: reduce velocity of vertical power ups --- src/games/hw4_joshua/hw4_joshua.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/games/hw4_joshua/hw4_joshua.cpp b/src/games/hw4_joshua/hw4_joshua.cpp index bf53dd6..1f6a3ad 100644 --- a/src/games/hw4_joshua/hw4_joshua.cpp +++ b/src/games/hw4_joshua/hw4_joshua.cpp @@ -62,11 +62,11 @@ void HandleAlienChordInput(Entity &alien, InputEvent *event) { switch (event->chord_id) { case 1: alien.GetComponent()->SetVelocity( - {alien.GetComponent()->GetVelocity().x, -200}); + {alien.GetComponent()->GetVelocity().x, -150}); break; case 2: alien.GetComponent()->SetVelocity( - {alien.GetComponent()->GetVelocity().x, 200}); + {alien.GetComponent()->GetVelocity().x, 150}); break; case 3: alien.GetComponent()->SetVelocity( From 5ae3bef2a25673e8bee3c669562399f129c61978 Mon Sep 17 00:00:00 2001 From: ron-matt163 Date: Thu, 7 Nov 2024 23:56:15 -0500 Subject: [PATCH 5/5] Null check for the physics component in HandlePairwiseCollisions and Chord support in HW4 Rohan game --- src/engine/Collision.cpp | 24 +++++---- src/games/hw4_rohan/hw4_rohan.cpp | 84 +++++++++++++++++++------------ 2 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/engine/Collision.cpp b/src/engine/Collision.cpp index ae3ca61..57862ee 100644 --- a/src/engine/Collision.cpp +++ b/src/engine/Collision.cpp @@ -72,8 +72,6 @@ void Collision::HandlePairwiseCollision(Entity *collider) { Overlap overlap = GetOverlap(rect_1, rect_2); int pos_x = 0, pos_y = 0; - float vel_x = this->entity->GetComponent()->GetVelocity().x; - float vel_y = this->entity->GetComponent()->GetVelocity().y; if (overlap == Overlap::Left) { pos_x = col_x - obj_width; @@ -89,18 +87,22 @@ void Collision::HandlePairwiseCollision(Entity *collider) { pos_y = col_y + col_height; } - this->entity->GetComponent()->SetPosition(Position{float(pos_x), float(pos_y)}); + if (this->entity->GetComponent()) { + this->entity->GetComponent()->SetPosition(Position{float(pos_x), float(pos_y)}); + float vel_x = this->entity->GetComponent()->GetVelocity().x; + float vel_y = this->entity->GetComponent()->GetVelocity().y; - if (collider->GetCategory() != EntityCategory::SideBoundary) { - if (overlap == Overlap::Left || overlap == Overlap::Right) { - vel_x *= -this->GetRestitution(); - } - if (overlap == Overlap::Top || overlap == Overlap::Bottom) { - vel_y *= -this->GetRestitution(); + if (collider->GetCategory() != EntityCategory::SideBoundary) { + if (overlap == Overlap::Left || overlap == Overlap::Right) { + vel_x *= -this->GetRestitution(); + } + if (overlap == Overlap::Top || overlap == Overlap::Bottom) { + vel_y *= -this->GetRestitution(); + } } - } - this->entity->GetComponent()->SetVelocity(Velocity{vel_x, vel_y}); + this->entity->GetComponent()->SetVelocity(Velocity{vel_x, vel_y}); + } } void Collision::Update() {} diff --git a/src/games/hw4_rohan/hw4_rohan.cpp b/src/games/hw4_rohan/hw4_rohan.cpp index f7ca54c..7ba7eb9 100644 --- a/src/games/hw4_rohan/hw4_rohan.cpp +++ b/src/games/hw4_rohan/hw4_rohan.cpp @@ -39,9 +39,34 @@ void AssignOperationsToKeys() { Engine::GetInstance().RegisterInputChord(3, {SDL_SCANCODE_UP, SDL_SCANCODE_SPACE}); } -void HandlePlayerSingleInput(InputEvent event) { - bool pressed = event.pressed; - SDL_Scancode key = event.key; +// Pass a nullptr if the input event was not a chord event so that the chord actions are disabled. +void HandlePlayerChordInput(InputEvent *event) { + if (event) { + bool pressed = event->pressed; + + switch (event->chord_id) { + case 1: + player_event.dash_left = pressed; + break; + case 2: + player_event.dash_right = pressed; + break; + case 3: + player_event.power_jump = pressed; + break; + default: + break; + } + } else { + // Chord release events are not raised + player_event.dash_left = player_event.dash_right = player_event.power_jump = false; + } +} + +void HandlePlayerSingleInput(InputEvent *event) { + HandlePlayerChordInput(nullptr); + bool pressed = event->pressed; + SDL_Scancode key = event->key; switch (key) { case SDL_SCANCODE_LEFT: @@ -60,39 +85,16 @@ void HandlePlayerSingleInput(InputEvent event) { } } -void HandlePlayerChordInput(Entity &player, InputEvent &event) { - bool pressed = event.pressed; - - switch (event.chord_id) { - case 1: - player_event.dash_left = pressed; - player.GetComponent()->SetVelocity( - {-90, player.GetComponent()->GetVelocity().y}); - break; - case 2: - player_event.dash_right = pressed; - player.GetComponent()->SetVelocity( - {90, player.GetComponent()->GetVelocity().y}); - break; - case 3: - player_event.power_jump = pressed; - player.GetComponent()->SetVelocity( - {player.GetComponent()->GetVelocity().x, -100}); - break; - default: - break; - } -} - void HandlePlayerEvent(Entity &player, Event &event) { InputEvent *input_event = std::get_if(&(event.data)); + if (input_event) { switch (input_event->type) { case InputEventType::Single: - HandlePlayerSingleInput(*input_event); + HandlePlayerSingleInput(input_event); break; case InputEventType::Chord: - HandlePlayerChordInput(player, *input_event); + HandlePlayerChordInput(input_event); break; default: break; @@ -107,17 +109,36 @@ void UpdatePlayer(Entity &player) { player_moved = true; player.GetComponent()->SetVelocity( {30, player.GetComponent()->GetVelocity().y}); - } else if (player_event.move_left) { + } + if (player_event.move_left) { player_moved = true; player.GetComponent()->SetVelocity( {-30, player.GetComponent()->GetVelocity().y}); } - if (player_event.jump) { + // Log(LogLevel::Info, "Regular jump"); player_moved = true; player.GetComponent()->SetVelocity( {player.GetComponent()->GetVelocity().x, -30}); } + if (player_event.dash_left) { + // Log(LogLevel::Info, "Left dash!"); + player.GetComponent()->SetVelocity( + {-90, player.GetComponent()->GetVelocity().y}); + player_moved = true; + } + if (player_event.dash_right) { + // Log(LogLevel::Info, "Right dash!"); + player.GetComponent()->SetVelocity( + {90, player.GetComponent()->GetVelocity().y}); + player_moved = true; + } + if (player_event.power_jump) { + // Log(LogLevel::Info, "Power jump!"); + player.GetComponent()->SetVelocity( + {player.GetComponent()->GetVelocity().x, -100}); + player_moved = true; + } if (!player_moved) { player.GetComponent()->SetVelocity( @@ -330,7 +351,6 @@ Entity *CreatePlayer() { player->AddComponent(); player->AddComponent(); - // player->GetComponent()->SetPosition({300, 300}); player->GetComponent()->SetSize({50, 100}); player->GetComponent()->SetAcceleration({0, 10});