Skip to content

Commit

Permalink
features
Browse files Browse the repository at this point in the history
- Weapon animations are done
- Bot animation skeleton is prepared
- MP5 assets added
- Animator is removed because state is better approach
- Texture manager is improved
  • Loading branch information
bilalkah committed Sep 14, 2024
1 parent 95276c9 commit 9ed5528
Show file tree
Hide file tree
Showing 58 changed files with 946 additions and 296 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
**/*.png filter=lfs diff=lfs merge=lfs -text
**/*.ttf filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ add_subdirectory(src/Map)
add_subdirectory(src/Math)
add_subdirectory(src/NavigationManager)
add_subdirectory(src/Strike)
add_subdirectory(src/State)
add_subdirectory(src/TextureManager)
add_subdirectory(src/TimeManager)
add_subdirectory(src/Utility)
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(800, 600, 0, 50, 120, 15.0, ToRadians(60.0), false);
GeneralConfig config(800, 600, 0, 30, 120, 15.0, ToRadians(60.0), false);

Game game(config);
game.Run();
Expand Down
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/loaded/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/loaded/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/loaded/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/loaded/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/loaded/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/loaded/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/outofammo/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/outofammo/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/outofammo/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/outofammo/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/sprites/weapon/mp5/reload/9.png
Binary file modified project.drawio.png
2 changes: 1 addition & 1 deletion src/Animation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ add_library(
animation
STATIC
src/time_based_single_animation.cpp
src/walk_animation.cpp
)
target_include_directories(animation PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)

38 changes: 0 additions & 38 deletions src/Animation/include/Animation/animator.h

This file was deleted.

41 changes: 0 additions & 41 deletions src/Animation/include/Animation/walk_animation.h

This file was deleted.

Empty file removed src/Animation/src/animator.cpp
Empty file.
26 changes: 0 additions & 26 deletions src/Animation/src/walk_animation.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion src/Characters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target_link_libraries(
collision_manager
animation
SDL2
shotgun
weapon
enemy_state
)

19 changes: 12 additions & 7 deletions src/Characters/include/Characters/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
#ifndef CHARACTERS_INCLUDE_ENEMY_H_
#define CHARACTERS_INCLUDE_ENEMY_H_

#include "Animation/walk_animation.h"
#include "Characters/character.h"
#include "GameObjects/game_object.h"
#include "Math/vector.h"
#include "State/enemy_state.h"
#include <memory>

namespace wolfenstein {

class Enemy : public ICharacter, public IGameObject
class Enemy : public ICharacter,
public IGameObject,
public std::enable_shared_from_this<Enemy>
{
public:
explicit Enemy(CharacterConfig config, double width, double height,
WalkAnimation animation);
explicit Enemy(CharacterConfig config, std::shared_ptr<State<Enemy>> state,
double width, double height);
~Enemy() = default;

void Init();
void Update(double delta_time) override;
void TransitionTo(std::shared_ptr<State<Enemy>> state);

void SetPose(const vector2d& pose) override;
void SetPosition(Position2D position) override;
Expand All @@ -42,16 +46,17 @@ class Enemy : public ICharacter, public IGameObject
void SetNextPose(vector2d pose);

private:
Enemy() = default;
void Move(double delta_time);

Position2D position_;
double rotation_speed_;
double translation_speed_;
std::string id_;
std::shared_ptr<State<Enemy>> state_;
double width;
double height;
std::string id_;
vector2d next_pose;
WalkAnimation animation;
};

} // namespace wolfenstein
Expand Down
12 changes: 6 additions & 6 deletions src/Characters/include/Characters/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "Characters/character.h"
#include "GameObjects/game_object.h"
#include "Strike/shotgun.h"
#include "Strike/weapon.h"
#include <functional>
#include <memory>

Expand All @@ -35,23 +35,23 @@ class Player : public ICharacter, public IGameObject
void SetPosition(Position2D position) override;
Position2D GetPosition() const override;
std::string GetId() const override;
int GetTextureId() const override { return shotgun_->GetTextureId(); }
double GetWidth() const override { return width_; }
double GetHeight() const override { return height_; }
int GetTextureId() const override;
double GetWidth() const override;
double GetHeight() const override;
void SubscribeToPlayerPosition(std::function<void(Position2D)> subscriber);

private:
void Move(double delta_time);
void Rotate(double delta_time);
void Shoot();
void ShootAndReload();

Position2D position_;
double rotation_speed_;
double translation_speed_;
double width_{0.4};
double height_{1.0};
std::string id_;
std::shared_ptr<Shotgun> shotgun_;
std::shared_ptr<Weapon> weapon_;
std::vector<std::function<void(Position2D)>> player_position_subscribers_;
};

Expand Down
24 changes: 15 additions & 9 deletions src/Characters/src/enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@
#include "CollisionManager/collision_manager.h"
#include "Math/vector.h"
#include "Utility/uuid_generator.h"
#include <memory>

namespace wolfenstein {

Enemy::Enemy(CharacterConfig config, double width, double height,
WalkAnimation animation)
Enemy::Enemy(CharacterConfig config, std::shared_ptr<State<Enemy>> state,
double width, double height)
: position_(config.initial_position),
rotation_speed_(config.rotation_speed),
translation_speed_(config.translation_speed),
state_(state),
width(width),
height(height),
animation(animation) {
id_ = UuidGenerator::GetInstance().GenerateUuid().bytes();
id_(UuidGenerator::GetInstance().GenerateUuid().bytes()) {}

void Enemy::Init() {
state_->SetContext(shared_from_this());
}

void Enemy::TransitionTo(std::shared_ptr<State<Enemy>> state) {
state_ = state;
state_->SetContext(shared_from_this());
}

void Enemy::Update(double delta_time) {
state_->Update(delta_time);
if (next_pose != position_.pose) {
Move(delta_time);
animation.Update(delta_time);
}
else {
animation.Reset();
}
}

Expand Down Expand Up @@ -69,7 +75,7 @@ void Enemy::SetNextPose(vector2d pose) {
}

int Enemy::GetTextureId() const {
return animation.GetCurrentFrame();
return state_->GetCurrentFrame();
}

double Enemy::GetWidth() const {
Expand Down
Loading

0 comments on commit 9ed5528

Please sign in to comment.