diff --git a/CMakeLists.txt b/CMakeLists.txt index 33b4cb4..64c4ef0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,12 @@ +set(CMAKE_CXX_STANDARD 20) # c++ 20 cmake_minimum_required(VERSION 3.22) # Specifies the required CMake version. project(rla_iipp) # Defines the project name. include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Includes the contents of the conanbuildinfo.cmake file. conan_basic_setup() # Prepares the CMakeList.txt for Conan. -set(CMAKE_CXX_STANDARD 20) # c++ 20 - # $source_files is a space-delimited list of filenames. -add_executable(rla_iipp src/main.cpp src/engine/engine.hpp src/engine/game/game.hpp src/engine/rendering/renderer.hpp src/game/visualizer.hpp src/game/visualizer.cpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/engine.cpp src/engine/engine.hpp src/engine/rendering/sdl/sdltexturemanager.cpp src/engine/rendering/sdl/sdltexturemanager.hpp src/engine/resources/resourcemanager.hpp src/engine/rendering/sdl/sdlfontmanager.cpp src/engine/rendering/sdl/sdlfontmanager.hpp src/engine/input/inputprocessor.hpp src/engine/input/sdlinputprocessor.cpp src/engine/input/sdlinputprocessor.hpp src/game/camera.cpp src/game/camera.hpp src/engine/utility/point.hpp src/engine/utility/rectangle.hpp src/engine/utility/grid2d.hpp) # Specifies the executable to build. +add_executable(rla_iipp src/main.cpp src/engine/engine.hpp src/engine/game/game.hpp src/engine/rendering/renderer.hpp src/game/visualizer.hpp src/game/visualizer.cpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/engine.cpp src/engine/engine.hpp src/engine/rendering/sdl/sdltexturemanager.cpp src/engine/rendering/sdl/sdltexturemanager.hpp src/engine/resources/resourcemanager.hpp src/engine/rendering/sdl/sdlfontmanager.cpp src/engine/rendering/sdl/sdlfontmanager.hpp src/engine/input/inputprocessor.hpp src/engine/input/sdlinputprocessor.cpp src/engine/input/sdlinputprocessor.hpp src/engine/utility/camera.cpp src/engine/utility/camera.hpp src/engine/utility/point.hpp src/engine/utility/rectangle.hpp src/engine/utility/grid2d.hpp src/game/dungeonalgorithm.cpp src/game/dungeonalgorithm.hpp) # Specifies the executable to build. target_link_libraries(rla_iipp ${CONAN_LIBS}) # Specifies what libraries to link, using Conan. file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin) file(COPY config DESTINATION ${CMAKE_BINARY_DIR}/bin) \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt index e17ba29..12e440a 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -5,5 +5,6 @@ sdl_image/2.0.5 fmt/8.0.1 tomlplusplus/2.5.0 sol2/3.2.3 +range-v3/0.11.0 [generators] cmake \ No newline at end of file diff --git a/src/game/camera.cpp b/src/engine/utility/camera.cpp similarity index 65% rename from src/game/camera.cpp rename to src/engine/utility/camera.cpp index 0aeb6c3..2a13f1e 100644 --- a/src/game/camera.cpp +++ b/src/engine/utility/camera.cpp @@ -5,6 +5,21 @@ #include "camera.hpp" Rectangle Camera::get_bounds() { + return cached_bounds; +} + +void Camera::move_camera(Point new_center) { + this->center = new_center; + this->cached_bounds = calculate_bounds(); +} + +void Camera::set_bounds(int max_x, int max_y) { + this->max_x = max_x; + this->max_y = max_y; + this->cached_bounds = calculate_bounds(); +} + +Rectangle Camera::calculate_bounds() { int minx = std::clamp(center.x-(tiles_rendered_x/2), 0, std::max(0,max_x - tiles_rendered_x)); int miny = std::clamp(center.y-(tiles_rendered_y/2), 0, std::max(0,max_y - tiles_rendered_y)); int width = std::min(tiles_rendered_x, max_x-minx); @@ -12,11 +27,7 @@ Rectangle Camera::get_bounds() { return Rectangle{minx, miny, width, height}; } -void Camera::move_camera(Point new_center) { - this->center = new_center; -} - -void Camera::set_bounds(int max_x, int max_y) { - this->max_x = max_x; - this->max_y = max_y; +Point Camera::camera_coords_to_screen_coords(Point camera_coord) { + auto bounds = get_bounds(); + return Point{camera_coord.x-bounds.x, camera_coord.y-bounds.y}; } diff --git a/src/game/camera.hpp b/src/engine/utility/camera.hpp similarity index 81% rename from src/game/camera.hpp rename to src/engine/utility/camera.hpp index 6453e9d..024c310 100644 --- a/src/game/camera.hpp +++ b/src/engine/utility/camera.hpp @@ -6,8 +6,8 @@ #define RLA_IIPP_CAMERA_HPP -#include "../engine/utility/point.hpp" -#include "../engine/utility/rectangle.hpp" +#include "point.hpp" +#include "rectangle.hpp" #include class Camera { @@ -18,10 +18,13 @@ private: int tiles_rendered_y=0; int max_x=0; int max_y=0; + Rectangle cached_bounds=Rectangle(); + Rectangle calculate_bounds(); public: Rectangle get_bounds(); void move_camera(Point new_center); void set_bounds(int max_x, int max_y); + Point camera_coords_to_screen_coords(Point camera_coord); Camera()=default; Camera(const Point ¢er, int tilesRenderedX, int tilesRenderedY, int maxX, int maxY) : center(center), @@ -30,7 +33,10 @@ public: tiles_rendered_y( tilesRenderedY), max_x(maxX), - max_y(maxY) {} + max_y(maxY) + { + cached_bounds = calculate_bounds(); + } }; diff --git a/src/game/dungeonalgorithm.cpp b/src/game/dungeonalgorithm.cpp new file mode 100644 index 0000000..6bf1713 --- /dev/null +++ b/src/game/dungeonalgorithm.cpp @@ -0,0 +1,5 @@ +// +// Created by m on 12/12/21. +// + +#include "dungeonalgorithm.hpp" diff --git a/src/game/dungeonalgorithm.hpp b/src/game/dungeonalgorithm.hpp new file mode 100644 index 0000000..68e4578 --- /dev/null +++ b/src/game/dungeonalgorithm.hpp @@ -0,0 +1,14 @@ +// +// Created by m on 12/12/21. +// + +#ifndef RLA_IIPP_DUNGEONALGORITHM_HPP +#define RLA_IIPP_DUNGEONALGORITHM_HPP + + +class DungeonAlgorithm { + +}; + + +#endif //RLA_IIPP_DUNGEONALGORITHM_HPP diff --git a/src/game/visualizer.cpp b/src/game/visualizer.cpp index 5492466..bba4844 100644 --- a/src/game/visualizer.cpp +++ b/src/game/visualizer.cpp @@ -30,16 +30,19 @@ void Visualizer::render(Renderer *renderer) { auto wall = Sprite{&tiles, 497}; auto character = Sprite{&characters, this->sprite_index}; auto bounds = this->camera.get_bounds(); - for(int ty=bounds.y;tytile_map.get(tx, ty) == FLOOR_CHAR) { - renderer->draw_sprite(grass, (tx-bounds.x)*TILE_WIDTH, (ty-bounds.y)*TILE_HEIGHT); + renderer->draw_sprite(grass, wx*TILE_WIDTH, wy*TILE_HEIGHT); } else { - renderer->draw_sprite(wall, (tx-bounds.x)*TILE_WIDTH, (ty-bounds.y)*TILE_HEIGHT); + renderer->draw_sprite(wall, wx*TILE_WIDTH, wy*TILE_HEIGHT); } if(tx == x && ty == y) { - renderer->draw_sprite(character, (tx-bounds.x)*TILE_WIDTH, (ty-bounds.y)*TILE_HEIGHT); + renderer->draw_sprite(character, wx*TILE_WIDTH, wy*TILE_HEIGHT); } } } @@ -59,12 +62,7 @@ void Visualizer::initialize_map(int width, int height) { this->tile_map = Grid2D(width, height); for(int ty=0;tytile_map.get_height();ty++) { for (int tx = 0; tx < tile_map.get_width(); tx++) { - if (tx == 0 || ty == 0 || ty == this->tile_map.get_height() - 1 || tx == this->tile_map.get_width() - 1) { - this->tile_map.insert(tx, ty, WALL_CHAR); - } - else { - this->tile_map.insert(tx, ty, FLOOR_CHAR); - } + this->tile_map.insert(tx, ty, FLOOR_CHAR); } } } diff --git a/src/game/visualizer.hpp b/src/game/visualizer.hpp index 15433f5..306d28c 100644 --- a/src/game/visualizer.hpp +++ b/src/game/visualizer.hpp @@ -3,13 +3,15 @@ // #include "../engine/game/game.hpp" #include "../engine/rendering/renderer.hpp" -#include "camera.hpp" +#include "../engine/utility/camera.hpp" #include "../engine/utility/grid2d.hpp" #include +#include +#include #ifndef RLA_IIPP_VISUALIZER_HPP #define RLA_IIPP_VISUALIZER_HPP -#define MAP_SIZE_W 10 -#define MAP_SIZE_H 10 +#define MAP_SIZE_W 20 +#define MAP_SIZE_H 20 #define TILE_WIDTH 48 #define TILE_HEIGHT 48 #define WALL_CHAR '#'