Skip to content

Commit

Permalink
Ft add path planning (#7)
Browse files Browse the repository at this point in the history
* Add path-planning as submodule

* Add modules
- Walk animation and tbs animation
- navigation_manager and use path-planning inside
- Render animation 2d and move enemy with planned path

* Lint
  • Loading branch information
bilalkah authored Aug 26, 2024
1 parent 31770ed commit cfeddd5
Show file tree
Hide file tree
Showing 54 changed files with 605 additions and 163 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third-party/uuid_v4"]
path = third-party/uuid_v4
url = https://github.com/crashoz/uuid_v4.git
[submodule "third-party/path-planning"]
path = third-party/path-planning
url = https://github.com/bilalkah/path-planning.git
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
project(wolfenstein VERSION 1.0 LANGUAGES CXX)
add_definitions("-Wall" "-g")

Expand Down Expand Up @@ -37,6 +37,10 @@ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third-party/uuid_v4/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third-party/path-planning/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

# internal libraries
add_subdirectory(app)
add_subdirectory(src/Animation)
Expand All @@ -48,12 +52,14 @@ add_subdirectory(src/GameObjects)
add_subdirectory(src/Graphics)
add_subdirectory(src/Map)
add_subdirectory(src/Math)
add_subdirectory(src/NavigationManager)
add_subdirectory(src/TextureManager)
add_subdirectory(src/TimeManager)
add_subdirectory(src/Utility)

# external libraries
add_subdirectory(third-party/uuid_v4)
add_subdirectory(third-party/path-planning)

find_package(SDL2 REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

int main() {
using namespace wolfenstein;
GeneralConfig config(1280, 768, 0, 50, 120, 10.0, ToRadians(60.0));
GeneralConfig config(2560, 1440, 0, 50, 120, 10.0, ToRadians(60.0), true);

Game game(config);
game.Run();
Expand Down
3 changes: 2 additions & 1 deletion src/Animation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ link_directories(
add_library(
animation
STATIC
src/animation.cpp
src/time_based_single_animation.cpp
src/walk_animation.cpp
)

target_include_directories(animation PUBLIC
Expand Down
23 changes: 7 additions & 16 deletions src/Animation/include/Animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Bilal Kahraman ([email protected])
* @brief
* @version 0.1
* @date 2024-08-18
* @date 2024-08-19
*
* @copyright Copyright (c) 2024
*
Expand All @@ -12,27 +12,18 @@
#ifndef ANIMATION_INCLUDE_ANIMATION_ANIMATION_H_
#define ANIMATION_INCLUDE_ANIMATION_ANIMATION_H_

#include <vector>

namespace wolfenstein {

class Animation
class IAnimation
{
public:
Animation(const std::vector<int>& tex_ids, const double animation_speed);
~Animation() = default;

void Update(const double& delta_time);
void Reset();
virtual ~IAnimation() = default;

int GetCurrentFrame() const;

private:
std::vector<int> tex_ids;
int current_frame;
double animation_speed;
double counter;
virtual void Update(const double& delta_time) = 0;
virtual void Reset() = 0;
virtual int GetCurrentFrame() const = 0;
};

} // namespace wolfenstein

#endif // ANIMATION_INCLUDE_ANIMATION_ANIMATION_H_
38 changes: 38 additions & 0 deletions src/Animation/include/Animation/animator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file animator.h
* @author Bilal Kahraman ([email protected])
* @brief
* @version 0.1
* @date 2024-08-26
*
* @copyright Copyright (c) 2024
*
*/

#ifndef ANIMATION_INCLUDE_ANIMATION_ANIMATOR_H_
#define ANIMATION_INCLUDE_ANIMATION_ANIMATOR_H_

#include "Animation/animation.h"
#include <memory>
#include <vector>

namespace wolfenstein {

class Animator
{
public:
Animator();
~Animator() = default;

void AddAnimation(std::shared_ptr<IAnimation> animation);
void Update(const double& delta_time);
void Reset();
int GetCurrentFrame() const;

private:
std::vector<std::shared_ptr<IAnimation>> animations;
};

} // namespace wolfenstein

#endif // ANIMATION_INCLUDE_ANIMATION_ANIMATOR_H_
39 changes: 39 additions & 0 deletions src/Animation/include/Animation/time_based_single_animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @file animation.h
* @author Bilal Kahraman ([email protected])
* @brief
* @version 0.1
* @date 2024-08-18
*
* @copyright Copyright (c) 2024
*
*/

#ifndef ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_
#define ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_

#include "Animation/animation.h"
#include <vector>

namespace wolfenstein {

class TBSAnimation : public IAnimation
{
public:
TBSAnimation(const std::vector<int>& tex_ids, const double animation_speed);
~TBSAnimation() = default;

void Update(const double& delta_time) override;
void Reset() override;

int GetCurrentFrame() const override;

private:
std::vector<int> tex_ids;
int current_frame;
double animation_speed;
double counter;
};

} // namespace wolfenstein
#endif // ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_
40 changes: 40 additions & 0 deletions src/Animation/include/Animation/walk_animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @file state_based_animation.h
* @author Bilal Kahraman ([email protected])
* @brief
* @version 0.1
* @date 2024-08-26
*
* @copyright Copyright (c) 2024
*
*/

#ifndef ANIMATION_INCLUDE_ANIMATION_STATE_BASED_ANIMATION_H_
#define ANIMATION_INCLUDE_ANIMATION_STATE_BASED_ANIMATION_H_

#include "Animation/animation.h"
#include <vector>

namespace wolfenstein {

class WalkAnimation : public IAnimation
{
public:
WalkAnimation(const std::vector<int>& tex_ids, const double step_size);
~WalkAnimation() = default;

void Update(const double& delta_time) override;
void Reset() override;

int GetCurrentFrame() const override;

private:
std::vector<int> tex_ids;
int current_frame;
double step_size;
double counter;
};

} // namespace wolfenstein

#endif // ANIMATION_INCLUDE_ANIMATION_STATE_BASED_ANIMATION_H_
Empty file added src/Animation/src/animator.cpp
Empty file.
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include <Animation/animation.h>
#include "Animation/time_based_single_animation.h"

namespace wolfenstein {

Animation::Animation(const std::vector<int>& tex_ids,
const double animation_speed)
TBSAnimation::TBSAnimation(const std::vector<int>& tex_ids,
const double animation_speed)
: tex_ids(tex_ids), current_frame(0), animation_speed(animation_speed) {}

void Animation::Update(const double& delta_time) {
void TBSAnimation::Update(const double& delta_time) {
counter += delta_time;
if (counter > animation_speed) {
current_frame = (current_frame + 1) % tex_ids.size();
counter = 0;
}
}

void Animation::Reset() {
void TBSAnimation::Reset() {
current_frame = 0;
counter = 0;
}

int Animation::GetCurrentFrame() const {
int TBSAnimation::GetCurrentFrame() const {
return tex_ids[current_frame];
}

Expand Down
26 changes: 26 additions & 0 deletions src/Animation/src/walk_animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Animation/walk_animation.h"

namespace wolfenstein {

WalkAnimation::WalkAnimation(const std::vector<int>& tex_ids,
const double step_size)
: tex_ids(tex_ids), current_frame(1), step_size(step_size), counter(0) {}

void WalkAnimation::Update(const double& delta_time) {
counter += delta_time;
if (counter > step_size) {
current_frame = (current_frame + 1) % tex_ids.size();
counter = 0;
}
}

void WalkAnimation::Reset() {
current_frame = 1;
counter = 0;
}

int WalkAnimation::GetCurrentFrame() const {
return tex_ids[current_frame];
}

} // namespace wolfenstein
14 changes: 7 additions & 7 deletions src/Camera/include/Camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#ifndef CAMERA_INCLUDE_CAMERA_H
#define CAMERA_INCLUDE_CAMERA_H

#include <Camera/ray.h>
#include <Camera/raycaster.h>
#include <Characters/character.h>
#include <GameObjects/game_object.h>
#include <GameObjects/static_object.h>
#include <Graphics/scene.h>
#include <Map/map.h>
#include "Camera/ray.h"
#include "Camera/raycaster.h"
#include "Characters/character.h"
#include "GameObjects/game_object.h"
#include "GameObjects/static_object.h"
#include "Graphics/scene.h"
#include "Map/map.h"

#include <memory>
#include <optional>
Expand Down
2 changes: 1 addition & 1 deletion src/Camera/include/Camera/ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef CAMERA_INCLUDE_CAMERA_RAY_H_
#define CAMERA_INCLUDE_CAMERA_RAY_H_

#include <Math/vector.h>
#include "Math/vector.h"

#include <vector>

Expand Down
8 changes: 4 additions & 4 deletions src/Camera/include/Camera/raycaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#ifndef CAMERA_INCLUDE_CAMERA_RAYCASTER_H_
#define CAMERA_INCLUDE_CAMERA_RAYCASTER_H_

#include <Camera/ray.h>
#include <Characters/character.h>
#include <Map/map.h>
#include <Math/vector.h>
#include "Camera/ray.h"
#include "Characters/character.h"
#include "Map/map.h"
#include "Math/vector.h"

#include <memory>

Expand Down
8 changes: 4 additions & 4 deletions src/Camera/src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
*
*/

#include <Camera/camera.h>
#include <Camera/ray.h>
#include <Math/vector.h>
#include <TextureManager/texture_manager.h>
#include "Camera/camera.h"
#include "Camera/ray.h"
#include "Math/vector.h"
#include "TextureManager/texture_manager.h"

#include <cmath>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/Camera/src/ray.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Camera/ray.h>
#include "Camera/ray.h"

#include <cmath>

Expand Down
2 changes: 1 addition & 1 deletion src/Camera/src/raycaster.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Camera/raycaster.h>
#include "Camera/raycaster.h"

#include <cmath>
#include <vector>
Expand Down
11 changes: 6 additions & 5 deletions src/Characters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
link_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)

add_library(
character
STATIC
Expand All @@ -15,11 +10,17 @@ target_include_directories(character PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_directories(character PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(
character
PUBLIC
game_object
vector
collision_manager
animation
)

3 changes: 1 addition & 2 deletions src/Characters/include/Characters/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef CHARACTERS_INCLUDE_CHARACTER_H
#define CHARACTERS_INCLUDE_CHARACTER_H

#include <GameObjects/game_object.h>
#include "GameObjects/game_object.h"

namespace wolfenstein {

Expand Down Expand Up @@ -41,7 +41,6 @@ class ICharacter

virtual void SetPosition(Position2D position) = 0;
virtual Position2D GetPosition() const = 0;

};
} // namespace wolfenstein

Expand Down
Loading

0 comments on commit cfeddd5

Please sign in to comment.