From 02ff10520ff74e24bff743f32439b0edc2a72bb4 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sat, 14 Mar 2026 11:10:54 -0400 Subject: [PATCH 1/3] feat: add action bindings --- CMakeLists.txt | 2 +- CMakePresets.json | 6 ++- index.html | 4 ++ src/main.cpp | 6 +-- src/scenes/game.h | 16 +++---- src/scenes/init.h | 55 ++++++++++++++++++++++ src/scenes/level_select.h | 96 +++++++++++++++++++++++---------------- src/scenes/menu.h | 4 +- src/scenes/scenes.h | 2 +- src/scenes/win.h | 5 +- 10 files changed, 135 insertions(+), 61 deletions(-) create mode 100644 src/scenes/init.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ea070d..6815c35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) include(cmake/get_cpm.cmake) -CPMAddPackage("gh:adsgames/asw@0.8.0") +CPMAddPackage("gh:adsgames/asw#9e541deba7c39097e47b6beee8e9ba3afb834667") CPMAddPackage("gh:nlohmann/json@3.11.3") # Source code diff --git a/CMakePresets.json b/CMakePresets.json index 3516c98..856502b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -32,13 +32,15 @@ "name": "debug", "description": "Build a debug build", "displayName": "debug", - "configurePreset": "debug" + "configurePreset": "debug", + "jobs": 0 }, { "name": "release", "description": "Build a release build", "displayName": "release", - "configurePreset": "release" + "configurePreset": "release", + "jobs": 0 } ] } diff --git a/index.html b/index.html index 89882cf..7036885 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,10 @@ display: flex; margin: 0 auto; } + + canvas { + image-rendering: pixelated; + } diff --git a/src/main.cpp b/src/main.cpp index f30d6d0..57d8ab0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include #include "./scenes/game.h" +#include "./scenes/init.h" #include "./scenes/intro.h" #include "./scenes/level_select.h" #include "./scenes/menu.h" @@ -20,17 +21,16 @@ int main() // Initializing asw::core::init(1280, 960); - asw::display::set_title("Mazes"); - asw::display::set_icon("assets/mazes.ico"); // Starts Game auto app = asw::scene::SceneManager(); + app.register_scene(Init, app); app.register_scene(Game, app); app.register_scene(Menu, app); app.register_scene(Win, app); app.register_scene(LevelSelect, app); app.register_scene(Intro, app); - app.set_next_scene(Intro); + app.set_next_scene(Init); app.start(); return 0; diff --git a/src/scenes/game.h b/src/scenes/game.h index 9f061fa..4b318af 100644 --- a/src/scenes/game.h +++ b/src/scenes/game.h @@ -82,14 +82,14 @@ class GameScene : public asw::scene::Scene { Scene::update(dt); // Toggle pause - if (get_key_down(Key::Escape)) { + if (is_action_pressed("pause")) { paused = !paused; } // Skip updates when paused if (paused) { // TO menu - if (get_key_down(Key::M)) { + if (is_action_pressed("back")) { manager.set_next_scene(GameState::Menu); } return; @@ -104,7 +104,7 @@ class GameScene : public asw::scene::Scene { } // Use broom - broom_active = get_key(Key::Space) && has_broom; + broom_active = is_action_down("interact") && has_broom; // Character movement character_move(); @@ -118,7 +118,7 @@ class GameScene : public asw::scene::Scene { } // Restart Map - if (get_key_down(Key::R)) { + if (is_action_pressed("restart")) { changeMap(); } @@ -229,16 +229,16 @@ class GameScene : public asw::scene::Scene { { using namespace asw::input; - if (get_key(Key::Up) || get_key(Key::W)) { + if (is_action_down("up")) { rotation = 128; move_towards({ 0, -1 }); - } else if (get_key(Key::Down) || get_key(Key::S)) { + } else if (is_action_down("down")) { rotation = 0; move_towards({ 0, 1 }); - } else if (get_key(Key::Left) || get_key(Key::A)) { + } else if (is_action_down("left")) { rotation = 64; move_towards({ -1, 0 }); - } else if (get_key(Key::Right) || get_key(Key::D)) { + } else if (is_action_down("right")) { rotation = 192; move_towards({ 1, 0 }); } diff --git a/src/scenes/init.h b/src/scenes/init.h new file mode 100644 index 0000000..7777f33 --- /dev/null +++ b/src/scenes/init.h @@ -0,0 +1,55 @@ + +#pragma once + +#include + +#include "./scenes.h" + +class InitScene : public asw::scene::Scene { +public: + using asw::scene::Scene::Scene; + + void init() override + { + using namespace asw::input; + + asw::display::set_title("Mazes"); + asw::display::set_icon("assets/mazes.ico"); + + // Bind global actions + bind_action("right", KeyBinding { Key::Right }); + bind_action("right", KeyBinding { Key::D }); + bind_action("right", ControllerButtonBinding { ControllerButton::DPadRight, 0 }); + bind_action("right", ControllerAxisBinding { ControllerAxis::LeftX, 0, 0.1F, true }); + + bind_action("left", KeyBinding { Key::Left }); + bind_action("left", KeyBinding { Key::A }); + bind_action("left", ControllerButtonBinding { ControllerButton::DPadLeft, 0 }); + bind_action("left", ControllerAxisBinding { ControllerAxis::LeftX, 0, -0.1F, true }); + + bind_action("up", KeyBinding { Key::Up }); + bind_action("up", KeyBinding { Key::W }); + bind_action("up", ControllerButtonBinding { ControllerButton::DPadUp, 0 }); + // bind_action("up", ControllerAxisBinding { ControllerAxis::LeftY, 0, -0.1F, false }); + + bind_action("down", KeyBinding { Key::Down }); + bind_action("down", KeyBinding { Key::S }); + bind_action("down", ControllerButtonBinding { ControllerButton::DPadDown, 0 }); + // bind_action("down", ControllerAxisBinding { ControllerAxis::LeftY, 0, 0.1F, true }); + + bind_action("interact", KeyBinding { Key::Return }); + bind_action("interact", KeyBinding { Key::Space }); + bind_action("interact", ControllerButtonBinding { ControllerButton::A, 0 }); + + bind_action("back", KeyBinding { Key::Escape }); + bind_action("back", ControllerButtonBinding { ControllerButton::Back, 0 }); + + bind_action("pause", KeyBinding { Key::P }); + bind_action("pause", ControllerButtonBinding { ControllerButton::Start, 0 }); + } + + void update(float dt) override + { + manager.set_next_scene(GameState::Intro); + } +}; \ No newline at end of file diff --git a/src/scenes/level_select.h b/src/scenes/level_select.h index 56e165b..cb5ad47 100644 --- a/src/scenes/level_select.h +++ b/src/scenes/level_select.h @@ -19,47 +19,32 @@ class LevelSelectScene : public asw::scene::Scene { // Load font const auto font = asw::assets::load_font("assets/fonts/jersey-10.ttf", 48); - // Load sounds - const auto click = asw::assets::load_sample("assets/sfx/click.wav"); - // Build UI tree - ui_root_ = asw::ui::Root(); - ui_root_.root.transform.set_size(1280, 960); - ui_root_.root.bg_image = asw::assets::load_texture("assets/images/background.png"); + _ui_root = asw::ui::Root(); + _ui_root.root.transform.set_size(1280, 960); + _ui_root.root.bg_image = asw::assets::load_texture("assets/images/background.png"); // Setup buttons - auto& btn_left = ui_root_.root.add_child(); + auto& btn_left = _ui_root.root.add_child(); btn_left.text = "<"; btn_left.font = font; btn_left.transform.set_position(100, 420); btn_left.transform.set_size(64, 64); - btn_left.on_click = [this, click]() { - const auto file_path = std::format("assets/levels/level{}.json", GameScene::level - 1); - if (tilemap_.load(file_path)) { - asw::sound::play(click); - GameScene::level--; - } - }; + btn_left.on_click = [this]() { previous_level(); }; - auto& btn_play = ui_root_.root.add_child(); + auto& btn_play = _ui_root.root.add_child(); btn_play.transform.set_position(320, 220); btn_play.transform.set_size(640, 480); btn_play.on_click = [this]() { manager.set_next_scene(GameState::Game); }; - auto& btn_right = ui_root_.root.add_child(); + auto& btn_right = _ui_root.root.add_child(); btn_right.text = ">"; btn_right.font = font; btn_right.transform.set_position(1280 - 64 - 100, 420); btn_right.transform.set_size(64, 64); - btn_right.on_click = [this, click]() { - const auto file_path = std::format("assets/levels/level{}.json", GameScene::level + 1); - if (tilemap_.load(file_path)) { - asw::sound::play(click); - GameScene::level++; - } - }; + btn_right.on_click = [this]() { next_level(); }; - auto& back = ui_root_.root.add_child(); + auto& back = _ui_root.root.add_child(); back.text = "Back"; back.font = font; back.transform.set_position(40, 856); @@ -67,17 +52,17 @@ class LevelSelectScene : public asw::scene::Scene { back.on_click = [this]() { manager.set_next_scene(GameState::Menu); }; // Level text - auto& level_text = ui_root_.root.add_child(); + auto& level_text = _ui_root.root.add_child(); level_text.font = font; level_text.color = palette::white; level_text.justify = asw::TextJustify::Center; level_text.transform.set_position(640, 760); - level_text_ref_ = &level_text; + _level_text_ref = &level_text; // Load sprites // Load tilemap - tilemap_.load(std::format("assets/levels/level{}.json", GameScene::level)); - tilemap_.setRenderConfig( + _tilemap.load(std::format("assets/levels/level{}.json", GameScene::level)); + _tilemap.setRenderConfig( { .tile_size = 20, .render_size = 30, .offset_x = 320, .offset_y = 220 }); } @@ -86,37 +71,70 @@ class LevelSelectScene : public asw::scene::Scene { Scene::update(dt); // Text - level_text_ref_->text - = std::format("Level {}: {}", GameScene::level, tilemap_.getLevelText()); + _level_text_ref->text + = std::format("Level {}: {}", GameScene::level, _tilemap.getLevelText()); // UI State - ui_root_.update(); + _ui_root.update(); - // Go to menu - if (asw::input::get_key_down(asw::input::Key::Escape)) { + // Keyboard shortcuts + if (asw::input::is_action_pressed("back")) { manager.set_next_scene(GameState::Menu); } + if (asw::input::is_action_pressed("left")) { + previous_level(); + } + if (asw::input::is_action_pressed("right")) { + next_level(); + } + if (asw::input::is_action_pressed("interact")) { + select_level(); + } } void draw() override { Scene::draw(); - ui_root_.draw(); + _ui_root.draw(); - tilemap_.renderBackground(); + _tilemap.renderBackground(); // Mini tiles tiles for (int i = 0; i < TileMap::WIDTH; i++) { for (int t = 0; t < TileMap::HEIGHT; t++) { - tilemap_.render({ i, t }); + _tilemap.render({ i, t }); } } } private: - asw::ui::Root ui_root_; - asw::ui::Label* level_text_ref_; + asw::ui::Root _ui_root; + asw::ui::Label* _level_text_ref; + asw::Sample _click; + + TileMap _tilemap; - TileMap tilemap_; + void next_level() + { + const auto file_path = std::format("assets/levels/level{}.json", GameScene::level + 1); + if (_tilemap.load(file_path)) { + asw::sound::play(_click); + GameScene::level++; + } + } + + void previous_level() + { + const auto file_path = std::format("assets/levels/level{}.json", GameScene::level - 1); + if (_tilemap.load(file_path)) { + asw::sound::play(_click); + GameScene::level--; + } + } + + void select_level() + { + manager.set_next_scene(GameState::Game); + } }; \ No newline at end of file diff --git a/src/scenes/menu.h b/src/scenes/menu.h index 1fb4640..21f00f3 100644 --- a/src/scenes/menu.h +++ b/src/scenes/menu.h @@ -72,9 +72,7 @@ class MenuScene : public asw::scene::Scene { { Scene::update(dt); - if (spr_help_->visible - && (asw::input::keyboard.any_pressed - || asw::input::get_mouse_button(asw::input::MouseButton::Left))) { + if (spr_help_->visible && asw::input::is_action_pressed("back")) { spr_help_->visible = false; return; } diff --git a/src/scenes/scenes.h b/src/scenes/scenes.h index f9dd7e4..3406b47 100644 --- a/src/scenes/scenes.h +++ b/src/scenes/scenes.h @@ -1,4 +1,4 @@ #pragma once /// Scene stuff to get working in browser -enum class GameState { Intro, Menu, LevelSelect, Game, Win }; \ No newline at end of file +enum class GameState { Init, Intro, Menu, LevelSelect, Game, Win }; \ No newline at end of file diff --git a/src/scenes/win.h b/src/scenes/win.h index a741265..6d9018f 100644 --- a/src/scenes/win.h +++ b/src/scenes/win.h @@ -21,10 +21,7 @@ class WinScene : public asw::scene::Scene { { Scene::update(dt); - if (asw::input::get_key_down(asw::input::Key::Space) - || asw::input::get_key_down(asw::input::Key::Return) - || asw::input::get_key_down(asw::input::Key::Escape) - || asw::input::get_mouse_button_down(asw::input::MouseButton::Left)) { + if (asw::input::is_action_pressed("interact") || asw::input::is_action_pressed("back")) { manager.set_next_scene(GameState::Menu); } } From e6b420a60dfb41c5e3605f92b40bfb0f7dbf2933 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Mon, 16 Mar 2026 19:02:28 -0400 Subject: [PATCH 2/3] chore: bump asw --- CMakeLists.txt | 2 +- src/scenes/game.h | 2 +- src/scenes/menu.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6815c35..4572502 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) include(cmake/get_cpm.cmake) -CPMAddPackage("gh:adsgames/asw#9e541deba7c39097e47b6beee8e9ba3afb834667") +CPMAddPackage("gh:adsgames/asw#1124854a08dc5b3076063aad200f9f0b566f950f") CPMAddPackage("gh:nlohmann/json@3.11.3") # Source code diff --git a/src/scenes/game.h b/src/scenes/game.h index 4b318af..04c0d95 100644 --- a/src/scenes/game.h +++ b/src/scenes/game.h @@ -72,7 +72,7 @@ class GameScene : public asw::scene::Scene { { .tile_size = 40, .render_size = 60, .offset_x = 0, .offset_y = 0 }); // Background Music - fade_in_music(song, 1.0F, 1000); + asw::sound::play_music(song, 1.0F, 1000); } void update(float dt) override diff --git a/src/scenes/menu.h b/src/scenes/menu.h index 21f00f3..d35f4a6 100644 --- a/src/scenes/menu.h +++ b/src/scenes/menu.h @@ -43,7 +43,7 @@ class MenuScene : public asw::scene::Scene { auto& quit = column.add_child(); quit.text = "Quit"; quit.transform.size.y = 48; - quit.on_click = []() { asw::core::exit = true; }; + quit.on_click = []() { asw::core::exit(); }; quit.font = font_small; // Add text From 079cc40cdecbd5f6cb996dabdb04ba266f0b2712 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Thu, 19 Mar 2026 21:09:01 -0400 Subject: [PATCH 3/3] fix: action bindings --- CMakeLists.txt | 2 +- src/main.cpp | 1 + src/scenes/game.h | 82 ++++++++++++++++++++++++---------------------- src/scenes/init.h | 8 ++--- src/scenes/intro.h | 6 ++-- src/scenes/win.h | 4 +-- src/tilemap.cpp | 25 ++++++++------ src/tilemap.h | 11 +++---- 8 files changed, 74 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4572502..2bbdc16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) include(cmake/get_cpm.cmake) -CPMAddPackage("gh:adsgames/asw#1124854a08dc5b3076063aad200f9f0b566f950f") +CPMAddPackage("gh:adsgames/asw@0.9.1") CPMAddPackage("gh:nlohmann/json@3.11.3") # Source code diff --git a/src/main.cpp b/src/main.cpp index 57d8ab0..1f8083f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ int main() // Initializing asw::core::init(1280, 960); + asw::core::print_info(); // Starts Game auto app = asw::scene::SceneManager(); diff --git a/src/scenes/game.h b/src/scenes/game.h index 04c0d95..b5ef383 100644 --- a/src/scenes/game.h +++ b/src/scenes/game.h @@ -34,7 +34,7 @@ class GameScene : public asw::scene::Scene { move_acc = 0.0F; paused = false; lives = DEFAULT_LIVES; - position = asw::Vec2(40, 40); + position = asw::Vec2i(40, 40); rotation = 0; has_broom = false; broom_active = false; @@ -155,11 +155,11 @@ class GameScene : public asw::scene::Scene { } // Draws Stats - rect_fill(asw::Quad(0, 0, 1280, 20), asw::Color(0, 0, 0, 200)); + rect_fill(asw::Quadf(0, 0, 1280, 20), asw::Color(0, 0, 0, 200)); - text(font, std::format("Score: {}", score), asw::Vec2(0, 0), palette::white); - text(font, std::format("Lives: {}", lives), asw::Vec2(100, 0), palette::white); - text(font, tilemap.getLevelText(), asw::Vec2(640, 0), palette::white, + text(font, std::format("Score: {}", score), asw::Vec2f(0, 0), palette::white); + text(font, std::format("Lives: {}", lives), asw::Vec2f(100, 0), palette::white); + text(font, tilemap.getLevelText(), asw::Vec2f(640, 0), palette::white, asw::TextJustify::Center); // Robot progress meter @@ -172,29 +172,27 @@ class GameScene : public asw::scene::Scene { const float progress = tilemap.getProgress(); // Background - rect_fill( - asw::Quad(meterX, meterY, meterWidth, meterHeight), palette::dark_gray); + rect_fill(asw::Quadf(meterX, meterY, meterWidth, meterHeight), palette::dark_gray); // Filled portion (red when robots remain, green when cleared) const auto barColor = tilemap.getCompleted() ? palette::green : palette::red; - rect_fill( - asw::Quad(meterX, meterY, meterWidth * progress, meterHeight), barColor); + rect_fill(asw::Quadf(meterX, meterY, meterWidth * progress, meterHeight), barColor); // Border - rect(asw::Quad(meterX, meterY, meterWidth, meterHeight), palette::white); + rect(asw::Quadf(meterX, meterY, meterWidth, meterHeight), palette::white); // Label text(font, std::format("Robots: {}/{}", tilemap.getRobotsCaptured(), tilemap.getRobotsTotal()), - asw::Vec2(meterX - 5.0F, 0), palette::white, asw::TextJustify::Right); + asw::Vec2f(meterX - 5.0F, 0), palette::white, asw::TextJustify::Right); } // Pause Game if (paused) { - rect_fill(asw::Quad(300, 300, 680, 360), palette::very_dark_green); + rect_fill(asw::Quadf(300, 300, 680, 360), palette::very_dark_green); text(font_pause, "Paused press ESC to resume. Press M to go to the Menu.", - asw::Vec2(640, 480), palette::white, asw::TextJustify::Center); + asw::Vec2f(640, 480), palette::white, asw::TextJustify::Center); } } @@ -204,7 +202,7 @@ class GameScene : public asw::scene::Scene { using namespace asw::input; const auto float_pos - = asw::Vec2(static_cast(position.x), static_cast(position.y)); + = asw::Vec2f(static_cast(position.x), static_cast(position.y)); // Draws Character if (rotation == 0) { @@ -219,7 +217,7 @@ class GameScene : public asw::scene::Scene { // Draws broom if needed if (broom_active) { - rotate_sprite(broom, float_pos + asw::Vec2(10, 10), rotation); + rotate_sprite(broom, float_pos + asw::Vec2f(10, 10), rotation); } } @@ -232,19 +230,22 @@ class GameScene : public asw::scene::Scene { if (is_action_down("up")) { rotation = 128; move_towards({ 0, -1 }); - } else if (is_action_down("down")) { + } + if (is_action_down("down")) { rotation = 0; move_towards({ 0, 1 }); - } else if (is_action_down("left")) { + } + if (is_action_down("left")) { rotation = 64; move_towards({ -1, 0 }); - } else if (is_action_down("right")) { + } + if (is_action_down("right")) { rotation = 192; move_towards({ 1, 0 }); } } - void move_towards(const asw::Vec2& target) + void move_towards(const asw::Vec2i& target) { using namespace asw::input; @@ -254,12 +255,10 @@ class GameScene : public asw::scene::Scene { move_acc = 0; - auto player_pos = asw::Vec2(position.x / 40, position.y / 40); + auto player_pos = asw::Vec2i(position.x / 40, position.y / 40); auto tile_pos = player_pos + target; - auto tile_next_pos = player_pos + target * 2; auto tile = tilemap.at(tile_pos); - auto next_tile = tilemap.at(tile_next_pos); // Allow walking into if (tile == TileType::Empty || tile == TileType::WallWalkable || tile == TileType::Robot) { @@ -272,6 +271,22 @@ class GameScene : public asw::scene::Scene { return; } + if (tile == TileType::JanitorRoom && !has_broom) { + asw::sound::play(door); + has_broom = true; + tilemap.setValue(tile_pos, TileType::JanitorRoomOpen); + return; + } + + if (tile == TileType::JanitorRoomOpen && tilemap.getCompleted()) { + level_complete = true; + return; + } + + // Check for box pushing or broom sweeping + auto tile_next_pos = player_pos + target * 2; + auto next_tile = tilemap.at(tile_next_pos); + if (tile == TileType::Box && next_tile == TileType::Empty) { asw::sound::play(boxslide); tilemap.setValue(tile_pos, TileType::Empty); @@ -307,18 +322,6 @@ class GameScene : public asw::scene::Scene { asw::sound::play(trash); return; } - - if (tile == TileType::JanitorRoom && !has_broom) { - asw::sound::play(door); - has_broom = true; - tilemap.setValue(tile_pos, TileType::JanitorRoomOpen); - return; - } - - if (tile == TileType::JanitorRoomOpen && tilemap.getCompleted()) { - level_complete = true; - return; - } } void update_robots() @@ -326,7 +329,7 @@ class GameScene : public asw::scene::Scene { const auto player_pos = position / 40; // Collect all robot positions first to avoid double-processing - std::vector> robots; + std::vector robots; for (int i = 0; i < TileMap::WIDTH; i++) { for (int t = 0; t < TileMap::HEIGHT; t++) { @@ -343,8 +346,9 @@ class GameScene : public asw::scene::Scene { } // Build list of valid moves - std::array, 4> moves = { { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } } }; - std::vector> valid; + const std::array moves + = { { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } } }; + std::vector valid; for (const auto& m : moves) { const auto next_pos = r + m; @@ -364,7 +368,7 @@ class GameScene : public asw::scene::Scene { // 50% chance to move toward the player, 50% random const int random_index = asw::random::between(0, valid.size() - 1); - asw::Vec2 chosen = valid[random_index]; + asw::Vec2i chosen = valid[random_index]; if (asw::random::chance()) { auto bestDist = player_pos.distance(r + chosen); @@ -405,7 +409,7 @@ class GameScene : public asw::scene::Scene { float move_acc; // Player - asw::Vec2 position; + asw::Vec2i position; int rotation; bool has_broom; bool broom_active; diff --git a/src/scenes/init.h b/src/scenes/init.h index 7777f33..7f798bf 100644 --- a/src/scenes/init.h +++ b/src/scenes/init.h @@ -20,22 +20,22 @@ class InitScene : public asw::scene::Scene { bind_action("right", KeyBinding { Key::Right }); bind_action("right", KeyBinding { Key::D }); bind_action("right", ControllerButtonBinding { ControllerButton::DPadRight, 0 }); - bind_action("right", ControllerAxisBinding { ControllerAxis::LeftX, 0, 0.1F, true }); + bind_action("right", ControllerAxisBinding { ControllerAxis::LeftX, 0, 0.5F, true }); bind_action("left", KeyBinding { Key::Left }); bind_action("left", KeyBinding { Key::A }); bind_action("left", ControllerButtonBinding { ControllerButton::DPadLeft, 0 }); - bind_action("left", ControllerAxisBinding { ControllerAxis::LeftX, 0, -0.1F, true }); + bind_action("left", ControllerAxisBinding { ControllerAxis::LeftX, 0, 0.5F, false }); bind_action("up", KeyBinding { Key::Up }); bind_action("up", KeyBinding { Key::W }); bind_action("up", ControllerButtonBinding { ControllerButton::DPadUp, 0 }); - // bind_action("up", ControllerAxisBinding { ControllerAxis::LeftY, 0, -0.1F, false }); + bind_action("up", ControllerAxisBinding { ControllerAxis::LeftY, 0, 0.5F, false }); bind_action("down", KeyBinding { Key::Down }); bind_action("down", KeyBinding { Key::S }); bind_action("down", ControllerButtonBinding { ControllerButton::DPadDown, 0 }); - // bind_action("down", ControllerAxisBinding { ControllerAxis::LeftY, 0, 0.1F, true }); + bind_action("down", ControllerAxisBinding { ControllerAxis::LeftY, 0, 0.5F, true }); bind_action("interact", KeyBinding { Key::Return }); bind_action("interact", KeyBinding { Key::Space }); diff --git a/src/scenes/intro.h b/src/scenes/intro.h index 59db670..42be842 100644 --- a/src/scenes/intro.h +++ b/src/scenes/intro.h @@ -45,10 +45,10 @@ class IntroScene : public asw::scene::Scene { // Show the appropriate image for this frame if (frame == 0) { - asw::draw::sprite(background_, asw::Vec2(0, 0)); - asw::draw::sprite(intro_, asw::Vec2(0, 0)); + asw::draw::sprite(background_, asw::Vec2f(0, 0)); + asw::draw::sprite(intro_, asw::Vec2f(0, 0)); } else { - asw::draw::sprite(splash_, asw::Vec2(0, 0)); + asw::draw::sprite(splash_, asw::Vec2f(0, 0)); } // Compute alpha: fade in → hold → fade out diff --git a/src/scenes/win.h b/src/scenes/win.h index 6d9018f..df30325 100644 --- a/src/scenes/win.h +++ b/src/scenes/win.h @@ -28,8 +28,8 @@ class WinScene : public asw::scene::Scene { void draw() override { - asw::draw::sprite(winscreen, asw::Vec2(0, 0)); - asw::draw::text(font, std::to_string(score), asw::Vec2(620, 850), palette::black); + asw::draw::sprite(winscreen, asw::Vec2f(0, 0)); + asw::draw::text(font, std::to_string(score), asw::Vec2f(620, 850), palette::black); } private: diff --git a/src/tilemap.cpp b/src/tilemap.cpp index 8289b5f..b5e6a34 100644 --- a/src/tilemap.cpp +++ b/src/tilemap.cpp @@ -5,23 +5,28 @@ using namespace asw::assets; -TileType TileMap::at(const asw::Vec2& pos) const +TileType TileMap::at(const asw::Vec2i& pos) const { + if (pos.x < 0 || pos.x >= WIDTH || pos.y < 0 || pos.y >= HEIGHT) { + asw::log::warn("Warning: Grid position ({}, {}) is out of bounds", pos.x, pos.y); + return TileType::Empty; + } + return tiles[pos.x][pos.y]; } -TileType TileMap::atPixel(const asw::Vec2& pos) const +TileType TileMap::atPixel(const asw::Vec2i& pos) const { - return tiles[pos.x / render_config.tile_size][pos.y / render_config.tile_size]; + return at(asw::Vec2i(pos.x / render_config.tile_size, pos.y / render_config.tile_size)); } -TileType TileMap::getValue(const asw::Vec2& pos) const +void TileMap::setValue(const asw::Vec2i& pos, TileType type) { - return tiles[pos.x][pos.y]; -} + if (pos.x < 0 || pos.x >= WIDTH || pos.y < 0 || pos.y >= HEIGHT) { + asw::log::warn("Warning: Grid position ({}, {}) is out of bounds", pos.x, pos.y); + return; + } -void TileMap::setValue(const asw::Vec2& pos, TileType type) -{ tiles[pos.x][pos.y] = type; } @@ -89,14 +94,14 @@ bool TileMap::load(const std::string& path) return true; } -void TileMap::render(const asw::Vec2& pos) const +void TileMap::render(const asw::Vec2i& pos) const { tile_renderer.renderTile(tiles[pos.x][pos.y], pos.x, pos.y, render_config); } void TileMap::renderBackground() const { - const auto pos = asw::Quad(render_config.offset_x, render_config.offset_y, + const auto pos = asw::Quadf(render_config.offset_x, render_config.offset_y, WIDTH * render_config.tile_size, HEIGHT * render_config.tile_size); asw::draw::rect_fill(pos, background); diff --git a/src/tilemap.h b/src/tilemap.h index da8b945..da87a92 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -32,7 +32,7 @@ class TileRenderer { auto texture = getTileTexture(tile); if (texture) { - const auto position = asw::Quad((x * config.tile_size) + config.offset_x, + const auto position = asw::Quadf((x * config.tile_size) + config.offset_x, (y * config.tile_size) + config.offset_y, config.render_size, config.render_size); asw::draw::stretch_sprite(texture, position); } @@ -79,20 +79,19 @@ class TileMap { static constexpr int HEIGHT = 24; // Grid coordinate access - TileType at(const asw::Vec2& pos) const; + TileType at(const asw::Vec2i& pos) const; // Pixel-to-grid coordinate access - TileType atPixel(const asw::Vec2& pos) const; + TileType atPixel(const asw::Vec2i& pos) const; // Coordinate checking helpers - TileType getValue(const asw::Vec2& pos) const; - void setValue(const asw::Vec2& pos, TileType type); + void setValue(const asw::Vec2i& pos, TileType type); // Map file loading bool load(const std::string& path); // Draw at position - void render(const asw::Vec2& pos) const; + void render(const asw::Vec2i& pos) const; void renderBackground() const; // Set render config