-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ target_link_libraries( | |
collision_manager | ||
animation | ||
SDL2 | ||
shotgun | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
add_library( | ||
shotgun | ||
STATIC | ||
src/shotgun.cpp | ||
) | ||
target_include_directories(shotgun PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
) | ||
target_link_libraries( | ||
shotgun | ||
PUBLIC | ||
animation | ||
time_manager | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @file shotgun.h | ||
* @author Bilal Kahraman ([email protected]) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2024-08-29 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#ifndef STRIKE_INCLUDE_STRIKE_SHOTGUN_H | ||
#define STRIKE_INCLUDE_STRIKE_SHOTGUN_H | ||
|
||
#include "Animation/time_based_single_animation.h" | ||
#include "Strike/weapon.h" | ||
#include <memory> | ||
|
||
namespace wolfenstein { | ||
|
||
class Shotgun : public IWeapon | ||
{ | ||
public: | ||
Shotgun(); | ||
~Shotgun() = default; | ||
|
||
void Attack() override; | ||
int GetTextureId() const; | ||
|
||
private: | ||
void AttackAnimation(); | ||
double attack_speed_; | ||
double attack_damage_; | ||
std::shared_ptr<TBSAnimation> animation_; | ||
|
||
bool cooldown_; | ||
double last_attack_time_; | ||
}; | ||
|
||
} // namespace wolfenstein | ||
|
||
#endif // STRIKE_INCLUDE_STRIKE_SHOTGUN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @file strike.h | ||
* @author Bilal Kahraman ([email protected]) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2024-08-29 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#ifndef STRIKE_INCLUDE_STRIKE_STRIKE_H | ||
#define STRIKE_INCLUDE_STRIKE_STRIKE_H | ||
|
||
namespace wolfenstein { | ||
|
||
class IStrike | ||
{ | ||
public: | ||
virtual ~IStrike() = default; | ||
|
||
virtual void Attack() = 0; | ||
}; | ||
|
||
} // namespace wolfenstein | ||
|
||
#endif // STRIKE_INCLUDE_STRIKE_STRIKE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @file weapon.h | ||
* @author Bilal Kahraman ([email protected]) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2024-08-29 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#ifndef STRIKE_INCLUDE_STRIKE_WEAPON_H | ||
#define STRIKE_INCLUDE_STRIKE_WEAPON_H | ||
|
||
namespace wolfenstein { | ||
|
||
class IWeapon | ||
{ | ||
public: | ||
virtual ~IWeapon() = default; | ||
|
||
virtual void Attack() = 0; | ||
}; | ||
|
||
} // namespace wolfenstein | ||
|
||
#endif // STRIKE_INCLUDE_STRIKE_WEAPON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "Strike/shotgun.h" | ||
#include "TimeManager/time_manager.h" | ||
#include <iostream> | ||
#include <thread> | ||
|
||
namespace wolfenstein { | ||
|
||
Shotgun::Shotgun() : attack_speed_(0.6), attack_damage_(10) { | ||
std::vector<int> tex_ids{90, 91, 92, 93, 94, 95}; | ||
animation_ = | ||
std::make_shared<TBSAnimation>(tex_ids, attack_speed_ / tex_ids.size()); | ||
cooldown_ = false; | ||
} | ||
|
||
int Shotgun::GetTextureId() const { | ||
return animation_->GetCurrentFrame(); | ||
} | ||
|
||
void Shotgun::Attack() { | ||
// If the weapon is not in cooldown, attack and set the cooldown true | ||
if (!cooldown_) { | ||
cooldown_ = true; | ||
last_attack_time_ = TimeManager::GetInstance().GetCurrentTime(); | ||
|
||
// Create a new thread to play the attack animation | ||
// Use attack speed to calculate the time to wait | ||
std::thread attack_thread(&Shotgun::AttackAnimation, this); | ||
attack_thread.detach(); | ||
} | ||
} | ||
// BUG: Segmentation fault if game closes while the thread is running | ||
void Shotgun::AttackAnimation() { | ||
auto attack_time = last_attack_time_; | ||
auto current_time = TimeManager::GetInstance().GetCurrentTime(); | ||
while (current_time - last_attack_time_ < attack_speed_) { | ||
auto time_elapsed = current_time - attack_time; | ||
animation_->Update(time_elapsed); | ||
attack_time = current_time; | ||
current_time = TimeManager::GetInstance().GetCurrentTime(); | ||
} | ||
animation_->Reset(); | ||
cooldown_ = false; | ||
} | ||
|
||
} // namespace wolfenstein |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.