Skip to content

Commit

Permalink
Ft update codebase (#19)
Browse files Browse the repository at this point in the history
* Update graphics

* Update animation

* Update animation refs

* Get with ref

* I am feel sorry about not to commit on time

* Revert clang-format

* Add new line
  • Loading branch information
bilalkah authored Dec 18, 2024
1 parent 72cdfdb commit acd69c1
Show file tree
Hide file tree
Showing 75 changed files with 25,991 additions and 587 deletions.
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, 30, 120, 15.0, ToRadians(60.0), false);
GeneralConfig config(800, 600, 0, 20, 120, 15.0, ToRadians(60.0), false);

Game game(config);
game.Run();
Expand Down
35 changes: 35 additions & 0 deletions assets/levels/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"player_config": {
"t_speed": 2.0,
"r_speed": 0.4,
"width": 0.4,
"height": 1.0
},
"config_enemy": {
"soldier": {
"t_speed": 0.8,
"r_speed": 0.4,
"width": 0.3,
"height": 0.6
},
"caco_demon": {
"t_speed": 0.8,
"r_speed": 0.4,
"width": 0.4,
"height": 0.8
},
"cyber_demon": {
"t_speed": 0.8,
"r_speed": 0.4,
"width": 0.5,
"height": 1.0
}
},
"config_dynamic": {
"light": {
"animation_speed": 0.3,
"width": 0.2,
"height": 0.9
}
}
}
28 changes: 28 additions & 0 deletions assets/levels/level1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"map": "map1.txt",
"player": { "position": { "x": 3, "y": 1.5, "theta": 1.5} },
"enemies": [
{ "type": "soldier", "position": { "x": 9, "y": 7, "theta": 0 }},
{ "type": "soldier", "position": { "x": 9, "y": 8, "theta": 0 }},
{ "type": "soldier", "position": { "x": 18, "y": 10.5, "theta": 0 }},
{ "type": "soldier", "position": { "x": 23, "y": 10.5, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 13.5, "y": 2.5, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 6, "y": 11.5, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 21, "y": 14, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 12.5, "y": 14.5, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 23, "y": 4, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 20, "y": 4, "theta": 0 }}
],
"dynamicObjects": [
{ "type": "red_light", "position": { "x": 12.1, "y": 8.15 } },
{ "type": "red_light", "position": { "x": 10.9, "y": 8.15 } },
{ "type": "green_light", "position": { "x": 9.9, "y": 10.9 } },
{ "type": "green_light", "position": { "x": 9.9, "y": 13.1 } },
{ "type": "green_light", "position": { "x": 12.1, "y": 13.1 } },
{ "type": "green_light", "position": { "x": 12.1, "y": 10.9 } }
],
"staticObjects": [

],
"next_level": "level2.json"
}
35 changes: 35 additions & 0 deletions assets/levels/level2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"map": "map2.txt",
"player": { "position": { "x": 1.5, "y": 1.5, "theta": 1.5} },
"enemies": [
{ "type": "soldier", "position": { "x": 8.5, "y": 10.5, "theta": 0 }},
{ "type": "soldier", "position": { "x": 9.6, "y": 6.2, "theta": 0 }},
{ "type": "soldier", "position": { "x": 19, "y": 9.3, "theta": 0 }},
{ "type": "soldier", "position": { "x": 3.5, "y": 15.5, "theta": 0 }},
{ "type": "soldier", "position": { "x": 2.5, "y": 23.5, "theta": 0 }},
{ "type": "soldier", "position": { "x": 8.5, "y": 22.5, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 5.9, "y": 22, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 22.5, "y": 5.5, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 13.5, "y": 2.5, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 11.5, "y": 18, "theta": 0 }},
{ "type": "caco_demon", "position": { "x": 18, "y": 6, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 13.5, "y": 22.5, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 16.5, "y": 23.5, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 21.5, "y": 19.5, "theta": 0 }},
{ "type": "cyber_demon", "position": { "x": 15.5, "y": 8, "theta": 0 }}
],
"dynamicObjects": [
{ "type": "red_light", "position": { "x": 6.1, "y": 4.9 } },
{ "type": "red_light", "position": { "x": 1.9, "y": 4.9 } },
{ "type": "red_light", "position": { "x": 1.9, "y": 13.1 } },
{ "type": "red_light", "position": { "x": 6.1, "y": 10.9 } },
{ "type": "green_light", "position": { "x": 14.1, "y": 9.9 } },
{ "type": "green_light", "position": { "x": 14.9, "y": 9.9 } },
{ "type": "green_light", "position": { "x": 14.9, "y": 21.1 } },
{ "type": "green_light", "position": { "x": 14.1, "y": 21.1 } }
],
"staticObjects": [

],
"next_level": ""
}
28 changes: 28 additions & 0 deletions assets/maps/map1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
height 26
width 16
3333333333333333
3000000000000003
3000000000000003
3001111000000003
3000000002222003
3001110022000053
3000000002000053
3000000002222003
3000000000000003
3000000000000003
3333333300044003
3000000000044003
3000333300000003
3000300000000003
3000300000000003
3111111111111003
3000000100000003
3000000100000003
3000000100001013
3000000100001003
3111000101101003
3000000100001003
3000000000001103
3000000000001003
3000000000001003
3333333333333333
26 changes: 26 additions & 0 deletions assets/maps/map2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
height 24
width 30
111111111111111111111111111111
100000000000000001111111111111
100001111111100001100000000011
111001111111100001111110111111
111001111111100001111110111111
111001111111100000000000111111
111000000001111111111000111111
111000000000011111111000111111
111001110001111111100000111111
111000010000011111111100000111
111111111011111110000000110111
111111111011111100011111110111
111111111011100000000000110111
111100000011111111111000110111
111111100000000000000000110111
111011100011111111111000010111
111000000011111000000000000111
111100000011111111111100011111
111100000011111111000000011111
111100000011111111111111011111
111111111011111111000000011111
111111111011111111000111111111
111000000011111111000111111111
111111111111111111111111111111
Binary file modified assets/sounds/npc_attack.wav
Binary file not shown.
Binary file modified assets/sounds/npc_death.wav
Binary file not shown.
Binary file modified assets/sounds/npc_pain.wav
Binary file not shown.
Binary file modified assets/sounds/player_pain.wav
Binary file not shown.
Binary file modified assets/sounds/shotgun.wav
Binary file not shown.
Binary file modified assets/sounds/theme.mp3
Binary file not shown.
4 changes: 2 additions & 2 deletions project.drawio.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: 2 additions & 1 deletion src/Animation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
add_library(
animation
STATIC
src/time_based_single_animation.cpp
src/looped_animation.cpp
src/triggered_single_animation.cpp
)
target_include_directories(animation PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*
*/

#ifndef ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_
#define ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_
#ifndef ANIMATION_INCLUDE_ANIMATION_LOOPED_ANIMATION_H_
#define ANIMATION_INCLUDE_ANIMATION_LOOPED_ANIMATION_H_

#include "Animation/animation.h"
#include <cstdint>
Expand All @@ -19,14 +19,14 @@

namespace wolfenstein {

class TBSAnimation : public IAnimation
class LoopedAnimation : public IAnimation
{
public:
TBSAnimation(const std::vector<uint16_t>& textures,
LoopedAnimation(const std::vector<uint16_t>& textures,
const double animation_speed);
TBSAnimation(const std::string collection_name,
LoopedAnimation(const std::string collection_name,
const double animation_speed);
~TBSAnimation() = default;
~LoopedAnimation() = default;

void Update(const double& delta_time) override;
void Reset() override;
Expand All @@ -44,4 +44,4 @@ class TBSAnimation : public IAnimation
};

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

#ifndef ANIMATION_INCLUDE_ANIMATION_TRIGGERED_SINGLE_ANIMATION_H_
#define ANIMATION_INCLUDE_ANIMATION_TRIGGERED_SINGLE_ANIMATION_H_

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

namespace wolfenstein {

class Texture;

class TriggeredSingleAnimation : public IAnimation
{
public:
TriggeredSingleAnimation(const uint16_t texture_id,
const double animation_speed,
int alpha_start = 128, int alpha_end = 0);
~TriggeredSingleAnimation() = default;

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

int GetCurrentFrame() const override;
bool IsAnimationFinishedOnce() const override;

private:
Texture& texture;
uint16_t texture_id;
double counter;
double animation_speed;
int transparancy;
int alpha_start;
int alpha_end;
int direction;
bool is_animation_finished_once;
};

} // namespace wolfenstein
#endif // ANIMATION_INCLUDE_ANIMATION_TRIGGERED_SINGLE_ANIMATION_H_
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "Animation/time_based_single_animation.h"
#include "Animation/looped_animation.h"
#include "TextureManager/texture_manager.h"
namespace wolfenstein {

TBSAnimation::TBSAnimation(const std::vector<uint16_t>& textures,
const double animation_speed)
LoopedAnimation::LoopedAnimation(const std::vector<uint16_t>& textures,
const double animation_speed)
: textures(textures),
textures_size(textures.size()),
current_frame(0),
animation_speed(animation_speed),
counter(0),
is_animation_finished_once(false) {}

TBSAnimation::TBSAnimation(const std::string collection_name,
const double animation_speed)
LoopedAnimation::LoopedAnimation(const std::string collection_name,
const double animation_speed)
: textures(
TextureManager::GetInstance().GetTextureCollection(collection_name)),
textures_size(textures.size()),
Expand All @@ -21,7 +21,7 @@ TBSAnimation::TBSAnimation(const std::string collection_name,
counter(0),
is_animation_finished_once(false) {}

void TBSAnimation::Update(const double& delta_time) {
void LoopedAnimation::Update(const double& delta_time) {
counter += delta_time;
if (counter >= animation_speed) {
current_frame = (current_frame + 1) % textures_size;
Expand All @@ -32,16 +32,16 @@ void TBSAnimation::Update(const double& delta_time) {
}
}

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

int TBSAnimation::GetCurrentFrame() const {
int LoopedAnimation::GetCurrentFrame() const {
return textures[current_frame];
}

bool TBSAnimation::IsAnimationFinishedOnce() const {
bool LoopedAnimation::IsAnimationFinishedOnce() const {
return is_animation_finished_once;
}

Expand Down
52 changes: 52 additions & 0 deletions src/Animation/src/triggered_single_animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "Animation/triggered_single_animation.h"
#include "TextureManager/texture_manager.h"
#include <cassert>

#define assertm(exp, msg) assert((void(msg), exp))

namespace wolfenstein {

TriggeredSingleAnimation::TriggeredSingleAnimation(const uint16_t texture_id,
const double animation_speed,
int alpha_start,
int alpha_end)
: texture(TextureManager::GetInstance().GetTexture(texture_id)),
texture_id(texture_id),
counter(0),
animation_speed(animation_speed),
transparancy(alpha_start),
alpha_start(alpha_start),
alpha_end(alpha_end),
direction((alpha_end - alpha_start) / abs((alpha_end - alpha_start))),
is_animation_finished_once(false) {}

void TriggeredSingleAnimation::Update(const double& delta_time) {
if (is_animation_finished_once) {
return;
}
counter += delta_time;
transparancy =
static_cast<int>(alpha_start + (counter * direction * animation_speed) *
abs(alpha_start - alpha_end));
SDL_SetTextureAlphaMod(texture.texture, transparancy);

if (!is_animation_finished_once && transparancy == alpha_end) {
is_animation_finished_once = true;
}
} // namespace wolfenstein

void TriggeredSingleAnimation::Reset() {
counter = 0;
transparancy = alpha_start;
is_animation_finished_once = false;
}

int TriggeredSingleAnimation::GetCurrentFrame() const {
return texture_id;
}

bool TriggeredSingleAnimation::IsAnimationFinishedOnce() const {
return is_animation_finished_once;
}

} // namespace wolfenstein
2 changes: 2 additions & 0 deletions src/Camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ target_link_libraries(
ray
vector
map
character
scene
)
Loading

0 comments on commit acd69c1

Please sign in to comment.