├── .gitattributes
├── Engine
├── Engine.vcxproj
├── Engine.vcxproj.filters
├── Engine.vcxproj.user
└── src
│ ├── Animations
│ ├── Animator.cpp
│ └── Animator.hpp
│ ├── Asset Manager.hpp
│ ├── Collision
│ ├── Collider.hpp
│ ├── Collision.cpp
│ └── Collision.hpp
│ ├── Fixed Clock.hpp
│ ├── Key Check.cpp
│ ├── Key Check.hpp
│ ├── Random.cpp
│ ├── Random.hpp
│ ├── Shader Library.cpp
│ ├── Shader Library.hpp
│ ├── Text.cpp
│ ├── Text.hpp
│ ├── Timer.cpp
│ └── Timer.hpp
├── LICENSE
├── README.md
├── The Platformer.sln
└── The Platformer
├── Application.cpp
├── Application.hpp
├── Effects
├── Camera
│ ├── Camera.cpp
│ └── Camera.hpp
├── Light
│ ├── Light.cpp
│ └── Light.hpp
├── Music controller
│ ├── Music Controller.cpp
│ └── Music Controller.hpp
├── Particle Emitter
│ ├── Particle Emitter.cpp
│ └── Particle Emitter.hpp
└── Transition
│ ├── Transition.cpp
│ └── Transition.hpp
├── Entities
├── Entity.cpp
├── Entity.hpp
├── Fireball.cpp
├── Fireball.hpp
├── Ghost.cpp
├── Ghost.hpp
├── Heart.cpp
├── Heart.hpp
├── Player.cpp
└── Player.hpp
├── Objects
├── Wall.cpp
└── Wall.hpp
├── Precompiled Headers
├── stdafx.cpp
└── stdafx.h
├── Public Variables
├── Extern.cpp
└── Extern.hpp
├── States
├── Machine
│ ├── State Machine.cpp
│ └── State Machine.hpp
├── Save.cpp
├── Save.hpp
└── State
│ ├── Game
│ ├── Game.cpp
│ └── Game.hpp
│ ├── Menu
│ ├── Menu.cpp
│ └── Menu.hpp
│ ├── Pause
│ ├── Pause.cpp
│ └── Pause.hpp
│ └── Settings
│ ├── Settings.cpp
│ └── Settings.hpp
├── The Platformer.rc
├── The Platformer.vcxproj
├── The Platformer.vcxproj.filters
├── The Platformer.vcxproj.user
├── UI
├── Button.cpp
├── Button.hpp
├── Color Picker.cpp
├── Color Picker.hpp
├── Color Wheel.cpp
├── Color Wheel.hpp
├── Countdown.cpp
├── Countdown.hpp
├── Health Bar.cpp
├── Health Bar.hpp
├── Seeker Bar.cpp
├── Seeker Bar.hpp
└── UI.hpp
├── main.cpp
├── openal32.dll
├── res
├── fonts
│ └── upheavtt.ttf
├── music
│ ├── main.ogg
│ ├── menu.ogg
│ └── pause.ogg
├── save
├── shaders
│ ├── blurFragment.shader
│ ├── blurVertex.shader
│ ├── fogFragment.shader
│ ├── fogVertex.shader
│ ├── lightFragment.shader
│ ├── lightVertex.shader
│ ├── transitionFragment.shader
│ └── transitionVertex.shader
├── sounds
│ ├── 1.wav
│ ├── 2.wav
│ ├── 3.wav
│ ├── blowUp.wav
│ ├── button.wav
│ ├── ghost.wav
│ ├── go.wav
│ ├── pickUp.wav
│ ├── playerCrouch.wav
│ └── playerJump.wav
└── textures
│ ├── Bez nazwy-1.psd
│ ├── Bez nazwy-2.psd
│ ├── background.png
│ ├── explo.png
│ ├── fireball.png
│ ├── ghost.png
│ ├── health.png
│ ├── heart.png
│ ├── icon.ico
│ ├── icon.png
│ ├── map — kopia.png
│ ├── map.png
│ ├── menu.png
│ ├── player.png
│ ├── proj.psd
│ └── timer.png
└── resource.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/Engine/Engine.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | 16.0
44 | Win32Proj
45 | {bed87c3e-8d9d-43c0-8223-d214d79ccd8c}
46 | Engine
47 | 10.0
48 |
49 |
50 |
51 | Application
52 | true
53 | v143
54 | Unicode
55 |
56 |
57 | Application
58 | false
59 | v143
60 | true
61 | Unicode
62 |
63 |
64 | StaticLibrary
65 | true
66 | v143
67 | Unicode
68 |
69 |
70 | StaticLibrary
71 | false
72 | v143
73 | true
74 | Unicode
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | true
96 |
97 |
98 | false
99 |
100 |
101 | true
102 |
103 |
104 | false
105 |
106 |
107 |
108 | Level3
109 | true
110 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
111 | true
112 |
113 |
114 | Console
115 | true
116 |
117 |
118 |
119 |
120 | Level3
121 | true
122 | true
123 | true
124 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
125 | true
126 |
127 |
128 | Console
129 | true
130 | true
131 | true
132 |
133 |
134 |
135 |
136 | Level3
137 | true
138 | SFML_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
139 | true
140 | $(ProjectDir)\Precompiled Headers;$(SolutionDir)\..\VSSFML-STATIC\include
141 | MultiThreadedDebug
142 | NotUsing
143 | stdcpp17
144 |
145 |
146 | Console
147 | true
148 | $(SolutionDir)\..\VSSFML-STATIC\extlibs\libs-msvc\x64;$(SolutionDir)\..\VSSFML-STATIC\lib\Debug;%(AdditionalLibraryDirectories)
149 | opengl32.lib;openal32.lib;freetype.lib;winmm.lib;gdi32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;sfml-audio-s-d.lib;sfml-network-s-d.lib;%(AdditionalDependencies)
150 |
151 |
152 |
153 |
154 | Level3
155 | true
156 | true
157 | true
158 | SFML_STATIC;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
159 | true
160 | $(ProjectDir)\Precompiled Headers;$(SolutionDir)\..\VSSFML-STATIC\include
161 | MultiThreaded
162 | NotUsing
163 | stdcpp17
164 |
165 |
166 | Console
167 | true
168 | true
169 | true
170 | $(SolutionDir)\..\VSSFML-STATIC\extlibs\libs-msvc\x64;$(SolutionDir)\..\VSSFML-STATIC\lib\Release
171 | opengl32.lib;openal32.lib;freetype.lib;winmm.lib;gdi32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib;sfml-audio-s.lib;sfml-network-s.lib;%(AdditionalDependencies)
172 |
173 |
174 |
175 |
176 |
177 |
--------------------------------------------------------------------------------
/Engine/Engine.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 | Header Files
41 |
42 |
43 | Header Files
44 |
45 |
46 | Header Files
47 |
48 |
49 |
50 |
51 | Source Files
52 |
53 |
54 | Source Files
55 |
56 |
57 | Source Files
58 |
59 |
60 | Source Files
61 |
62 |
63 | Source Files
64 |
65 |
66 | Source Files
67 |
68 |
69 | Source Files
70 |
71 |
72 |
--------------------------------------------------------------------------------
/Engine/Engine.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/Engine/src/Animations/Animator.cpp:
--------------------------------------------------------------------------------
1 | #include "Animator.hpp"
2 |
3 | Animator::Animator(unsigned framesX, unsigned framesY, float time, sf::Vector2i frameSize, sf::Sprite& sprite, unsigned YStart) {
4 | unsigned frameCount = framesX * (framesY > 0 ? framesY : 1);
5 |
6 | m_updateTime = time;
7 |
8 | m_sprite = &sprite;
9 | m_frames = new sf::IntRect[frameCount];
10 |
11 | frameCount = frameCount;
12 |
13 | CutFrames(framesX, framesY, YStart, frameSize);
14 | }
15 |
16 | void Animator::Create(unsigned framesX, unsigned framesY, float time, sf::Vector2i frameSize, sf::Sprite& sprite, unsigned YStart) {
17 | if (m_frameCount > 0)
18 | return;
19 |
20 | unsigned frameCount = framesX * (framesY > 0 ? framesY : 1);
21 |
22 | m_updateTime = time;
23 |
24 | m_sprite = &sprite;
25 | m_frames = new sf::IntRect[frameCount];
26 |
27 | m_frameCount = frameCount;
28 |
29 | CutFrames(framesX, framesY, YStart, frameSize);
30 | }
31 |
32 | void Animator::Update(const float deltaTime) {
33 | m_elapsedTime += deltaTime;
34 | while (m_elapsedTime >= m_updateTime) {
35 | m_elapsedTime -= m_updateTime;
36 | UpdateAnimation();
37 | }
38 | }
39 |
40 | unsigned Animator::GetCurrentFrame() const {
41 | return m_currentFrame;
42 | }
43 |
44 | unsigned Animator::GetFrameCount() const {
45 | return m_frameCount;
46 | }
47 |
48 | void Animator::SetFrame(const unsigned& frame) {
49 | m_currentFrame = frame;
50 | m_sprite->setTextureRect(m_frames[m_currentFrame]);
51 | }
52 |
53 | void Animator::SetUpdateTime(const float& time) {
54 | m_updateTime = time;
55 | }
56 |
57 | Animator::~Animator() {
58 | delete[] m_frames;
59 | }
60 |
61 | void Animator::UpdateAnimation() {
62 | if (++m_currentFrame > m_frameCount - 1)
63 | m_currentFrame = 0;
64 | m_sprite->setTextureRect(m_frames[m_currentFrame]);
65 | }
66 |
67 | void Animator::CutFrames(const unsigned& framesX, const unsigned& framesY, const unsigned& YStart, const sf::Vector2i& frameSize) {
68 | if (framesY > 0) {
69 | unsigned iterator = 0;
70 | for (unsigned y = YStart; y < YStart + framesY; y++) {
71 | for (unsigned x = 0; x < framesX; x++) {
72 | m_frames[iterator] = sf::IntRect(x * frameSize.x, y * frameSize.y, frameSize.x, frameSize.y);
73 | iterator++;
74 | }
75 | }
76 | }
77 | else {
78 | for (unsigned i = 0; i < framesX; i++)
79 | m_frames[i] = sf::IntRect(i * frameSize.x, YStart * frameSize.y, frameSize.x, frameSize.y);
80 | }
81 | }
--------------------------------------------------------------------------------
/Engine/src/Animations/Animator.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | //TODO: rewrite this shit with delegats to use after animation finished B)
5 |
6 | class Animator {
7 | public:
8 | Animator() = default;
9 |
10 | Animator(unsigned framesX, unsigned framesY, float time, sf::Vector2i frameSize, sf::Sprite& sprite, unsigned YStart = 0);
11 |
12 | void Create(unsigned framesX, unsigned framesY, float time, sf::Vector2i frameSize, sf::Sprite& sprite, unsigned YStart = 0);
13 | void Update(const float deltaTime);
14 |
15 | // Accessors
16 | unsigned GetCurrentFrame() const;
17 | unsigned GetFrameCount() const;
18 | void SetFrame(const unsigned& frame);
19 | void SetUpdateTime(const float& time);
20 |
21 | ~Animator();
22 | private:
23 | unsigned m_currentFrame = 0;
24 | unsigned m_frameCount = 0;
25 |
26 | sf::IntRect* m_frames = nullptr;
27 | sf::Sprite* m_sprite = nullptr;
28 |
29 | float m_elapsedTime = 0.f;
30 | float m_updateTime = 0.f;
31 |
32 | void UpdateAnimation();
33 | void CutFrames(const unsigned& framesX, const unsigned& framesY, const unsigned& YStart, const sf::Vector2i& frameSize);
34 | };
35 |
--------------------------------------------------------------------------------
/Engine/src/Asset Manager.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 | template
6 | class AssetManager {
7 | public:
8 | void Load(const std::string& name, const std::string& path) { m_assets[name].loadFromFile(path); }
9 | T& Get(const std::string& name) { return m_assets[name]; }
10 | private:
11 | std::unordered_map m_assets;
12 | };
--------------------------------------------------------------------------------
/Engine/src/Collision/Collider.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | struct Collider
5 | {
6 | Collider
7 | (
8 | const sf::Vector2f& s = sf::Vector2f(),
9 | const sf::Vector2f& p = sf::Vector2f()
10 | )
11 | : size(s), position(p) { }
12 |
13 | sf::Vector2f size;
14 | sf::Vector2f position;
15 | };
--------------------------------------------------------------------------------
/Engine/src/Collision/Collision.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "Collision.hpp"
3 |
4 | Collision::Collision(Collider& body)
5 | : body(body)
6 | {
7 |
8 | }
9 |
10 | Collision::~Collision() {
11 |
12 | }
13 |
14 | bool Collision::CheckCollision(const Collision& other, sf::Vector2f& MTV) const {
15 | const sf::Vector2f otherPosition = other.body.position;
16 | const sf::Vector2f otherSize = other.body.size / 2.0f;
17 |
18 | const sf::Vector2f thisPosition = this->body.position;
19 | const sf::Vector2f thisSize = this->body.size / 2.0f;
20 |
21 | const sf::Vector2f delta = otherPosition - thisPosition;
22 | const sf::Vector2f intersect = abs(delta) - (otherSize + thisSize);
23 |
24 | if (intersect.x < 0.0f && intersect.y < 0.0f) {
25 | if (intersect.x > intersect.y)
26 | MTV.x = (delta.x > 0.0f ? intersect.x : -intersect.x);
27 | else
28 | MTV.y = (delta.y > 0.0f ? intersect.y : -intersect.y);
29 | return true;
30 | }
31 |
32 | return false;
33 | }
34 |
35 | const sf::Vector2f Collision::abs(sf::Vector2f v) {
36 | v.x = (v.x < 0.0f ? -v.x : v.x);
37 | v.y = (v.y < 0.0f ? -v.y : v.y);
38 |
39 | return v;
40 | }
41 |
42 | const Collider Collision::GetBody() {
43 | return body;
44 | }
--------------------------------------------------------------------------------
/Engine/src/Collision/Collision.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Collider.hpp"
3 |
4 | class Collision {
5 | public:
6 | Collision(Collider& body);
7 | ~Collision();
8 |
9 | bool CheckCollision(const Collision& other, sf::Vector2f& MTV) const;
10 |
11 | const Collider GetBody();
12 | private:
13 | Collider& body;
14 |
15 | const static sf::Vector2f abs(sf::Vector2f v);
16 | };
--------------------------------------------------------------------------------
/Engine/src/Fixed Clock.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | class FixedClock {
5 | public:
6 | sf::Time getElapsedTime()
7 | {
8 | if (this->clock_flag)
9 | {
10 | this->clock.restart();
11 | this->clock_flag = false;
12 | }
13 | return this->clock.getElapsedTime();
14 | }
15 |
16 | void restart()
17 | {
18 | this->clock.restart();
19 | this->clock_flag = true;
20 | }
21 | private:
22 | sf::Clock clock;
23 | bool clock_flag = true;
24 | };
--------------------------------------------------------------------------------
/Engine/src/Key Check.cpp:
--------------------------------------------------------------------------------
1 | #include "Key Check.hpp"
2 |
3 | //KeyCheck& KeyCheck::Get() {
4 | // return s_instance;
5 | //}
6 |
7 | void KeyCheck::Init() {
8 | for (int i = 0; i < 26; i++)
9 | s_Keys[i + 65] = false;
10 |
11 | s_Keys[' '] = false;
12 |
13 | s_Buttons['L'] = false;
14 | s_Buttons['R'] = false;
15 | s_Buttons['M'] = false;
16 | }
17 |
18 | void KeyCheck::Update() {
19 | // if you are asking yourself why i did't do just m_Keys[i + 65] = sf::Keyboard::isKeyPressed
20 | // it's because everything was getting fucked up
21 |
22 | for (int i = 0; i < 26; i++)
23 | if (!sf::Keyboard::isKeyPressed((sf::Keyboard::Key)i))
24 | s_Keys[i + 65] = false;
25 |
26 | if (!sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
27 | s_Keys[' '] = false;
28 |
29 | if (!sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
30 | s_Keys['/'] = false; // <- escape key B))
31 |
32 |
33 | if (!sf::Mouse::isButtonPressed(sf::Mouse::Left))
34 | s_Buttons['L'] = false;
35 | if (!sf::Mouse::isButtonPressed(sf::Mouse::Right))
36 | s_Buttons['R'] = false;
37 | if (!sf::Mouse::isButtonPressed(sf::Mouse::Middle))
38 | s_Buttons['M'] = false;
39 | }
40 |
41 | const bool KeyCheck::Button(char button) {
42 | bool pressed = s_Buttons[button];
43 |
44 | if (!pressed)
45 | s_Buttons[button] = true;
46 |
47 | return !pressed;
48 | }
49 |
50 | const bool KeyCheck::Key(char key) {
51 | bool pressed = s_Keys[key];
52 |
53 | if (!pressed)
54 | s_Keys[key] = true;
55 |
56 | return !pressed;
57 | }
58 |
59 | std::unordered_map KeyCheck::s_Keys = {};
60 | std::unordered_map KeyCheck::s_Buttons = {};
61 |
62 | //KeyCheck KeyCheck::s_instance;
--------------------------------------------------------------------------------
/Engine/src/Key Check.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 | #include
6 |
7 | class KeyCheck {
8 | public:
9 | //KeyCheck(const KeyCheck&) = delete;
10 |
11 | //static KeyCheck& Get();
12 |
13 | static void Init();
14 | static void Update();
15 |
16 | // this functions below return true if buttons IS NOT PRESSED otherwies false
17 | const static bool Key(char key);
18 | const static bool Button(char button);
19 | private:
20 | KeyCheck() {}
21 | ~KeyCheck() {}
22 |
23 | static std::unordered_map s_Keys;
24 | static std::unordered_map s_Buttons;
25 |
26 | //static KeyCheck s_instance;
27 | };
28 |
--------------------------------------------------------------------------------
/Engine/src/Random.cpp:
--------------------------------------------------------------------------------
1 | #include "Random.hpp"
2 |
3 | int Random::RandInt(int min, int max) {
4 | return std::uniform_int_distribution(min, max)(rgen);
5 | }
6 |
7 | float Random::RandFloat(float min, float max) {
8 | return std::uniform_real_distribution(min, max)(rgen);
9 | }
10 |
11 | std::random_device Random::rgen;
--------------------------------------------------------------------------------
/Engine/src/Random.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | class Random {
5 | public:
6 | static int RandInt(int min, int max);
7 | static float RandFloat(float min, float max);
8 |
9 | private:
10 | static std::random_device rgen;
11 | };
--------------------------------------------------------------------------------
/Engine/src/Shader Library.cpp:
--------------------------------------------------------------------------------
1 | #include "Shader Library.hpp"
2 |
3 | ShaderLibrary& ShaderLibrary::Get() {
4 | return s_instance;
5 | }
6 |
7 | void ShaderLibrary::Clear() {
8 | for (const auto& s : m_Shaders)
9 | delete s.second;
10 | }
11 |
12 | void ShaderLibrary::LoadShader(const std::string& name, const std::string& fragment, const std::string& vertex) {
13 | sf::Shader* shader = new sf::Shader();
14 | shader->loadFromFile(vertex, fragment);
15 |
16 | m_Shaders[name] = shader;
17 | }
18 |
19 | sf::Shader& ShaderLibrary::GetShader(const std::string& name) {
20 | return *m_Shaders[name];
21 | }
22 |
23 | ShaderLibrary ShaderLibrary::s_instance;
--------------------------------------------------------------------------------
/Engine/src/Shader Library.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 | class ShaderLibrary {
6 | public:
7 | ShaderLibrary(const ShaderLibrary&) = delete;
8 |
9 | static ShaderLibrary& Get();
10 |
11 | void Clear();
12 |
13 | void LoadShader(const std::string& name, const std::string& fragment, const std::string& vertex);
14 |
15 | sf::Shader& GetShader(const std::string& name);
16 |
17 | private:
18 | ShaderLibrary() {}
19 | ~ShaderLibrary() {}
20 |
21 | std::unordered_map m_Shaders;
22 |
23 | static ShaderLibrary s_instance;
24 | };
--------------------------------------------------------------------------------
/Engine/src/Text.cpp:
--------------------------------------------------------------------------------
1 | #include "Text.hpp"
2 |
3 | Text::Text()
4 | {
5 |
6 | }
7 |
8 | Text::~Text()
9 | {
10 |
11 | }
12 |
13 | const void Text::setFont(const sf::Font& font) {
14 | m_text::setFont(font);
15 | m_text::setOrigin(sf::Vector2f(unsigned(m_text::getGlobalBounds().width) / 2, unsigned(m_text::getGlobalBounds().height + m_text::getCharacterSize()) / 2));
16 | }
17 |
18 | const void Text::setFont(const sf::Font& font, unsigned size) {
19 | m_text::setFont(font);
20 | m_text::setCharacterSize(size);
21 |
22 | // i know it's hard coded
23 | const_cast(font.getTexture(size)).setSmooth(false);
24 |
25 | m_text::setOrigin(sf::Vector2f(unsigned(m_text::getGlobalBounds().width) / 2, unsigned(m_text::getGlobalBounds().height + m_text::getCharacterSize()) / 2));
26 | }
27 |
28 | const void Text::setCharacterSize(unsigned size) {
29 | m_text::setCharacterSize(size);
30 | m_text::setOrigin(sf::Vector2f(unsigned(m_text::getGlobalBounds().width) / 2, unsigned(m_text::getGlobalBounds().height + size) / 2));
31 | }
32 |
33 | const void Text::reposition() {
34 | sf::Vector2f pos = m_text::getPosition();
35 | m_text::setOrigin(sf::Vector2f(unsigned(m_text::getGlobalBounds().width) / 2, unsigned(m_text::getGlobalBounds().height + m_text::getCharacterSize()) / 2));
36 |
37 | m_text::setPosition(pos);
38 | }
39 |
40 | const void Text::setSmooth(bool x) {
41 | sf::Font* font = const_cast(m_text::getFont());
42 |
43 | if (!font)
44 | return;
45 |
46 | const_cast(font->getTexture(m_text::getCharacterSize())).setSmooth(x);
47 | }
48 |
49 | const sf::Vector2f Text::getSize() {
50 | return sf::Vector2f(m_text::getGlobalBounds().width, m_text::getGlobalBounds().height);
51 | }
52 |
--------------------------------------------------------------------------------
/Engine/src/Text.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "SFML/Graphics/Drawable.hpp"
3 | #include "SFML/Graphics/Text.hpp"
4 |
5 | #include
6 |
7 | class Text : public sf::Text {
8 | public:
9 | Text();
10 | ~Text();
11 |
12 | const void setFont(const sf::Font& font);
13 | const void setFont(const sf::Font& font, unsigned size);
14 | const void setCharacterSize(unsigned size);
15 |
16 | const void reposition();
17 |
18 | const void setSmooth(bool x);
19 |
20 | const sf::Vector2f getSize();
21 |
22 | public:
23 | using sf::Text::getPosition;
24 | using sf::Text::setPosition;
25 | using sf::Text::move;
26 |
27 | using sf::Text::setLetterSpacing;
28 |
29 | using sf::Text::setOutlineThickness;
30 | using sf::Text::setOutlineColor;
31 |
32 | using sf::Text::setFillColor;
33 |
34 | using sf::Text::setString;
35 |
36 | private:
37 | typedef sf::Text m_text;
38 | };
--------------------------------------------------------------------------------
/Engine/src/Timer.cpp:
--------------------------------------------------------------------------------
1 | #include "Timer.hpp"
2 |
3 | void Timer::Update(const float& dt) {
4 | m_elapsedTime += dt;
5 | while (m_elapsedTime > m_updateTime) {
6 | m_fun();
7 | m_elapsedTime -= m_updateTime;
8 | }
9 | }
10 |
11 | void Timer::SetFunction(float time, std::function fun) {
12 | m_updateTime = time;
13 | m_fun = fun;
14 | }
15 |
16 | void Timer::SetUpdateTime(float time) {
17 | m_updateTime = time;
18 | }
19 |
20 | float Timer::GetUpdateTime() const {
21 | return m_updateTime;
22 | }
23 |
--------------------------------------------------------------------------------
/Engine/src/Timer.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 | class Timer {
6 | public:
7 | void Update(const float& dt);
8 |
9 | void SetFunction(float time, std::function fun);
10 | void SetUpdateTime(float time);
11 |
12 | float GetUpdateTime() const;
13 | private:
14 | float m_elapsedTime = 0.0f;
15 | float m_updateTime = 9999999.0f;
16 |
17 | std::function m_fun;
18 | };
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 2-Clause License
2 |
3 | Copyright (c) 2021, xSnapi
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DEATHJUMP
2 | Simple game created in c++ using SFML
3 |
--------------------------------------------------------------------------------
/The Platformer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31717.71
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "The Platformer", "The Platformer\The Platformer.vcxproj", "{2D062FC7-4469-4F89-87AF-E22CD693A961}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Engine", "Engine\Engine.vcxproj", "{BED87C3E-8D9D-43C0-8223-D214D79CCD8C}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Debug|x64.ActiveCfg = Debug|x64
19 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Debug|x64.Build.0 = Debug|x64
20 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Debug|x86.ActiveCfg = Debug|Win32
21 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Debug|x86.Build.0 = Debug|Win32
22 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Release|x64.ActiveCfg = Release|x64
23 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Release|x64.Build.0 = Release|x64
24 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Release|x86.ActiveCfg = Release|Win32
25 | {2D062FC7-4469-4F89-87AF-E22CD693A961}.Release|x86.Build.0 = Release|Win32
26 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Debug|x64.ActiveCfg = Debug|x64
27 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Debug|x64.Build.0 = Debug|x64
28 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Debug|x86.ActiveCfg = Debug|Win32
29 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Debug|x86.Build.0 = Debug|Win32
30 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Release|x64.ActiveCfg = Release|x64
31 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Release|x64.Build.0 = Release|x64
32 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Release|x86.ActiveCfg = Release|Win32
33 | {BED87C3E-8D9D-43C0-8223-D214D79CCD8C}.Release|x86.Build.0 = Release|Win32
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | GlobalSection(ExtensibilityGlobals) = postSolution
39 | SolutionGuid = {FB17980E-A6AA-4CE9-A2CA-634926E4475C}
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/The Platformer/Application.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Application.hpp"
3 |
4 | Application::Application
5 | (
6 | const float& dt,
7 | const float& fdt
8 | )
9 | : m_dt(dt), m_fdt(fdt)
10 | {
11 | InitWindow();
12 | LoadShaders();
13 | LoadMusicsAndSounds();
14 |
15 | SaveFile::Load("res/save");
16 |
17 | InitStates();
18 |
19 | Transition::Get().Init(); // transition has to be initialized after loading shaders
20 | KeyCheck::Init();
21 | }
22 |
23 |
24 | Application::~Application() {
25 | delete m_machine;
26 |
27 | // could be in destructor
28 | ShaderLibrary::Get().Clear();
29 |
30 | SaveFile::Save("res/save");
31 | }
32 |
33 | void Application::Update() {
34 | HandleEvents();
35 |
36 | Camera::Get().Update(m_dt);
37 | MusicController::Get().Update();
38 |
39 | m_machine->Update();
40 |
41 | Transition::Get().Update(m_dt);
42 | KeyCheck::Update();
43 | }
44 |
45 | void Application::FixedUpdate() {
46 | m_machine->FixedUpdate();
47 |
48 | //LOG(1 / m_dt, '\n');
49 |
50 | //LOG(sf::Mouse::getPosition(m_window).x, ", ", sf::Mouse::getPosition(m_window).y, '\n');
51 | }
52 |
53 | void Application::Render() {
54 | m_window.setView(Camera::Get().GetView());
55 |
56 | m_window.clear();
57 | m_machine->Render();
58 | m_window.display();
59 | }
60 |
61 | void Application::MoveWindow() {
62 | const sf::Vector2f mousePos = m_window.mapPixelToCoords(sf::Mouse::getPosition(m_window));
63 | const int offset = 30;
64 |
65 | if (m_event.type == sf::Event::MouseButtonPressed && m_event.mouseButton.button == sf::Mouse::Left) {
66 | if (mousePos.x > 0 && mousePos.x < offset ||
67 | mousePos.x > WINDOW_WIDTH - offset && mousePos.x < WINDOW_WIDTH ||
68 | mousePos.y > 0 && mousePos.y < offset ||
69 | mousePos.y > WINDOW_HEIGHT - offset && mousePos.y < WINDOW_HEIGHT)
70 | {
71 | m_windowOffset = m_window.getPosition() - sf::Mouse::getPosition();
72 | m_windowGrabbed = true;
73 | }
74 | }
75 | else if (m_event.type == sf::Event::MouseButtonReleased && m_event.mouseButton.button == sf::Mouse::Left) {
76 | m_windowGrabbed = false;
77 | }
78 | else if (m_event.type == sf::Event::MouseMoved && m_windowGrabbed) {
79 | m_window.setPosition(sf::Mouse::getPosition() + m_windowOffset);
80 | }
81 | }
82 |
83 | void Application::LoadMusicsAndSounds() {
84 | //MUSIC//
85 | MusicController::Get().AddMusic("menu", "res/music/menu.ogg");
86 | MusicController::Get().AddMusic("main_track", "res/music/main.ogg");
87 | //MusicController::Get().AddMusic("pause", "res/music/pause.ogg");
88 |
89 | //SOUNDS//
90 | MusicController::Get().AddSound("button", "res/sounds/button.wav");
91 | MusicController::Get().AddSound("player_jump", "res/sounds/playerJump.wav");
92 | MusicController::Get().AddSound("player_crouch", "res/sounds/playerCrouch.wav");
93 | MusicController::Get().AddSound("blow_up", "res/sounds/blowUp.wav");
94 | MusicController::Get().AddSound("pick_up", "res/sounds/pickUp.wav");
95 | //MusicController::Get().AddSound("ghost", "res/sounds/ghost.wav"); <- it dosen't work and i dont know why B))
96 |
97 | //MusicController::Get().AddSound("3", "res/sounds/3.wav");
98 | //MusicController::Get().AddSound("2", "res/sounds/2.wav");
99 | //MusicController::Get().AddSound("1", "res/sounds/1.wav");
100 | //MusicController::Get().AddSound("GO", "res/sounds/go.wav");
101 | }
102 |
103 | void Application::SetShaderUniforms() {
104 | ShaderLibrary::Get().GetShader("transition").setUniform("u_resolution", sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
105 | ShaderLibrary::Get().GetShader("fog").setUniform("u_resolution", sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
106 |
107 | }
108 |
109 | void Application::LoadShaders() {
110 | ShaderLibrary::Get().LoadShader("transition", "res/shaders/transitionFragment.shader", "res/shaders/transitionVertex.shader");
111 | ShaderLibrary::Get().LoadShader("blur", "res/shaders/blurFragment.shader", "res/shaders/blurVertex.shader");
112 | ShaderLibrary::Get().LoadShader("fog", "res/shaders/fogFragment.shader", "res/shaders/fogVertex.shader");
113 | ShaderLibrary::Get().LoadShader("light", "res/shaders/lightFragment.shader", "res/shaders/lightVertex.shader");
114 |
115 | SetShaderUniforms();
116 | }
117 |
118 | void Application::InitStates() {
119 | m_machine = new StateMachine(m_window, m_dt, m_fdt);
120 |
121 | m_machine->AddStateAtTop(new Menu(*m_machine));
122 | }
123 |
124 | void Application::HandleEvents() {
125 | while (m_window.pollEvent(m_event)) {
126 | if (
127 | m_event.type == sf::Event::MouseMoved ||
128 | m_event.type == sf::Event::MouseButtonPressed ||
129 | m_event.type == sf::Event::MouseButtonReleased
130 | )
131 | {
132 | MoveWindow();
133 | }
134 |
135 | switch (m_event.type) {
136 | case sf::Event::Closed:
137 | m_window.close();
138 | break;
139 | }
140 | }
141 | }
142 |
143 | void Application::InitWindow() {
144 | sf::ContextSettings contextSettings;
145 |
146 | //contextSettings.majorVersion = 3;
147 | //contextSettings.minorVersion = 3;
148 |
149 | sf::VideoMode videoMode(WINDOW_WIDTH, WINDOW_HEIGHT);
150 |
151 | sf::Image image;
152 | image.loadFromFile("res/textures/icon.png");
153 |
154 | m_window.create(videoMode, "DEATHJUMP!", sf::Style::None, contextSettings);
155 | m_window.setIcon(image.getSize().x, image.getSize().y, image.getPixelsPtr());
156 | m_window.setFramerateLimit(250);
157 | }
158 |
159 | bool Application::IsRunning() const {
160 | return m_window.isOpen();
161 | }
--------------------------------------------------------------------------------
/The Platformer/Application.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "Shader Library.hpp"
5 | #include "Key Check.hpp"
6 |
7 | #include "States/Machine/State Machine.hpp"
8 | #include "States/State/Menu/Menu.hpp"
9 | #include "States/Save.hpp"
10 |
11 | #include "Effects/Transition/Transition.hpp"
12 | #include "Effects/Music Controller/Music Controller.hpp"
13 | #include "Effects/Camera/Camera.hpp"
14 |
15 | class Application {
16 | public:
17 | Application(const float& dt, const float& fdt);
18 | ~Application();
19 |
20 | void Update();
21 | void FixedUpdate();
22 |
23 | void Render();
24 |
25 | bool IsRunning() const;
26 | private:
27 | sf::RenderWindow m_window;
28 | sf::Event m_event;
29 |
30 | StateMachine* m_machine;
31 |
32 | const float& m_fdt;
33 | const float& m_dt;
34 |
35 | sf::Vector2i m_windowOffset;
36 | bool m_windowGrabbed = false;
37 |
38 | void MoveWindow();
39 |
40 | void LoadMusicsAndSounds();
41 |
42 | void SetShaderUniforms();
43 | void LoadShaders();
44 |
45 | void InitStates();
46 |
47 | void HandleEvents();
48 | void InitWindow();
49 | };
50 |
--------------------------------------------------------------------------------
/The Platformer/Effects/Camera/Camera.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Camera.hpp"
3 |
4 | #include "Random.hpp"
5 |
6 | Camera& Camera::Get() {
7 | return s_instance;
8 | }
9 |
10 | const sf::View& Camera::GetView() {
11 | return m_view;
12 | }
13 |
14 | void Camera::Update(const float& dt) {
15 | m_elapsedTime += dt;
16 | while (m_elapsedTime > m_updateTime) {
17 | ApplayEffect();
18 | m_elapsedTime -= m_updateTime;
19 | }
20 | }
21 |
22 | void Camera::Shake(const float& duration) {
23 | m_duration = duration;
24 |
25 | m_currentPosition = 0;
26 |
27 | for (int i = 0; i < 15; i++)
28 | m_positions[i] = sf::Vector2i(Random::RandInt(-12, 12), Random::RandInt(-12, 12));
29 | }
30 |
31 | void Camera::ApplayEffect() {
32 | if (m_duration > 0.0f) {
33 | m_duration -= 0.1f;
34 |
35 | m_view.setCenter(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT) / 2.0f + (sf::Vector2f)m_positions[m_currentPosition]);
36 |
37 | m_currentPosition++;
38 | if (m_currentPosition > 9)
39 | m_currentPosition = 0;
40 |
41 | if (m_duration <= 0.0f)
42 | m_duration = 0.0f;
43 | }
44 |
45 | if (m_duration == 0.0f) {
46 | m_view.setCenter(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT) / 2.0f);
47 | }
48 | }
49 |
50 | void Camera::InitView() {
51 | m_view.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
52 | m_view.setCenter(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT) / 2.0f);
53 | }
54 |
55 | Camera Camera::s_instance;
--------------------------------------------------------------------------------
/The Platformer/Effects/Camera/Camera.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | class Camera {
5 | public:
6 | static Camera& Get();
7 |
8 | const sf::View& GetView();
9 |
10 | void Update(const float& dt);
11 |
12 | void Shake(const float& duration);
13 | private:
14 | Camera() { InitView(); }
15 | ~Camera() {}
16 |
17 | sf::View m_view;
18 |
19 | sf::Vector2i m_positions[15];
20 |
21 | int m_currentPosition = 0;
22 |
23 | const float m_updateTime = 0.02f;
24 | float m_elapsedTime = 0.0f;
25 |
26 | float m_duration = 0.0f;
27 |
28 | static Camera s_instance;
29 |
30 | void ApplayEffect();
31 | void InitView();
32 | };
--------------------------------------------------------------------------------
/The Platformer/Effects/Light/Light.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Light.hpp"
3 |
4 | #include "Random.hpp"
5 |
6 | Light::Light
7 | (
8 | sf::Vector2f position,
9 | float radius
10 | )
11 | : m_shader(ShaderLibrary::Get().GetShader("light")), m_position(position), m_radius(radius)
12 | {
13 | m_body.setSize(sf::Vector2f(radius, radius));
14 | m_body.setOrigin(sf::Vector2f(radius, radius) / 2.0f);
15 | m_body.setTextureRect(sf::IntRect(0, 0, 1, 1));
16 | m_body.setPosition(position);
17 |
18 | const int r1 = Random::RandInt(1, 10);
19 | const int r2 = Random::RandInt(5, 20);
20 |
21 | m_move = (float)r1 / (float)r2;
22 | }
23 |
24 | Light::~Light() {
25 |
26 | }
27 |
28 | void Light::SetPosition(sf::Vector2f position) {
29 | m_position = position;
30 | m_body.setPosition(position);
31 | }
32 |
33 | void Light::draw(sf::RenderTarget& target, sf::RenderStates states) const {
34 | m_shader.setUniform("u_move", m_move);
35 | target.draw(m_body, &m_shader);
36 | }
37 |
--------------------------------------------------------------------------------
/The Platformer/Effects/Light/Light.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Shader Library.hpp"
4 |
5 | class Light : public sf::Drawable {
6 | public:
7 | Light(sf::Vector2f position, float radius);
8 | ~Light();
9 |
10 | void SetPosition(sf::Vector2f position);
11 | private:
12 | float m_radius = 0.0f;
13 | sf::Vector2f m_position;
14 |
15 | sf::Shader& m_shader;
16 | sf::RectangleShape m_body;
17 |
18 | float m_move = 0.0f;
19 |
20 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
21 | };
--------------------------------------------------------------------------------
/The Platformer/Effects/Music controller/Music Controller.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Music Controller.hpp"
3 |
4 | MusicController& MusicController::Get() {
5 | return s_instance;
6 | }
7 |
8 | void MusicController::Update() {
9 | for (auto& s : m_Sounds)
10 | s.second.setVolume((float)Extern::sound_volume);
11 |
12 | for (auto& m : m_Musics)
13 | m.second.setVolume((float)Extern::music_volume);
14 | }
15 |
16 | void MusicController::AddSound(std::string name, std::string path) {
17 | m_Buffers.push_back(sf::SoundBuffer());
18 | m_Buffers.back().loadFromFile(path);
19 |
20 | m_Sounds.insert(std::pair(name, sf::Sound()));
21 |
22 | int i = 0;
23 | for (auto& s : m_Sounds) {
24 | s.second.setBuffer(m_Buffers[i]);
25 | s.second.setVolume(0);
26 | i++;
27 | }
28 | }
29 |
30 | void MusicController::AddMusic(std::string name, std::string path) {
31 | m_Musics[name].openFromFile(path);
32 | m_Musics[name].setVolume(0);
33 | }
34 |
35 | sf::Sound& MusicController::GetSound(std::string name) {
36 | return m_Sounds[name];
37 | }
38 |
39 | sf::Music& MusicController::GetMusic(std::string name) {
40 | return m_Musics[name];
41 | }
42 |
43 | MusicController MusicController::s_instance;
--------------------------------------------------------------------------------
/The Platformer/Effects/Music controller/Music Controller.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "../Public Variables/Extern.hpp"
5 |
6 | class MusicController {
7 | public:
8 | MusicController(const MusicController&) = delete;
9 |
10 | static MusicController& Get();
11 |
12 | void Update();
13 |
14 | void AddSound(std::string name, std::string path);
15 | void AddMusic(std::string name, std::string path);
16 |
17 | sf::Sound& GetSound(std::string name);
18 | sf::Music& GetMusic(std::string name);
19 | private:
20 | MusicController() {}
21 | ~MusicController() {}
22 |
23 | std::vector m_Buffers;
24 | std::unordered_map m_Musics;
25 | std::unordered_map m_Sounds;
26 |
27 | static MusicController s_instance;
28 | };
--------------------------------------------------------------------------------
/The Platformer/Effects/Particle Emitter/Particle Emitter.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Particle Emitter.hpp"
3 |
4 | #include "Random.hpp"
5 |
6 | ParticleEmitter::ParticleEmitter
7 | (
8 | const sf::Color birthColor,
9 | const sf::Color deathColor,
10 | unsigned size
11 | )
12 | : m_size(size)
13 | {
14 | m_birthColor = sf::Vector3f(birthColor.r, birthColor.g, birthColor.b);
15 | m_deathColor = sf::Vector3f(deathColor.r, deathColor.g, deathColor.b);
16 | }
17 |
18 | ParticleEmitter::~ParticleEmitter() {
19 |
20 | }
21 |
22 | void ParticleEmitter::Update(const float& dt) {
23 | m_elapsedTime += dt;
24 | while (m_elapsedTime >= m_updateTime) {
25 | m_elapsedTime -= m_updateTime;
26 | UpdateParticles();
27 | }
28 | }
29 |
30 | void ParticleEmitter::AddParticles() {
31 | for (int i = m_particles.size(); i < m_max; i++) {
32 | float randX = Random::RandFloat(-m_spread, m_spread);
33 | float randY = Random::RandFloat(-m_spread, m_spread);
34 |
35 | // god please
36 | if (m_direction == sf::Vector2f()) {
37 | randX = Random::RandInt(0, 1) ? Random::RandFloat(-1.15f, -0.15f) : Random::RandFloat(0.15f, 1.15f);
38 | randY = Random::RandInt(0, 1) ? Random::RandFloat(-1.15f, -0.15f) : Random::RandFloat(0.15f, 1.15f);
39 | }
40 |
41 | sf::Vector2f dir = sf::Vector2f
42 | (
43 | m_direction.x == 0.0f ? randX : m_direction.x * Random::RandFloat(0.90f, 1.12f),
44 | m_direction.y == 0.0f ? randY : m_direction.y * Random::RandFloat(0.90f, 1.12f)
45 | );
46 |
47 | m_particles.push_back(Particle(Random::RandFloat(m_lifeTimeMin, m_lifeTimeMax), dir));
48 |
49 | AddQuad(m_position);
50 | SetQuadRotation(i, Random::RandInt(0, 180));
51 | }
52 |
53 | }
54 |
55 | void ParticleEmitter::SetPosition(const sf::Vector2f& pos) {
56 | m_position = pos;
57 | }
58 |
59 | void ParticleEmitter::SetDirection(const sf::Vector2f& dir) {
60 | m_direction = dir;
61 | }
62 |
63 | void ParticleEmitter::SetLifeTimeRange(const float& min, const float& max) {
64 | m_lifeTimeMin = min;
65 | m_lifeTimeMax = max;
66 | }
67 |
68 | void ParticleEmitter::SetSpeed(const float& speed) {
69 | m_movementSpeed = speed;
70 | }
71 | void ParticleEmitter::SetBirthColor(sf::Color color) {
72 | m_birthColor = sf::Vector3f(color.r, color.g, color.b);
73 | }
74 | void ParticleEmitter::SetDeathColor(sf::Color color) {
75 | m_deathColor = sf::Vector3f(color.r, color.g, color.b);
76 | }
77 |
78 | void ParticleEmitter::SetParticleMax(unsigned max) {
79 | m_max = max;
80 | }
81 |
82 | void ParticleEmitter::SetSpread(float spraed) {
83 | m_spread = spraed;
84 | }
85 |
86 | void ParticleEmitter::SetSize(unsigned size) {
87 | m_size = size;
88 | }
89 |
90 | void ParticleEmitter::Clear() {
91 | m_particles.clear();
92 | m_vertices.clear();
93 | }
94 |
95 |
96 | void ParticleEmitter::UpdateParticles() {
97 | for (int i = 0; i < m_particles.size(); i++) {
98 | auto& particle = m_particles[i];
99 |
100 | particle.lifeTime -= 0.1f;
101 |
102 | if (particle.lifeTime <= 0.0f) {
103 | DeleteQuad(i);
104 | continue;
105 | }
106 |
107 | float life = particle.lifeTime / particle.constLifeTime;
108 |
109 | sf::Vector3f color = Lerp(m_deathColor, m_birthColor, life);
110 |
111 | SetQuadColor(i, sf::Color(color.x, color.y, color.z, life * 255));
112 |
113 | float scale = Lerp((96.0f * m_size) / 100.0f, m_size, life); // i should consider making function for set this shit with now is (96.0f * m_size) / 100.0f
114 |
115 | SetQuadScale(i, scale / m_size);
116 |
117 | MoveQuad(i, particle.direction);
118 | }
119 | }
120 |
121 | void ParticleEmitter::AddQuad(const sf::Vector2f pos) {
122 | std::array vertices;
123 |
124 | vertices[0].position = sf::Vector2f(pos.x, pos.y);
125 | vertices[1].position = sf::Vector2f(pos.x + m_size, pos.y);
126 | vertices[2].position = sf::Vector2f(pos.x + m_size, pos.y + m_size);
127 | vertices[3].position = sf::Vector2f(pos.x, pos.y + m_size);
128 |
129 | for (auto& v : vertices) {
130 | v.color = sf::Color(m_birthColor.x, m_birthColor.y, m_birthColor.z);
131 | m_vertices.push_back(v);
132 | }
133 | }
134 |
135 | void ParticleEmitter::DeleteQuad(unsigned index) {
136 | m_particles.erase(m_particles.begin() + index);
137 |
138 | index *= 4;
139 | for (int i = index; i < index + 4; i++)
140 | m_vertices.erase(m_vertices.begin() + index);
141 | }
142 |
143 | void ParticleEmitter::SetQuadColor(unsigned index, const sf::Color& color) {
144 | index *= 4;
145 |
146 | for (int i = index; i < index + 4; i++)
147 | m_vertices[i].color = color;
148 | }
149 |
150 | void ParticleEmitter::SetQuadScale(unsigned index, const float& scale) {
151 | // yeah i think should consider suicide after writing this function
152 |
153 | index *= 4;
154 |
155 | float sizeX = (m_vertices[index].position.x - m_vertices[index + 1].position.x) / 2.0f;
156 | float sizeY = (m_vertices[index].position.y - m_vertices[index + 3].position.y) / 2.0f;
157 |
158 | float centX = m_vertices[index].position.x - sizeX;
159 | float centY = m_vertices[index].position.y - sizeY;
160 |
161 | sf::Transform t;
162 | t.scale(sf::Vector2f(scale, scale), sf::Vector2f(centX, centY));
163 |
164 | for (int i = index; i < index + 4; i++)
165 | m_vertices[i].position = t.transformPoint(m_vertices[i].position);
166 | }
167 |
168 | void ParticleEmitter::SetQuadRotation(unsigned index, const float& angle) {
169 | index *= 4;
170 |
171 | float sizeX = (m_vertices[index].position.x - m_vertices[index + 1].position.x) / 2.0f;
172 | float sizeY = (m_vertices[index].position.y - m_vertices[index + 3].position.y) / 2.0f;
173 |
174 | float centX = m_vertices[index].position.x - sizeX;
175 | float centY = m_vertices[index].position.y - sizeY;
176 |
177 | sf::Transform t;
178 | t.rotate(angle, sf::Vector2f(centX, centY));
179 |
180 | for (int i = index; i < index + 4; i++)
181 | m_vertices[i].position = t.transformPoint(m_vertices[i].position);
182 | }
183 |
184 | void ParticleEmitter::MoveQuad(unsigned index, const sf::Vector2f& dir) {
185 | index *= 4;
186 |
187 | const sf::Vector2f velocity = sf::Vector2f(m_movementSpeed * dir.x, m_movementSpeed * dir.y);
188 | sf::Transform t;
189 | t.translate(velocity);
190 |
191 | for (int i = index; i < index + 4; i++)
192 | m_vertices[i].position = t.transformPoint(m_vertices[i].position);
193 | }
194 |
195 | sf::Vector3f ParticleEmitter::Lerp(const sf::Vector3f& x, const sf::Vector3f& y, const float& t) {
196 | return x * (1.f - t) + y * t;
197 | }
198 |
199 | float ParticleEmitter::Lerp(const float& x, const float& y, const float& t) {
200 | return x * (1.f - t) + y * t;
201 | }
202 |
203 | void ParticleEmitter::draw(sf::RenderTarget& target, sf::RenderStates states) const {
204 | target.draw(m_vertices.data(), m_vertices.size(), sf::Quads);
205 | }
206 |
--------------------------------------------------------------------------------
/The Platformer/Effects/Particle Emitter/Particle Emitter.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | // it's not a good patricle class but it's good enough for me
5 |
6 | struct Particle
7 | {
8 | Particle(float lifeTime, sf::Vector2f direction)
9 | : lifeTime(lifeTime), constLifeTime(lifeTime), direction(direction)
10 | {
11 |
12 | }
13 |
14 | float lifeTime = 0.0f;
15 | float constLifeTime = 0.0f;
16 | sf::Vector2f direction;
17 | };
18 |
19 | class ParticleEmitter : public sf::Drawable {
20 | public:
21 | ParticleEmitter(const sf::Color birthColor, const sf::Color deathColor, unsigned size);
22 | ~ParticleEmitter();
23 |
24 | void Update(const float& dt);
25 | void AddParticles();
26 |
27 | void SetPosition(const sf::Vector2f& pos);
28 | void SetDirection(const sf::Vector2f& dir);
29 |
30 | void SetLifeTimeRange(const float& min, const float& max);
31 |
32 | void SetSpeed(const float& speed);
33 |
34 | void SetBirthColor(sf::Color color);
35 | void SetDeathColor(sf::Color color);
36 |
37 | void SetParticleMax(unsigned max);
38 | void SetSpread(float spred);
39 |
40 | void SetSize(unsigned size);
41 |
42 | void Clear();
43 | private:
44 | sf::Vector3f m_birthColor;
45 | sf::Vector3f m_deathColor;
46 |
47 | const float m_updateTime = 0.015f;
48 | float m_movementSpeed = 5.5f;
49 | float m_elapsedTime = 0.0f;
50 |
51 | unsigned m_size = 0;
52 | unsigned m_max = 50;
53 |
54 | float m_lifeTimeMin = 0.0f;
55 | float m_lifeTimeMax = 0.0f;
56 |
57 | float m_spread = 0.3f;
58 |
59 | sf::Vector2f m_position;
60 | sf::Vector2f m_direction;
61 |
62 | std::vector m_vertices;
63 | std::vector m_particles;
64 |
65 | void UpdateParticles();
66 |
67 | void AddQuad(const sf::Vector2f pos);
68 | void DeleteQuad(unsigned index);
69 | void SetQuadColor(unsigned index, const sf::Color& color);
70 | void SetQuadScale(unsigned index, const float& scale);
71 | void SetQuadRotation(unsigned index, const float& angle);
72 | void MoveQuad(unsigned index, const sf::Vector2f& dir);
73 |
74 | sf::Vector3f Lerp(const sf::Vector3f& x, const sf::Vector3f& y, const float& t);
75 | float Lerp(const float& x, const float& y, const float& t);
76 |
77 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
78 | };
--------------------------------------------------------------------------------
/The Platformer/Effects/Transition/Transition.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Transition.hpp"
3 |
4 | Transition& Transition::Get() {
5 | return s_instance;
6 | }
7 |
8 | void Transition::Init() {
9 | m_shader = &ShaderLibrary::Get().GetShader("transition");
10 | }
11 |
12 | void Transition::SetFunction(std::function fun) { m_fun = fun; }
13 |
14 | void Transition::Update(const float& dt) {
15 | m_elapsedTime += dt;
16 | while (m_elapsedTime >= m_updateTime) {
17 | m_elapsedTime -= m_updateTime;
18 | UpdateTransition(((bool)m_mode ? 1 : -1));
19 | }
20 | }
21 |
22 | void Transition::Start(Mode mode) {
23 | m_mode = mode;
24 | }
25 |
26 | const sf::Shader& Transition::GetShader() const { return *m_shader; }
27 |
28 |
29 | void Transition::UpdateTransition(int multi) {
30 | m_shader->setUniform("progress", m_progress);
31 |
32 | m_progress += 0.01f * multi;
33 |
34 | // do not ask
35 | if (multi > 0) {
36 | if (m_progress > 1.0f) {
37 | m_progress = 1.0f;
38 | if (m_fun) {
39 | m_fun();
40 | m_fun = 0;
41 | }
42 | }
43 | }
44 | else {
45 | if (m_progress < 0.0f) {
46 | m_progress = 0.0f;
47 | if (m_fun) {
48 | m_fun();
49 | m_fun = 0;
50 | }
51 | }
52 | }
53 | }
54 |
55 | Transition Transition::s_instance;
56 |
57 | //float Transition::m_updateTime = 0.0075f;
58 | //float Transition::m_elapsedTime = 0.0f;
59 | //float Transition::m_progress = 0.0f;
60 | //
61 | //Mode Transition::m_mode = Mode::Unveil;
62 | //
63 | //sf::Shader* Transition::m_shader = nullptr;
64 | //std::function Transition::m_fun = 0;
--------------------------------------------------------------------------------
/The Platformer/Effects/Transition/Transition.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "Shader Library.hpp"
5 |
6 | enum class Mode {
7 | Veil = 0,
8 | Unveil = 1
9 | };
10 |
11 | class Transition {
12 | public:
13 | Transition(const Transition&) = delete;
14 |
15 | static Transition& Get();
16 |
17 | void Init();
18 |
19 | void Update(const float& dt);
20 |
21 | void Start(Mode mode);
22 |
23 | void SetFunction(std::function fun);
24 |
25 | const sf::Shader& GetShader() const;
26 |
27 | private:
28 | Transition() {}
29 | ~Transition() {}
30 |
31 | static Transition s_instance;
32 |
33 | sf::Shader* m_shader = nullptr;
34 | float m_updateTime = 0.0075f;
35 | float m_elapsedTime = 0.0f;
36 | float m_progress = 0.0f;
37 |
38 | Mode m_mode = Mode::Unveil;
39 | std::function m_fun = 0;
40 |
41 | void UpdateTransition(int multi);
42 | };
--------------------------------------------------------------------------------
/The Platformer/Entities/Entity.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Entity.hpp"
3 |
4 | Entity::Entity
5 | (
6 | const float& dt,
7 | const float& fdt
8 | )
9 | : i_dt(dt), i_fdt(fdt)
10 | {
11 |
12 | }
13 |
14 | Entity::~Entity() {
15 | delete i_drawable;
16 | }
17 |
18 | Collision Entity::GetCollider() { return i_collider; }
19 |
20 | void Entity::draw(sf::RenderTarget& target, sf::RenderStates states) const { target.draw(*i_drawable, i_shader); }
21 | //void Entity::draw(sf::RenderTarget& target, sf::RenderStates states) const {
22 | // sf::RectangleShape shape;
23 | // shape.setSize(i_collider.size);
24 | // shape.setOrigin(i_collider.size / 2.0f);
25 | // shape.setPosition(i_collider.position);
26 | //
27 | // target.draw(shape);
28 | //}
29 |
--------------------------------------------------------------------------------
/The Platformer/Entities/Entity.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Collision/Collision.hpp"
4 |
5 | class Entity : public sf::Drawable {
6 | public:
7 | Entity(const float& dt, const float& fdt);
8 | virtual ~Entity();
9 |
10 | virtual void FixedUpdate() = 0;
11 | virtual void Update() = 0;
12 |
13 | Collision GetCollider();
14 | protected:
15 | Collider i_collider;
16 |
17 | sf::Drawable* i_drawable = nullptr;
18 | sf::Texture* i_texture = nullptr;
19 | sf::Shader* i_shader = nullptr;
20 |
21 | const float& i_fdt;
22 | const float& i_dt;
23 |
24 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
25 | };
--------------------------------------------------------------------------------
/The Platformer/Entities/Fireball.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Fireball.hpp"
3 |
4 | #include "Random.hpp"
5 |
6 | Fireball::Fireball
7 | (
8 | const float& dt,
9 | const float& fdt,
10 | sf::Texture* texture,
11 | sf::Texture* blowUp,
12 | float velocity,
13 | bool left
14 | )
15 | : Entity(dt, fdt), m_velocity(velocity), m_dt(dt), m_fdt(fdt) // haha ;))))) i wanna killmyselfffffff
16 | {
17 | i_texture = texture;
18 | m_blowTexture = blowUp;
19 | m_left = left;
20 |
21 | InitCollider(sf::Vector2f(left ? -100.f : WINDOW_WIDTH + 100.f, m_positions[Random::RandInt(0, 12)]));
22 | InitSprites();
23 | InitAnimations();
24 | InitEmiiter();
25 | InitLight();
26 | }
27 |
28 | Fireball::~Fireball() {
29 | delete m_emitter;
30 | delete m_light;
31 | }
32 |
33 | void Fireball::FixedUpdate() {
34 | if(!m_blowUp)
35 | Move();
36 | }
37 |
38 | void Fireball::Update() {
39 | UpdateLight();
40 | UpdateEmitter();
41 | Animate();
42 |
43 | if (i_collider.position.x > WINDOW_WIDTH + 300.0f || i_collider.position.x < -300.0f)
44 | m_alive = false;
45 | }
46 |
47 | bool Fireball::Alive() const {
48 | return m_alive;
49 | }
50 |
51 | void Fireball::Move() {
52 | int multi = (m_left ? 1 : -1);
53 |
54 | i_collider.position += sf::Vector2f(m_velocity * multi * m_fdt, 0.0f);
55 | m_fireballSprite.setPosition(i_collider.position);
56 | }
57 |
58 | void Fireball::UpdateLight() {
59 | m_light->SetPosition(i_collider.position);
60 | }
61 |
62 | void Fireball::InitLight() {
63 | m_light = new Light(i_collider.position, 290.0f);
64 | }
65 |
66 | void Fireball::UpdateEmitter() {
67 | if(!m_blowUp)
68 | m_emitter->AddParticles();
69 | m_emitter->Update(m_dt);
70 | m_emitter->SetPosition(i_collider.position);
71 | }
72 |
73 | void Fireball::InitEmiiter() {
74 | m_emitter = new ParticleEmitter(sf::Color(255, 255, 0), sf::Color(255, 0, 0), 20);
75 | m_emitter->SetDirection(sf::Vector2f(m_left ? -1 : 1, 0.0f));
76 | m_emitter->SetLifeTimeRange(0.8f, 2.0f);
77 | m_emitter->SetSpeed(4.1f);
78 | m_emitter->SetPosition(i_collider.position);
79 | }
80 |
81 | void Fireball::Animate() {
82 | if (m_blowUp) {
83 |
84 | if (m_Animations["blow_up"].GetCurrentFrame() == m_Animations["blow_up"].GetFrameCount() - 1) {
85 | m_alive = false;
86 | return;
87 | }
88 |
89 | m_blowUpSprite.setPosition(i_collider.position);
90 | m_Animations["blow_up"].Update(m_dt);
91 | }
92 | }
93 |
94 | void Fireball::InitAnimations() {
95 | m_Animations["blow_up"].Create(12, 0, 0.05f, sf::Vector2i(512, 512), m_blowUpSprite);
96 | }
97 |
98 | void Fireball::InitSprites() {
99 | {
100 | m_fireballSprite.setTexture(*i_texture);
101 | m_fireballSprite.setOrigin(sf::Vector2f(m_size.x, m_size.y) / 2.0f);
102 | m_fireballSprite.setScale(sf::Vector2f(m_left ? 2.f : -2.f, 2.f));
103 | m_fireballSprite.setPosition(i_collider.position);
104 | }
105 |
106 | {
107 | sf::Vector2f size = sf::Vector2f(512.f, 512.f);
108 |
109 | m_blowUpSprite.setTexture(*m_blowTexture);
110 | m_blowUpSprite.setTextureRect(sf::IntRect(0, 0, size.x, size.y));
111 | m_blowUpSprite.setOrigin(size / 2.f);
112 | m_blowUpSprite.setScale(sf::Vector2f(0.30f, 0.30f));
113 | }
114 | }
115 |
116 | void Fireball::InitCollider(sf::Vector2f position) {
117 | const sf::Vector2f size = sf::Vector2f(32.f, 32.f);
118 | i_collider.size = size;
119 | i_collider.position = position;
120 | }
121 |
122 | void Fireball::draw(sf::RenderTarget& target, sf::RenderStates states) const {
123 | target.draw(*m_emitter);
124 | if (!m_blowUp)
125 | target.draw(m_fireballSprite);
126 | else
127 | target.draw(m_blowUpSprite);
128 | target.draw(*m_light);
129 | /*sf::RectangleShape rs;
130 | rs.setSize(i_collider.size);
131 | rs.setOrigin(i_collider.size / 2.0f);
132 | rs.setPosition(i_collider.position);
133 | target.draw(rs, i_shader);*/
134 | }
135 |
--------------------------------------------------------------------------------
/The Platformer/Entities/Fireball.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Entity.hpp"
4 |
5 | #include "Animations/Animator.hpp"
6 | #include "../Effects/Particle Emitter/Particle Emitter.hpp"
7 | #include "../Effects/Light/Light.hpp"
8 |
9 | class Player;
10 |
11 | class Fireball : public Entity {
12 | public:
13 | Fireball(const float& dt, const float& fdt, sf::Texture* texture, sf::Texture* blowUp, float velocity, bool left);
14 | ~Fireball();
15 |
16 | virtual void FixedUpdate();
17 | virtual void Update();
18 |
19 | bool Alive() const;
20 | private:
21 | friend class Player; // please don't judge me for that im out of my mind
22 |
23 | sf::Sprite m_fireballSprite;
24 | sf::Sprite m_blowUpSprite;
25 |
26 | sf::Texture* m_blowTexture;
27 |
28 | std::unordered_map m_Animations;
29 |
30 | sf::Vector2i m_size = sf::Vector2i(32, 32);
31 |
32 | ParticleEmitter* m_emitter;
33 |
34 | Light* m_light;
35 |
36 | bool m_left = true;
37 | bool m_alive = true;
38 | bool m_blowUp = false;
39 |
40 | const float m_velocity = 150.0f;
41 |
42 | const float& m_dt;
43 | const float& m_fdt;
44 |
45 | const float m_positions[13] =
46 | {
47 | 35.f,
48 | 105.f,
49 | 145.f,
50 | 210.f,
51 | 270.f,
52 | 310.f,
53 | 380.f,
54 | 455.f,
55 | 500.f,
56 | 565.f,
57 | 625.f,
58 | 730.f,
59 | 790.f,
60 | };
61 |
62 | void Move();
63 |
64 | void UpdateLight();
65 | void InitLight();
66 |
67 | void UpdateEmitter();
68 | void InitEmiiter();
69 |
70 | void Animate();
71 | void InitAnimations();
72 | void InitSprites();
73 | void InitCollider(sf::Vector2f position);
74 |
75 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
76 | };
--------------------------------------------------------------------------------
/The Platformer/Entities/Ghost.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Ghost.hpp"
3 |
4 | #include "Random.hpp"
5 |
6 | Ghost::Ghost
7 | (
8 | sf::Texture* texture,
9 | const float& dt,
10 | const float& fdt
11 | )
12 | : Entity(dt, fdt)
13 | {
14 | i_texture = texture;
15 |
16 | m_left = Random::RandInt(0, 1);
17 |
18 | //m_lifeTime = (float)Random::RandInt(10, 12);
19 |
20 | InitBody();
21 | InitAnimator();
22 | InitLight();
23 | InitEmitter();
24 | }
25 |
26 | Ghost::~Ghost() {
27 | delete m_light;
28 | delete m_emitter;
29 | }
30 |
31 | void Ghost::FixedUpdate() {
32 | const float velocity = 165.0f;
33 |
34 | i_collider.position += m_dir * velocity * i_fdt;
35 |
36 | i_collider.position.y += 80.0f * (sinf(4 * m_clock.getElapsedTime().asSeconds())) * i_fdt;
37 |
38 | m_sprite->setPosition(i_collider.position);
39 |
40 | //LOG(i_collider.position.x, '\n');
41 | }
42 |
43 | void Ghost::Update(Collider obj) {
44 | UpdateLight();
45 |
46 | m_emitter->Update(i_dt);
47 | m_emitter->SetPosition(i_collider.position);
48 |
49 | if (m_blowUp) {
50 | m_animator.Update(i_dt);
51 |
52 | if (m_animator.GetCurrentFrame() == m_animator.GetFrameCount() - 1)
53 | m_isAlive = false;
54 |
55 | return;
56 | }
57 | else
58 | m_emitter->AddParticles();
59 |
60 | m_lifeTime -= i_dt;
61 |
62 | if (m_lifeTime < 2.0f) {
63 | float life = m_lifeTime / 2.0f;
64 | float alpha = Lerp(0.0f, 1.0f, life);
65 |
66 | if (alpha <= 0.08f)
67 | m_isAlive = false;
68 |
69 | if (alpha < 0.55f)
70 | m_lightVal = alpha;
71 |
72 | m_sprite->setColor(sf::Color(255, 255, 255, alpha * 255));
73 | }
74 | obj.position.y += 35.0f;
75 |
76 | sf::Vector2f diff = obj.position - i_collider.position;
77 |
78 | float magnitude = sqrt(diff.x * diff.x + diff.y * diff.y);
79 |
80 | m_dir = diff / magnitude;
81 |
82 | m_left = obj.position.x > i_collider.position.x;
83 |
84 | m_animator.Update(i_dt);
85 | m_sprite->setScale(m_left ? sf::Vector2f(-2.75f, 2.75f) : sf::Vector2f(2.75f, 2.75f));
86 | }
87 |
88 | float Ghost::Lerp(const float& x, const float& y, const float& t) {
89 | return x * (1.f - t) + y * t;
90 | }
91 |
92 | void Ghost::InitEmitter() {
93 | m_emitter = new ParticleEmitter(sf::Color(255, 255, 255), sf::Color(0, 0, 0), 0);
94 | m_emitter->SetLifeTimeRange(0.8f, 2.0f);
95 | m_emitter->SetSpeed(4.1f);
96 | m_emitter->SetPosition(i_collider.position);
97 | m_emitter->AddParticles();
98 | }
99 |
100 | void Ghost::UpdateLight() {
101 | m_light->SetPosition(i_collider.position);
102 | }
103 |
104 | void Ghost::InitLight() {
105 | m_light = new Light(sf::Vector2f(), 275.0f);
106 | }
107 |
108 | void Ghost::InitAnimator() {
109 | m_animator.Create(4, 0, 0.1f, sf::Vector2i(64, 64), *m_sprite);
110 | }
111 |
112 | void Ghost::InitBody() {
113 | {
114 | i_drawable = new sf::Sprite(*i_texture);
115 |
116 | m_sprite = reinterpret_cast(i_drawable);
117 |
118 | m_sprite->setOrigin(sf::Vector2f(64.0f, 64.0f) / 2.0f);
119 | m_sprite->setTextureRect(sf::IntRect(0, 0, 64, 64));
120 | }
121 |
122 | {
123 | float posX = Random::RandInt(0, 1) ? -100.0f : WINDOW_WIDTH + 100.0f;
124 | //float posX = left ? 100.0f : 1450.0f;
125 |
126 | i_collider.position = sf::Vector2f(posX, Random::RandInt(90, WINDOW_HEIGHT - 90));
127 | i_collider.size = sf::Vector2f(10.0f, 13.0f) * 2.75f;
128 | }
129 | }
130 |
131 | void Ghost::draw(sf::RenderTarget& target, sf::RenderStates states) const {
132 | ShaderLibrary::Get().GetShader("light").setUniform("color", sf::Glsl::Vec4(0.9, 0.9, 0.9, m_lightVal));
133 | if(!m_blowUp)
134 | target.draw(*m_sprite);
135 | target.draw(*m_emitter);
136 | target.draw(*m_light);
137 | /*sf::RectangleShape rs;
138 | rs.setSize(i_collider.size);
139 | rs.setOrigin(i_collider.size / 2.0f);
140 | rs.setPosition(i_collider.position);
141 | target.draw(rs, i_shader);*/
142 | }
143 |
--------------------------------------------------------------------------------
/The Platformer/Entities/Ghost.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "Entity.hpp"
5 |
6 | #include "Animations/Animator.hpp"
7 | #include "../Effects/Light/Light.hpp"
8 | #include "../Effects/Particle Emitter/Particle Emitter.hpp"
9 |
10 | class Ghost : public Entity {
11 | public:
12 | Ghost(sf::Texture* texture, const float& dt, const float& fdt);
13 | ~Ghost();
14 |
15 | virtual void FixedUpdate();
16 | virtual void Update() {};
17 | void Update(Collider obj);
18 |
19 | // i should die for that too ;)
20 | bool m_isAlive = true;
21 | bool m_blowUp = false;
22 | Animator m_animator;
23 |
24 | ParticleEmitter* m_emitter;
25 | bool m_left = false;
26 | private:
27 | sf::Sprite* m_sprite;
28 |
29 | Light* m_light;
30 |
31 | sf::Clock m_clock;
32 |
33 | sf::Vector2f m_dir;
34 |
35 | float m_lifeTime = 12.0f;
36 |
37 | float m_lightVal = 0.55f;
38 |
39 | float Lerp(const float& x, const float& y, const float& t);
40 |
41 | void InitEmitter();
42 |
43 | void UpdateLight();
44 | void InitLight();
45 |
46 | void InitAnimator();
47 | void InitBody();
48 |
49 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
50 | };
--------------------------------------------------------------------------------
/The Platformer/Entities/Heart.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Heart.hpp"
3 |
4 | #include "Random.hpp"
5 |
6 | Heart::Heart
7 | (
8 | sf::Texture* texture,
9 | const float& dt,
10 | const float& fdt
11 | )
12 | : Entity(dt, fdt)
13 | {
14 | i_texture = texture;
15 | InitBody();
16 | InitAnimations();
17 | InitLight();
18 | }
19 |
20 | Heart::~Heart() {
21 | delete m_light;
22 | }
23 |
24 | void Heart::FixedUpdate() {
25 | constexpr float gravity = 300.0f;
26 |
27 | if (!m_grounded)
28 | i_collider.position.y += gravity * i_fdt;
29 |
30 | reinterpret_cast(i_drawable)->setPosition(i_collider.position);
31 | }
32 |
33 | void Heart::Update() {
34 | m_animation.Update(i_dt);
35 | UpdateLight();
36 |
37 | if (realDeSpawnClock.getElapsedTime().asSeconds() > deSpawnTime * 3.f)
38 | _IsAlive = false;
39 |
40 |
41 | if (deSpawnClock.getElapsedTime().asSeconds() > deSpawnTime) {
42 | disappearAnimationTime -= 0.203f;
43 | disappear = true;
44 | deSpawnClock.restart();
45 | }
46 |
47 | if (disappear)
48 | AnimateDisappear();
49 | }
50 |
51 | void Heart::ResolveCollision(std::vector& walls) {
52 | for (auto& o : walls) {
53 | sf::Vector2f MTV;
54 |
55 | if (!GetCollider().CheckCollision(o.GetCollider(), MTV))
56 | continue;
57 |
58 | i_collider.position += MTV;
59 | m_grounded = true;
60 | break;
61 | }
62 | }
63 |
64 | bool Heart::IsAlive() const {
65 | return this->_IsAlive;
66 | }
67 |
68 | void Heart::UpdateLight() {
69 | m_light->SetPosition(i_collider.position);
70 | }
71 |
72 | void Heart::InitLight() {
73 | m_light = new Light(i_collider.position, 180.0f);
74 | }
75 |
76 | void Heart::AnimateDisappear() {
77 | if (this->disappearClock.getElapsedTime().asSeconds() > this->disappearAnimationTime) {
78 | this->currentColor++;
79 | if (this->currentColor > 4)
80 | this->currentColor = 0;
81 | this->disappearClock.restart();
82 | }
83 |
84 | reinterpret_cast(i_drawable)->setColor(this->colors[this->currentColor]);
85 | }
86 |
87 | void Heart::InitAnimations() {
88 | m_animation.Create(4, 0, 0.1f, sf::Vector2i(32, 32), *reinterpret_cast(i_drawable));
89 | }
90 |
91 | void Heart::InitBody() {
92 | int pos = Random::RandInt(32, WINDOW_WIDTH - 32);
93 |
94 | i_drawable = new sf::Sprite(*i_texture);
95 | reinterpret_cast(i_drawable)->setOrigin(sf::Vector2f(32.0f, 32.0f) / 2.0f);
96 | reinterpret_cast(i_drawable)->setPosition(sf::Vector2f(pos, -100.0f));
97 |
98 |
99 | const sf::Vector2f size = sf::Vector2f(32.f, 32.f);
100 |
101 | i_collider.size = size;
102 | i_collider.position = sf::Vector2f(pos, -100.f);
103 | }
104 |
105 | void Heart::draw(sf::RenderTarget& target, sf::RenderStates states) const {
106 | ShaderLibrary::Get().GetShader("light").setUniform("color", sf::Glsl::Vec4(0.75, 0.20, 0.70, 0.8));
107 | target.draw(*m_light);
108 | target.draw(*i_drawable);
109 | }
--------------------------------------------------------------------------------
/The Platformer/Entities/Heart.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Entity.hpp"
4 |
5 | #include "Animations/Animator.hpp"
6 | #include "Fixed Clock.hpp"
7 |
8 | #include "../Effects/Light/Light.hpp"
9 | #include "../Objects/Wall.hpp"
10 |
11 | class Heart : public Entity {
12 | public:
13 | Heart(sf::Texture* texture, const float& dt, const float& fdt);
14 | ~Heart();
15 |
16 | virtual void FixedUpdate();
17 | virtual void Update();
18 |
19 | void ResolveCollision(std::vector& walls);
20 |
21 | bool IsAlive() const;
22 | bool _IsAlive = true; // i should die for that
23 | private:
24 |
25 | bool m_grounded = false;
26 |
27 | Light* m_light;
28 |
29 | Animator m_animation;
30 |
31 | FixedClock deSpawnClock;
32 | FixedClock realDeSpawnClock;
33 | FixedClock disappearClock;
34 |
35 | const float deSpawnTime = 3.0f;
36 | float disappearAnimationTime = 0.5f;
37 |
38 | bool disappear = false;
39 |
40 | unsigned currentColor = 0;
41 |
42 | const sf::Color colors[4] =
43 | {
44 | sf::Color(255, 255, 255, 80),
45 | sf::Color(255, 255, 255, 255),
46 | sf::Color(255, 255, 255, 80),
47 | sf::Color(255, 255, 255, 255),
48 | };
49 |
50 | void UpdateLight();
51 | void InitLight();
52 |
53 | void AnimateDisappear();
54 |
55 | void InitAnimations();
56 | void InitBody();
57 |
58 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
59 | };
--------------------------------------------------------------------------------
/The Platformer/Entities/Player.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Player.hpp"
3 |
4 | #include "Key Check.hpp"
5 |
6 | #include "../Public Variables/Extern.hpp"
7 | #include "../Effects/Music controller/Music Controller.hpp"
8 | #include "../Effects/Camera/Camera.hpp"
9 |
10 | #include "../Entities/Fireball.hpp"
11 |
12 | Player::Player
13 | (
14 | const float& dt,
15 | const float& fdt,
16 | sf::Texture* texture
17 | )
18 | : Entity(dt, fdt)
19 | {
20 | i_texture = texture;
21 |
22 | InitBody();
23 | InitCollider();
24 | InitAnimations();
25 | InitEmitters();
26 |
27 | m_ghostBuffer.loadFromFile("res/sounds/ghost.wav");
28 | m_ghost.setBuffer(m_ghostBuffer);
29 | }
30 |
31 | Player::~Player() {
32 | delete m_emitter;
33 | delete m_fallEmitter;
34 | }
35 |
36 | void Player::FixedUpdate() {
37 | Move();
38 | }
39 |
40 | void Player::Update() {
41 | Animate();
42 | UpdateVelocity();
43 | KeepInBorders();
44 | UpdateEmitters();
45 | UpdateTimer();
46 |
47 | // this here oh god
48 | if (m_healthBar.GetHealthState() <= 0)
49 | m_alive = false;
50 | }
51 |
52 | void Player::ResolveCollision(Entity* entity) {
53 | sf::Vector2f MTV;
54 |
55 | if (!GetCollider().CheckCollision(entity->GetCollider(), MTV) || m_hit)
56 | return;
57 |
58 | auto fireball = reinterpret_cast(entity);
59 |
60 | // i know do not scream
61 | fireball->m_blowUp = true;
62 | fireball->m_emitter->Clear();
63 | fireball->m_emitter->SetDirection(sf::Vector2f(0, 0));
64 | fireball->m_emitter->SetSpeed(5.4f);
65 | fireball->m_emitter->SetParticleMax(80);
66 | fireball->m_emitter->SetSize(25);
67 | fireball->m_emitter->SetLifeTimeRange(1.5f, 3.2f);
68 | fireball->m_emitter->AddParticles();
69 |
70 | m_healthBar.Change(true);
71 |
72 | MusicController::Get().GetSound("blow_up").play();
73 | Camera::Get().Shake(1.75f);
74 |
75 | m_hit = true;
76 | m_grabbing = false;
77 | m_movable = false;
78 | m_torque = 0.925f;
79 |
80 | //m_Animations["takedamage"].SetFrame(0);
81 |
82 | m_velocity.y = -950.0f;
83 | int multi = (reinterpret_cast(entity)->m_left ? 1 : -1);
84 | m_velocity.x = multi * 1200.0f;
85 |
86 | reinterpret_cast(i_drawable)->setScale(sf::Vector2f(2.0f * -multi, 2.0f));
87 | }
88 |
89 | void Player::ResolveCollision(Ghost* entity, std::vector& ghosts) {
90 | sf::Vector2f MTV;
91 |
92 | if (!GetCollider().CheckCollision(entity->GetCollider(), MTV) || m_hit || entity->m_blowUp)
93 | return;
94 |
95 | m_ghost.setVolume(Extern::sound_volume);
96 | m_ghost.play();
97 |
98 | if (MTV.y < 0.0f && m_velocity.y != 0.0f) {
99 | // i know do not scream
100 | entity->m_blowUp = true;
101 | entity->m_emitter->Clear();
102 | entity->m_emitter->SetDirection(sf::Vector2f(0, 0));
103 | entity->m_emitter->SetSpeed(5.4f);
104 | entity->m_emitter->SetParticleMax(80);
105 | entity->m_emitter->SetSize(25);
106 | entity->m_emitter->SetLifeTimeRange(1.5f, 3.2f);
107 | entity->m_emitter->AddParticles();
108 |
109 | entity->m_animator.SetFrame(0);
110 | entity->m_animator.SetUpdateTime(0.1f);
111 |
112 | MusicController::Get().GetSound("ghost").play();
113 |
114 | m_velocity.y = m_jumpVelocity + 400.0f;
115 | m_Animations["jump"].SetFrame(0);
116 |
117 | MusicController::Get().GetSound("player_jump").play();
118 | return;
119 | }
120 |
121 |
122 | // i know do not scream
123 | for (auto& g : ghosts) {
124 | g->m_blowUp = true;
125 | g->m_emitter->Clear();
126 | g->m_emitter->SetDirection(sf::Vector2f(0, 0));
127 | g->m_emitter->SetSpeed(5.4f);
128 | g->m_emitter->SetParticleMax(80);
129 | g->m_emitter->SetSize(25);
130 | g->m_emitter->SetLifeTimeRange(1.5f, 3.2f);
131 | g->m_emitter->AddParticles();
132 |
133 | g->m_animator.SetFrame(0);
134 | g->m_animator.SetUpdateTime(0.1f);
135 | }
136 |
137 | m_healthBar.Change(true);
138 |
139 | MusicController::Get().GetSound("blow_up").play();
140 | MusicController::Get().GetSound("ghost").play();
141 | Camera::Get().Shake(1.75f);
142 |
143 | m_hit = true;
144 | m_grabbing = false;
145 | m_movable = false;
146 | m_torque = 0.925f;
147 |
148 | //m_Animations["takedamage"].SetFrame(0);
149 |
150 | m_velocity.y = -950.0f;
151 | int multi = entity->m_left ? 1 : -1;
152 | m_velocity.x = multi * 1200.0f;
153 |
154 | reinterpret_cast(i_drawable)->setScale(sf::Vector2f(2.0f * -multi, 2.0f));
155 | }
156 |
157 | void Player::ResolveCollision(Heart* entity) {
158 | sf::Vector2f MTV;
159 |
160 | if (GetCollider().CheckCollision(entity->GetCollider(), MTV) && m_healthBar.GetHealthState() != 3) {
161 | m_healthBar.Change(false);
162 | MusicController::Get().GetSound("pick_up").play();
163 | entity->_IsAlive = false;
164 | }
165 | }
166 |
167 | void Player::ResolveCollision(std::vector& walls) {
168 | sf::Vector2f MTV;
169 |
170 | m_grounded = false;
171 |
172 | auto body = reinterpret_cast(i_drawable);
173 |
174 | for (auto& o : walls) {
175 | if (!GetCollider().CheckCollision(o.GetCollider(), MTV))
176 | continue;
177 |
178 | if (MTV.y < 0.0f && m_velocity.y >= 0.0f) {
179 | m_grounded = true;
180 | m_velocity.y = 0.0f;
181 | Crouch();
182 | }
183 | else if (MTV.y > 0.0f && m_velocity.y < 0.0f) {
184 | m_velocity.y = 0.0f;
185 | }
186 |
187 | i_collider.position += MTV;
188 | body->setPosition(i_collider.position);
189 |
190 | if (MTV.x != 0.0f && m_velocity.y > 0.0f && sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && m_movable) {
191 | bool diffY = i_collider.position.y - i_collider.size.y / 2.0f > o.GetCollider().GetBody().position.y - o.GetCollider().GetBody().size.y;
192 |
193 | if (!diffY)
194 | return;
195 |
196 | m_grabbing = true;
197 |
198 | m_velocity.y = 0.0f;
199 | m_velocity.x = 0.0f;
200 |
201 | bool diffX = body->getPosition().x > o.GetCollider().GetBody().position.x + o.GetCollider().GetBody().size.x / 2.0f;
202 |
203 | const int mulit = (diffX) ? -1 : 1;
204 |
205 | body->setScale(sf::Vector2f(2.0f * mulit, 2.0f));
206 | i_collider.position.y += -(i_collider.position.y - i_collider.size.y / 2.0f - o.GetCollider().GetBody().position.y + o.GetCollider().GetBody().size.y / 2.0f);
207 | }
208 |
209 | MTV = sf::Vector2f();
210 | }
211 |
212 | if (m_velocity.y > 0.0f)
213 | m_wasGrounded = false;
214 | }
215 |
216 | bool Player::IsAlive() const {
217 | return m_alive;
218 | }
219 |
220 | void Player::UpdateTimer() {
221 | if (m_hit) {
222 | if (m_currentHitTake > 9) {
223 | m_currentHitTake = 0;
224 | m_hit = false;
225 | return;
226 | }
227 |
228 | unsigned alpha[2] =
229 | {
230 | 60,
231 | 255,
232 | };
233 |
234 | auto body = reinterpret_cast(i_drawable);
235 |
236 | sf::Color c = body->getColor();
237 |
238 | body->setColor(sf::Color(c.r, c.g, c.b, alpha[(!(m_currentHitTake % 2) ? 0 : 1)]));
239 |
240 | if (m_hitTimer.getElapsedTime().asSeconds() > 0.175f) {
241 | m_currentHitTake++;
242 | m_hitTimer.restart();
243 | }
244 | }
245 | }
246 |
247 | void Player::Animate() {
248 | if (!m_movable) {
249 | m_Animations["takedamage"].Update(i_dt);
250 | if (m_Animations["takedamage"].GetCurrentFrame() == m_Animations["takedamage"].GetFrameCount() - 1) {
251 | m_Animations["takedamage"].SetFrame(0);
252 | m_movable = true;
253 | m_torque = 0.85f;
254 | }
255 | return;
256 | }
257 |
258 | if(m_grabbing) {
259 | m_Animations["grab"].Update(i_dt);
260 | return;
261 | }
262 |
263 | if (m_crouching) {
264 | m_Animations["crouch"].Update(i_dt);
265 | return;
266 | }
267 |
268 | if (m_velocity.y == 0.0f) { // NOT JUMPING
269 | if (m_velocity.x < 0) {
270 | m_Animations["move"].Update(i_dt);
271 | }
272 | else if (m_velocity.x > 0) {
273 | m_Animations["move"].Update(i_dt);
274 | }
275 | else if (m_velocity.x == 0) {
276 | m_Animations["idle"].Update(i_dt);
277 | }
278 | }
279 | else {
280 | if (m_velocity.y < 0) {
281 | if (m_Animations["jump"].GetCurrentFrame() != m_Animations["jump"].GetFrameCount() - 1)
282 | m_Animations["jump"].Update(i_dt);
283 | }
284 | if (m_velocity.y > 0) {
285 | m_Animations["fall"].Update(i_dt);
286 | }
287 | }
288 | }
289 |
290 | void Player::KeepInBorders() {
291 | if (i_collider.position.x < 0.0f)
292 | i_collider.position.x = 0.0f;
293 | else if (i_collider.position.x > WINDOW_WIDTH)
294 | i_collider.position.x = WINDOW_WIDTH;
295 | }
296 |
297 | void Player::Crouch() {
298 | bool wasCrouching = m_crouching;
299 | // yeah i know
300 | m_crouching = sf::Keyboard::isKeyPressed(sf::Keyboard::S) && m_grounded && m_movable;
301 |
302 | if (m_crouching) {
303 | //float preY = i_collider.position.y;
304 |
305 | m_velocity.x = 0.0f;
306 | i_collider.size.y = 40.0f;
307 |
308 | if (!wasCrouching)
309 | i_collider.position.y += 20.0f;
310 |
311 | reinterpret_cast(i_drawable)->setOrigin(sf::Vector2f(m_playerSize.x / 2, m_playerSize.y / 1.135f));
312 | }
313 | else {
314 | i_collider.size.y = 80.0f;
315 | if (wasCrouching)
316 | i_collider.position.y -= 20.0f;
317 | }
318 |
319 | if (wasCrouching != m_crouching && m_crouching)
320 | MusicController::Get().GetSound("player_crouch").play();
321 | }
322 |
323 | void Player::Move() {
324 | if(!m_grabbing)
325 | m_velocity.y += m_gravity * i_fdt;
326 | m_velocity.x *= m_torque;
327 | i_collider.position += m_velocity * i_fdt;
328 |
329 | float vel = abs(m_velocity.x);
330 | m_velocity.x = (vel < 8.0f ? 0.0f : m_velocity.x);
331 |
332 | auto body = reinterpret_cast(i_drawable);
333 |
334 | body->setOrigin(sf::Vector2f(m_playerSize.x / 2, m_playerSize.y / 1.315f));
335 |
336 | if(m_crouching)
337 | body->setOrigin(sf::Vector2f(m_playerSize.x / 2, m_playerSize.y / 1.135f));
338 |
339 | body->setPosition((m_grabbing ? sf::Vector2f(i_collider.position.x + 5.0f * body->getScale().x / 2.0f, i_collider.position.y) : i_collider.position));
340 | }
341 |
342 | void Player::UpdateVelocity() {
343 | if (m_crouching || !m_movable)
344 | return;
345 |
346 | if (
347 | m_grounded &&
348 | sf::Keyboard::isKeyPressed(sf::Keyboard::W) &&
349 | KeyCheck::Key('W') ||
350 | m_grabbing &&
351 | sf::Keyboard::isKeyPressed(sf::Keyboard::W) &&
352 | KeyCheck::Key('W')
353 | )
354 | {
355 | m_grounded = false;
356 | m_grabbing = false;
357 | m_velocity.y = m_jumpVelocity;
358 | m_Animations["jump"].SetFrame(0);
359 |
360 | MusicController::Get().GetSound("player_jump").play();
361 | }
362 |
363 | if (m_grabbing && !sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
364 | m_grabbing = false;
365 |
366 | if (m_grabbing)
367 | return;
368 |
369 | if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
370 | m_velocity.x = -m_movementSpeed;
371 | reinterpret_cast(i_drawable)->setScale(sf::Vector2f(-2.0f, 2.0f));
372 | }
373 |
374 | if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
375 | m_velocity.x = m_movementSpeed;
376 | reinterpret_cast(i_drawable)->setScale(sf::Vector2f(2.0f, 2.0f));
377 | }
378 | }
379 |
380 | void Player::UpdateEmitters() {
381 | m_emitter->SetDirection(sf::Vector2f((m_velocity.x < 0.0f ? 1.0f : -1.0f), 0.0f));
382 |
383 | m_emitter->SetPosition(sf::Vector2f(i_collider.position.x, i_collider.position.y - 10.0f));
384 | if (m_velocity.x != 0.0f)
385 | m_emitter->AddParticles();
386 | m_emitter->Update(i_dt);
387 |
388 | m_emitter->SetBirthColor(Extern::particle_birth_color);
389 | m_emitter->SetDeathColor(Extern::particle_death_color);
390 |
391 | m_fallEmitter->SetPosition(sf::Vector2f(i_collider.position.x - 10.0f, i_collider.position.y + 32.0f));
392 | if (!m_wasGrounded && m_grounded) {
393 | m_fallEmitter->AddParticles();
394 | m_wasGrounded = true;
395 | }
396 | m_fallEmitter->Update(i_dt);
397 | }
398 |
399 | void Player::InitEmitters() {
400 | {
401 | m_emitter = new ParticleEmitter(Extern::particle_birth_color, Extern::particle_death_color, 15);
402 | m_emitter->SetLifeTimeRange(0.5f, 2.0f);
403 | m_emitter->SetSpeed(1.5f);
404 | }
405 |
406 | {
407 | m_fallEmitter = new ParticleEmitter(sf::Color(79, 46, 26), sf::Color(20, 48, 18), 13);
408 | m_fallEmitter->SetLifeTimeRange(0.5f, 1.5f);
409 | m_fallEmitter->SetDirection(sf::Vector2f(0, -1));
410 | m_fallEmitter->SetSpread(4.59f);
411 | m_fallEmitter->SetSpeed(1.1f);
412 | m_fallEmitter->SetParticleMax(35);
413 | }
414 | }
415 |
416 | void Player::InitAnimations() {
417 | auto sprite = reinterpret_cast(i_drawable);
418 |
419 | m_Animations["move"]. Create( 8, 0, 0.08f, m_playerSize, *sprite, 3);
420 | m_Animations["idle"]. Create( 7, 0, 0.08f, m_playerSize, *sprite, 1);
421 | m_Animations["jump"]. Create( 2, 0, 0.125f, m_playerSize, *sprite, 4);
422 | m_Animations["fall"]. Create( 1, 0, 0.1f, m_playerSize, *sprite, 6);
423 | m_Animations["crouch"]. Create( 6, 0, 0.06f, m_playerSize, *sprite, 9);
424 | m_Animations["grab"]. Create( 1, 0, 0.1f, m_playerSize, *sprite, 15);
425 | m_Animations["takedamage"]. Create( 7, 0, 0.08f, m_playerSize, *sprite, 17);
426 | }
427 |
428 | void Player::InitBody() {
429 | i_drawable = new sf::Sprite(*i_texture);
430 |
431 | auto sprite = reinterpret_cast(i_drawable);
432 |
433 | sprite->setOrigin(sf::Vector2f(m_playerSize.x / 2, m_playerSize.y / 1.315f));
434 | sprite->setScale(sf::Vector2f(2.f, 2.f));
435 | }
436 |
437 | void Player::InitCollider() {
438 | const sf::Vector2f size = sf::Vector2f(40.0f, 80.0f);
439 |
440 | i_collider.position = sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT) / 2.0f;
441 | i_collider.size = size;
442 | }
443 |
444 | void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const {
445 | target.draw(*m_emitter, i_shader);
446 | target.draw(*m_fallEmitter, i_shader);
447 | target.draw(*i_drawable, i_shader);
448 | target.draw(m_healthBar);
449 | /*sf::RectangleShape rs;
450 | rs.setSize(i_collider.size);
451 | rs.setOrigin(i_collider.size / 2.0f);
452 | rs.setPosition(i_collider.position);
453 | target.draw(rs, i_shader);*/
454 | }
455 |
--------------------------------------------------------------------------------
/The Platformer/Entities/Player.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Entity.hpp"
4 |
5 | #include "Timer.hpp"
6 |
7 | #include "Animations/Animator.hpp"
8 |
9 | #include "../Objects/Wall.hpp"
10 | #include "Heart.hpp"
11 | #include "Ghost.hpp"
12 | #include "../Effects/Particle Emitter/Particle Emitter.hpp"
13 |
14 | #include "../UI/Health Bar.hpp"
15 |
16 | class Player : public Entity {
17 | public:
18 | Player(const float& dt, const float& fdt, sf::Texture* texture);
19 | ~Player();
20 |
21 | virtual void FixedUpdate();
22 | virtual void Update();
23 |
24 | void ResolveCollision(Entity* entity);
25 | void ResolveCollision(Ghost* entity, std::vector& ghosts);
26 | void ResolveCollision(Heart* entity);
27 | void ResolveCollision(std::vector& walls);
28 |
29 | bool IsAlive() const;
30 | private:
31 | sf::Vector2f m_velocity;
32 |
33 | bool m_alive = true;
34 |
35 | const float m_movementSpeed = 420.0f;
36 | float m_torque = 0.85f;
37 | const float m_gravity = 4605.0f;
38 | const float m_jumpVelocity = -1200.0f;
39 |
40 | bool m_grounded = true;
41 | bool m_crouching = false;
42 | bool m_grabbing = false;
43 |
44 | bool m_hit = true;
45 | bool m_movable = true;
46 |
47 | bool m_wasGrounded = false;
48 |
49 | unsigned m_currentHitTake = 10;
50 |
51 | const sf::Vector2i m_playerSize = sf::Vector2i(96, 84);
52 | std::unordered_map m_Animations;
53 |
54 | ParticleEmitter* m_emitter;
55 | ParticleEmitter* m_fallEmitter;
56 |
57 | sf::Clock m_hitTimer;
58 |
59 | // amogus
60 | HealthBar m_healthBar;
61 |
62 | sf::SoundBuffer m_ghostBuffer;
63 | sf::Sound m_ghost;
64 |
65 | //Timer m_hitTimer; we don't talk about it
66 |
67 | void UpdateTimer();
68 |
69 | void Animate();
70 |
71 | void KeepInBorders();
72 |
73 | void Crouch();
74 |
75 | void Move();
76 | void UpdateVelocity();
77 |
78 | void UpdateEmitters();
79 | void InitEmitters();
80 |
81 | void InitAnimations();
82 | void InitBody();
83 | void InitCollider();
84 |
85 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
86 | };
--------------------------------------------------------------------------------
/The Platformer/Objects/Wall.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Wall.hpp"
3 |
4 | Wall::Wall(sf::Vector2f position, sf::Vector2f size) {
5 | InitCollider(position, size);
6 | }
7 |
8 | Wall::~Wall() {
9 |
10 | }
11 |
12 | Collision Wall::GetCollider() {
13 | return m_collider;
14 | }
15 |
16 | void Wall::InitCollider(const sf::Vector2f& position, const sf::Vector2f& size) {
17 | m_collider.size = size;
18 | m_collider.position = position;
19 | }
20 |
--------------------------------------------------------------------------------
/The Platformer/Objects/Wall.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Collision/Collision.hpp"
4 |
5 | //TODO: REMOVE DRAWABLE
6 | class Wall{
7 | public:
8 | Wall(sf::Vector2f position, sf::Vector2f size);
9 | ~Wall();
10 |
11 | Collision GetCollider();
12 |
13 | private:
14 | Collider m_collider;
15 |
16 | void InitCollider(const sf::Vector2f& position, const sf::Vector2f& size);
17 | };
--------------------------------------------------------------------------------
/The Platformer/Precompiled Headers/stdafx.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
--------------------------------------------------------------------------------
/The Platformer/Precompiled Headers/stdafx.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | /*
4 | - ~ Snapi ~
5 | - Template created: 01/10/2021
6 | - Last update: 01/10/2021
7 | */
8 |
9 | /////STANDARD/////
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | //#include
17 | #include
18 | #include
19 | /////STANDARD/////
20 |
21 | ///////SFML///////
22 | #include
23 | #include
24 | ///////SFML///////
25 |
26 | constexpr int WINDOW_WIDTH = 1600;
27 | constexpr int WINDOW_HEIGHT = 900;
28 |
29 | constexpr float PHYSICS_STEP = 0.01f;
30 |
31 | #ifdef NDEBUG
32 | #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") // <- Dumps the console window
33 | #define LOG(...)
34 | #else
35 | #define LOG(...) DEBUG_MESSAGE_LOG(__VA_ARGS__)
36 | #endif
37 |
38 | /* Print for debug messages */
39 | template
40 | constexpr static void DEBUG_MESSAGE_LOG(Arg&& arg, Args&&... args)
41 | {
42 | std::cerr << std::forward(arg);
43 | ((std::cerr << std::forward(args)), ...);
44 | }
45 |
46 | /* This here makes sounds and music work */
47 | FILE _iob[] = { *stdin, *stdout, *stderr };
48 | extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
--------------------------------------------------------------------------------
/The Platformer/Public Variables/Extern.cpp:
--------------------------------------------------------------------------------
1 | #include "Extern.hpp"
2 |
3 | int Extern::music_volume = 80;
4 | int Extern::sound_volume = 80;
5 |
6 | sf::Color Extern::particle_birth_color = sf::Color(255, 255, 0);
7 | sf::Color Extern::particle_death_color = sf::Color(255, 0, 255);
8 |
9 | float Extern::best_time = 0.0f;
--------------------------------------------------------------------------------
/The Platformer/Public Variables/Extern.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | namespace Extern {
5 | extern int music_volume;
6 | extern int sound_volume;
7 |
8 | extern sf::Color particle_birth_color;
9 | extern sf::Color particle_death_color;
10 |
11 | extern float best_time;
12 | }
--------------------------------------------------------------------------------
/The Platformer/States/Machine/State Machine.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "State Machine.hpp"
3 |
4 | #include "../Effects/Transition/Transition.hpp"
5 |
6 | StateMachine::StateMachine
7 | (
8 | sf::RenderWindow& window,
9 | const float& dt,
10 | const float& fdt
11 | )
12 | :
13 |
14 | m_window(window),
15 | m_dt(dt),
16 | m_fdt(fdt)
17 | {
18 | m_frame.create(WINDOW_WIDTH, WINDOW_HEIGHT);
19 | }
20 |
21 | StateMachine::~StateMachine() {
22 | ClearStates();
23 | }
24 |
25 | void StateMachine::AddStateAtTop(State* state) {
26 | m_states.push(state);
27 | }
28 |
29 | void StateMachine::AddStateAtBottom(State* state) {
30 | if (m_states.empty()) {
31 | m_states.push(state);
32 | }
33 | else {
34 | State* temp = m_states.top();
35 | m_states.pop();
36 | AddStateAtBottom(state);
37 | m_states.push(temp);
38 | }
39 | }
40 |
41 | void StateMachine::FixedUpdate() {
42 | if (!m_states.empty())
43 | m_states.top()->FixedUpdate();
44 | }
45 |
46 | void StateMachine::Update() {
47 | if (!m_states.empty()) {
48 | m_states.top()->Update();
49 | if (!m_states.top()->IsRunning()) {
50 | delete m_states.top();
51 | m_states.pop();
52 | }
53 | }
54 | else {
55 | m_window.close();
56 | }
57 | }
58 |
59 | void StateMachine::Render() {
60 | m_frame.clear();
61 |
62 | if (!m_states.empty())
63 | m_states.top()->Render(m_frame);
64 | //m_frame.draw(sf::RectangleShape(sf::Vector2f(1600, 900)));
65 | m_frame.display();
66 |
67 | m_frameSprite.setTexture(m_frame.getTexture());
68 |
69 | // two separate draw calls still sholudn't be this expensive because of rendertexture
70 | m_window.draw(m_frameSprite, &Transition::Get().GetShader());
71 | //m_window.draw(m_frameSprite, &ShaderLibrary::GetShader("vignette"));
72 | }
73 |
74 | void StateMachine::ClearAndPush(State* state) {
75 | ClearStates();
76 | m_states.push(state);
77 | }
78 |
79 | void StateMachine::ClearStates() {
80 | while (!m_states.empty()) {
81 | delete m_states.top();
82 | m_states.pop();
83 | }
84 | }
85 |
86 | State::State
87 | (
88 | StateMachine& machine
89 | )
90 | :
91 |
92 | i_machine(machine),
93 | i_window(machine.m_window),
94 | i_dt(machine.m_dt),
95 | i_fdt(machine.m_fdt)
96 | {
97 |
98 | }
99 |
100 | State::~State() {
101 |
102 | }
103 |
104 | const bool State::IsRunning() const {
105 | return i_isRunning;
106 | }
107 |
108 | sf::Vector2f State::GetMousePos() const {
109 | return i_window.mapPixelToCoords(sf::Mouse::getPosition(i_window));
110 | }
111 |
--------------------------------------------------------------------------------
/The Platformer/States/Machine/State Machine.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Asset Manager.hpp"
4 |
5 | #include "../Effects/Music controller/Music Controller.hpp"
6 |
7 | class State;
8 |
9 | class StateMachine {
10 | public:
11 | StateMachine(sf::RenderWindow& window, const float& dt, const float& fdt);
12 | ~StateMachine();
13 |
14 | void AddStateAtTop(State* state);
15 | void AddStateAtBottom(State* state);
16 |
17 | void FixedUpdate();
18 | void Update();
19 | void Render();
20 |
21 | void ClearAndPush(State* state);
22 |
23 | sf::RenderWindow& m_window;
24 | const float& m_fdt;
25 | const float& m_dt;
26 |
27 | private:
28 | sf::Sprite m_frameSprite;
29 | sf::RenderTexture m_frame;
30 | std::stack m_states;
31 |
32 | void ClearStates();
33 | };
34 |
35 | class State {
36 | public:
37 | State(StateMachine& machine);
38 | virtual ~State();
39 |
40 | virtual void FixedUpdate() = 0;
41 | virtual void Update() = 0;
42 | virtual void Render(sf::RenderTarget& target) = 0;
43 |
44 | const bool IsRunning() const;
45 |
46 | // Accessors
47 | sf::Vector2f GetMousePos() const;
48 |
49 | protected:
50 | StateMachine& i_machine;
51 |
52 | sf::RenderWindow& i_window;
53 | const float& i_fdt;
54 | const float& i_dt;
55 | bool i_isRunning = true;
56 | };
--------------------------------------------------------------------------------
/The Platformer/States/Save.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Save.hpp"
3 |
4 | void SaveFile::Load(const std::string path) {
5 | s_file.open(path, std::ios::in);
6 |
7 | if (!s_file.good()) {
8 | s_file.close();
9 | Save(path);
10 | return;
11 | }
12 |
13 | std::string lines[5];
14 |
15 | for (int i = 0; i < 5; i++)
16 | std::getline(s_file, lines[i]);
17 |
18 | Extern::music_volume = atoi(lines[0].c_str());
19 | Extern::sound_volume = atoi(lines[1].c_str());
20 |
21 | sf::Color colors[2];
22 |
23 | for (int i = 2; i < 4; i++) {
24 | int color[3] = {0};
25 | int j = 0;
26 |
27 | std::string str;
28 | for (char& key : lines[i]) {
29 | if (key != ' ') {
30 | str += key;
31 | }
32 | else {
33 | color[j] = atoi(str.c_str());
34 | j++;
35 | str.clear();
36 | }
37 | }
38 |
39 | colors[i - 2] = sf::Color(color[0], color[1], color[2], 255);
40 | }
41 |
42 | Extern::particle_birth_color = colors[0];
43 | Extern::particle_death_color = colors[1];
44 |
45 | Extern::best_time = atof(lines[4].c_str());
46 |
47 | s_file.close();
48 | }
49 |
50 | void SaveFile::Save(const std::string path) {
51 | s_file.open(path, std::ios::out);
52 |
53 | s_file << Extern::music_volume << '\n';
54 | s_file << Extern::sound_volume << '\n';
55 | s_file << (int)Extern::particle_birth_color.r << ' ' << (int)Extern::particle_birth_color.g << ' ' << (int)Extern::particle_birth_color.b << ' ' << '\n';
56 | s_file << (int)Extern::particle_death_color.r << ' ' << (int)Extern::particle_death_color.g << ' ' << (int)Extern::particle_death_color.b << ' ' << '\n';
57 | s_file << Extern::best_time << '\n';
58 |
59 | s_file.close();
60 | }
61 |
62 | //void SaveFile::CreateFile(const std::string& path) {
63 | //
64 | //}
65 |
66 | std::fstream SaveFile::s_file;
--------------------------------------------------------------------------------
/The Platformer/States/Save.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "../Public Variables/Extern.hpp"
4 |
5 | class SaveFile {
6 | public:
7 | static void Load(const std::string path);
8 | static void Save(const std::string path);
9 | private:
10 | //static void CreateFile(const std::string& path);
11 |
12 | static std::fstream s_file;
13 | };
--------------------------------------------------------------------------------
/The Platformer/States/State/Game/Game.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Game.hpp"
3 |
4 | #include "../States/State/Pause/Pause.hpp"
5 | #include "../States/State/Menu/Menu.hpp"
6 | #include "../Effects/Camera/Camera.hpp"
7 | #include "Key Check.hpp"
8 |
9 | #include "Random.hpp"
10 |
11 | Game::Game(StateMachine& machine)
12 | : State(machine)
13 | {
14 | InitAssets();
15 | InitEntities();
16 | InitWalls();
17 | InitSprites();
18 | InitLights();
19 | InitCountdown();
20 | InitTexts();
21 | InitTimers();
22 |
23 | MusicController::Get().GetMusic("main_track").play();
24 | MusicController::Get().GetMusic("main_track").setLoop(true);
25 | }
26 |
27 | Game::~Game() {
28 | for (auto& f : m_fireballs)
29 | delete f;
30 |
31 | delete m_heart;
32 |
33 | delete m_countdown;
34 | delete m_player;
35 | }
36 |
37 | void Game::FixedUpdate() {
38 | if (m_player->IsAlive())
39 | FixedUpdateEntities();
40 | }
41 |
42 | void Game::Update() {
43 | // AVENTUSSSSS SUSSSSS AMOGUSSSSSSSSS
44 | if (m_player->IsAlive()) {
45 | UpdateEntities();
46 | m_bestTime = m_timeClock.getElapsedTime().asSeconds();
47 | }
48 | else {
49 | Transition::Get().SetFunction([&]() {
50 | if (m_bestTime > Extern::best_time)
51 | Extern::best_time = m_bestTime;
52 | i_machine.ClearAndPush(new Menu(i_machine));
53 | MusicController::Get().GetMusic("main_track").stop();
54 | Transition::Get().Start(Mode::Unveil);
55 | });
56 | Transition::Get().Start(Mode::Veil);
57 | }
58 |
59 | UpdateTexts();
60 | UpdateCountdown();
61 |
62 | if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) && KeyCheck::Key('/')) { // '/' <- is escape keyy XDDDD
63 | i_machine.AddStateAtTop(new Pause(i_machine));
64 | MusicController::Get().GetMusic("main_track").setPitch(0.79f);
65 | }
66 | }
67 |
68 | void Game::Render(sf::RenderTarget& target) {
69 | target.draw(m_Sprites["background"]);
70 |
71 | target.draw(*m_player);
72 |
73 | auto& fog = ShaderLibrary::Get().GetShader("fog");
74 | fog.setUniform("u_time", m_clock.getElapsedTime().asSeconds());
75 |
76 | target.draw(m_Sprites["foreground"]);
77 |
78 | auto& light = ShaderLibrary::Get().GetShader("light");
79 | light.setUniform("u_time", m_clock.getElapsedTime().asSeconds());
80 |
81 | light.setUniform("color", sf::Glsl::Vec4(0.75, 0.42, 0.28, 0.72));
82 | for (const auto& f : m_fireballs)
83 | target.draw(*f);
84 |
85 | target.draw(*m_countdown);
86 |
87 | if(m_countdown->CurrentFrame() >= 4) //god
88 | for (const auto& t : m_Texts)
89 | target.draw(t.second);
90 |
91 | for (const auto& g : m_ghosts)
92 | target.draw(*g);
93 |
94 | if(m_heart)
95 | target.draw(*m_heart);
96 |
97 | target.draw(m_fog, &fog);
98 |
99 | light.setUniform("color", sf::Glsl::Vec4(0.65, 0.50, 0.28, 0.8));
100 | for(const auto& l : m_lights)
101 | target.draw(l);
102 |
103 | }
104 |
105 | void Game::SpawnHeart() {
106 | if (m_heartSpawnClock.getElapsedTime().asSeconds() > 27.5f)
107 | m_heart = new Heart(&m_TextureManager.Get("heart"), i_dt, i_fdt);
108 | }
109 |
110 | void Game::FixedUpdateEntities() {
111 | m_player->FixedUpdate();
112 | if (m_heart)
113 | m_heart->FixedUpdate();
114 |
115 | for (auto& g : m_ghosts)
116 | g->FixedUpdate();
117 |
118 | for (auto& f : m_fireballs)
119 | f->FixedUpdate();
120 | }
121 |
122 | void Game::UpdateEntities() {
123 | m_player->ResolveCollision(m_walls);
124 | if (m_heart)
125 | m_player->ResolveCollision(m_heart);
126 |
127 | m_player->Update();
128 |
129 | if (!m_heart)
130 | SpawnHeart();
131 |
132 | if (m_heart && !m_heart->IsAlive()) {
133 | delete m_heart;
134 | m_heart = nullptr;
135 | }
136 | else if (m_heart) {
137 | m_heart->Update();
138 | m_heart->ResolveCollision(m_walls);
139 |
140 | m_heartSpawnClock.restart();
141 | }
142 |
143 | // Fireballs
144 |
145 | for (int i = 0; i < m_fireballs.size(); i++) {
146 | auto& fireball = m_fireballs[i];
147 |
148 | if (!fireball->Alive()) {
149 | delete fireball;
150 | m_fireballs.erase(m_fireballs.begin() + i);
151 |
152 | continue;
153 | }
154 |
155 | m_player->ResolveCollision(fireball);
156 |
157 | fireball->Update();
158 | }
159 |
160 | // Ghosts
161 | for (int i = 0; i < m_ghosts.size(); i++) {
162 | auto& ghost = m_ghosts[i];
163 |
164 | if (!ghost->m_isAlive) {
165 | delete ghost;
166 | m_ghosts.erase(m_ghosts.begin() + i);
167 |
168 | continue;
169 | }
170 |
171 | m_player->ResolveCollision(ghost, m_ghosts);
172 |
173 | ghost->Update(m_player->GetCollider().GetBody());
174 | }
175 |
176 | if (m_countdown->CurrentFrame() >= 4)
177 | UpdateTimers();
178 | }
179 |
180 | void Game::InitEntities() {
181 | //PLAYER//
182 | {
183 | m_player = new Player(i_dt, i_fdt, &m_TextureManager.Get("player"));
184 | }
185 |
186 | //FOG//
187 | {
188 | m_fog.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
189 | }
190 | }
191 |
192 | void Game::UpdateTimers() {
193 | //LOG(m_enemySpawnTimer.GetUpdateTime(), '\n');
194 | m_enemySpawnTimer.Update(i_dt);
195 | m_ghostSpawnTimer.Update(i_dt);
196 | m_gameSpeedTimer.Update(i_dt);
197 | }
198 |
199 | void Game::InitTimers() {
200 | m_enemySpawnTimer.SetFunction(1.0f, [&]() {
201 | if (m_fireballs.size() > 8)
202 | return;
203 |
204 | const float velocity = 450.0f * Random::RandFloat(1.01f, 1.82f);
205 |
206 | m_fireballs.push_back
207 | (
208 | new Fireball
209 | (
210 | i_dt, i_fdt, &m_TextureManager.Get("fireball"),
211 | &m_TextureManager.Get("blow_up"),
212 | velocity,
213 | Random::RandInt(0, 1)
214 | )
215 | );
216 |
217 | });
218 |
219 | m_gameSpeedTimer.SetFunction(5.5f, [&]() {
220 | const float sub = Random::RandFloat(0.085f, 0.125f);
221 | const float uTime = m_enemySpawnTimer.GetUpdateTime() - sub;
222 |
223 | m_enemySpawnTimer.SetUpdateTime
224 | (
225 | uTime < 0.285f ? 0.285f : uTime
226 | );
227 |
228 | m_ghostSpawnTimer.SetUpdateTime(m_ghostSpawnTimer.GetUpdateTime() - sub < 7.185f ? 7.185f : m_ghostSpawnTimer.GetUpdateTime() - sub);
229 | });
230 |
231 | m_ghostSpawnTimer.SetFunction(8.5f, [&]() {
232 | if (m_ghosts.size() > 2)
233 | return;
234 |
235 | m_ghosts.push_back(new Ghost(&m_TextureManager.Get("ghost"), i_dt, i_fdt));
236 | });
237 | }
238 |
239 | void Game::UpdateCountdown() {
240 | if (m_countdown->CurrentFrame() < 4) {
241 | m_countdown->Update();
242 | m_timeClock.restart();
243 | }
244 | }
245 |
246 | void Game::InitCountdown() {
247 | m_countdown = new Countdown(&m_FontManager.Get("default"));
248 | }
249 |
250 | void Game::UpdateTexts() {
251 | int n = (int)m_timeClock.getElapsedTime().asSeconds();
252 | int count = 0;
253 | while (n != 0) { // AMAOGUSUGUASGF
254 | n = n / 10;
255 | count++;
256 | }
257 |
258 | std::stringstream ss;
259 | ss.precision(count + 2);
260 | ss << m_timeClock.getElapsedTime().asSeconds();
261 |
262 | m_Texts["time"].setString(ss.str());
263 | if(!(count % 10) && count != 0)
264 | m_Texts["time"].reposition();
265 | }
266 |
267 | void Game::InitTexts() {
268 | m_Texts["time"].setString("0.00s");
269 | m_Texts["time"].setCharacterSize(90);
270 |
271 | for (auto& t : m_Texts)
272 | t.second.setFont(m_FontManager.Get("default"));
273 |
274 | m_Texts["time"].setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, 65.0f));
275 | }
276 |
277 | void Game::InitLights() {
278 | m_lights.push_back(Light(sf::Vector2f(460.0f, 490.0f), 275.0f));
279 | m_lights.push_back(Light(sf::Vector2f(210.0f, 200.0f), 275.0f));
280 | m_lights.push_back(Light(sf::Vector2f(1125.0f, 395.0f), 275.0f));
281 | m_lights.push_back(Light(sf::Vector2f(1350.0f, 780.0f), 275.0f));
282 | }
283 |
284 | void Game::InitSprites() {
285 | //FOREGROUND//
286 | {
287 | auto& s = m_Sprites["foreground"];
288 | s.setTexture(m_TextureManager.Get("foreground"));
289 | s.setScale(sf::Vector2f(2.0f, 2.0f));
290 | s.setPosition(sf::Vector2f(0.0f, 4.0f));
291 | }
292 |
293 | //BACKGROUND//
294 | {
295 | auto& s = m_Sprites["background"];
296 | s.setTexture(m_TextureManager.Get("background"));
297 | s.setScale(sf::Vector2f(6.0f, 6.0f));
298 | s.setPosition(sf::Vector2f(0.0f, 4.0f));
299 | }
300 | }
301 |
302 | void Game::InitWalls() {
303 | m_walls.push_back(Wall(sf::Vector2f(WINDOW_WIDTH / 2.0f, 855.0f), sf::Vector2f(WINDOW_WIDTH, 100.0f)));
304 | m_walls.push_back(Wall(sf::Vector2f(800.0f, 772.0f), sf::Vector2f(64.0f, 64.0f)));
305 | m_walls.push_back(Wall(sf::Vector2f(640.0f, 660.0f), sf::Vector2f(128.0f, 32.0f)));
306 | m_walls.push_back(Wall(sf::Vector2f(1072.0f, 660.0f), sf::Vector2f(96.0f, 32.0f)));
307 | m_walls.push_back(Wall(sf::Vector2f(192.0f, 596.0f), sf::Vector2f(192.0f, 32.0f)));
308 | m_walls.push_back(Wall(sf::Vector2f(435.0f, 530.0f), sf::Vector2f(160.0f, 32.0f)));
309 | m_walls.push_back(Wall(sf::Vector2f(880.0f, 530.0f), sf::Vector2f(224.0f, 32.0f)));
310 | m_walls.push_back(Wall(sf::Vector2f(658.0f, 436.0f), sf::Vector2f(96.0f, 32.0f)));
311 | m_walls.push_back(Wall(sf::Vector2f(80.0f, 466.0f), sf::Vector2f(96.0f, 32.0f)));
312 | m_walls.push_back(Wall(sf::Vector2f(1182.0f, 436.0f), sf::Vector2f(192.0f, 32.0f)));
313 | m_walls.push_back(Wall(sf::Vector2f(398.0f, 340.0f), sf::Vector2f(224.0f, 32.0f)));
314 | m_walls.push_back(Wall(sf::Vector2f(815.0f, 340.0f), sf::Vector2f(96.0f, 32.0f)));
315 | m_walls.push_back(Wall(sf::Vector2f(1377.0f, 340.0f), sf::Vector2f(128.0f, 32.0f)));
316 | m_walls.push_back(Wall(sf::Vector2f(176.0f, 244.0f), sf::Vector2f(160.0f, 32.0f)));
317 | m_walls.push_back(Wall(sf::Vector2f(960.0f, 244.0f), sf::Vector2f(192.0f, 32.0f)));
318 | m_walls.push_back(Wall(sf::Vector2f(1230.0f, 180.0f), sf::Vector2f(160.0f, 32.0f)));
319 | m_walls.push_back(Wall(sf::Vector2f(1490.0f, 116.0f), sf::Vector2f(160.0f, 32.0f)));
320 | }
321 |
322 | void Game::InitAssets() {
323 | //TEXTURES//
324 | {
325 | m_TextureManager.Load("player", "res/textures/player.png");
326 | m_TextureManager.Load("background", "res/textures/background.png");
327 | m_TextureManager.Load("foreground", "res/textures/map.png");
328 |
329 | m_TextureManager.Load("fireball", "res/textures/fireball.png");
330 | m_TextureManager.Load("blow_up", "res/textures/explo.png");
331 |
332 | m_TextureManager.Load("heart", "res/textures/heart.png");
333 |
334 | m_TextureManager.Load("ghost", "res/textures/ghost.png");
335 | }
336 |
337 | //FONTS//
338 | {
339 | m_FontManager.Load("default", "res/fonts/upheavtt.ttf");
340 | }
341 | }
342 |
--------------------------------------------------------------------------------
/The Platformer/States/State/Game/Game.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../States/Machine/State Machine.hpp"
3 | #include "Shader Library.hpp"
4 |
5 | #include "Timer.hpp"
6 | #include "Text.hpp"
7 |
8 | #include "../Entities/Player.hpp"
9 | #include "../Entities/Heart.hpp"
10 | #include "../Entities/Fireball.hpp"
11 | #include "../Entities/Ghost.hpp"
12 | #include "../Objects/Wall.hpp"
13 |
14 | #include "../Effects/Light/Light.hpp"
15 |
16 | #include "../UI/Countdown.hpp"
17 |
18 | class Game : public State {
19 | public:
20 | Game(StateMachine& machine);
21 | ~Game();
22 |
23 | virtual void FixedUpdate();
24 | virtual void Update();
25 | virtual void Render(sf::RenderTarget& target);
26 |
27 | private:
28 | Player* m_player;
29 | //std::vector m_hearts; // we need to store it in vector because of my brain damage
30 | Heart* m_heart = nullptr;
31 | std::vector m_ghosts;
32 |
33 | sf::RectangleShape m_fog;
34 | sf::Clock m_clock;
35 |
36 | std::unordered_map m_Sprites;
37 | std::unordered_map m_Texts;
38 |
39 | AssetManager m_TextureManager;
40 | AssetManager m_FontManager;
41 |
42 | std::vector m_walls;
43 | std::vector m_lights;
44 |
45 | std::vector m_fireballs;
46 |
47 | sf::Clock m_spawnClock;
48 | sf::Clock m_timeClock;
49 | sf::Clock m_heartSpawnClock;
50 | sf::Clock m_ghostSpawnClock;
51 |
52 | Countdown* m_countdown;
53 |
54 | Timer m_enemySpawnTimer;
55 | Timer m_ghostSpawnTimer;
56 | Timer m_gameSpeedTimer;
57 |
58 | float m_bestTime = 0.0f;
59 |
60 | void SpawnHeart();
61 |
62 | void FixedUpdateEntities();
63 | void UpdateEntities();
64 | void InitEntities();
65 |
66 | void UpdateTimers();
67 | void InitTimers();
68 |
69 | void UpdateCountdown();
70 | void InitCountdown();
71 |
72 | void UpdateTexts();
73 | void InitTexts();
74 |
75 | void InitLights();
76 |
77 | void InitSprites();
78 |
79 | void InitWalls();
80 |
81 | void InitAssets();
82 | };
--------------------------------------------------------------------------------
/The Platformer/States/State/Menu/Menu.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Menu.hpp"
3 |
4 | Menu::Menu(StateMachine& machine)
5 | : State(machine)
6 | {
7 | InitAssets();
8 | InitSprites();
9 | InitTexts();
10 | InitButtons();
11 | InitTimer();
12 | InitBorder();
13 |
14 | MusicController::Get().GetMusic("menu").play();
15 | MusicController::Get().GetMusic("menu").setLoop(true);
16 | }
17 |
18 | Menu::~Menu() {
19 |
20 | }
21 |
22 | void Menu::FixedUpdate() {
23 |
24 | }
25 |
26 | void Menu::Update() {
27 | UpdateButtons();
28 | AnimateTexts();
29 | }
30 |
31 | void Menu::Render(sf::RenderTarget& target) {
32 | // Sprites drawing
33 | for (const auto& s : m_Sprites)
34 | target.draw(s.second);
35 |
36 | target.draw(m_border);
37 |
38 | // Text drawing
39 | for (const auto& t : m_Texts)
40 | target.draw(t.second);
41 |
42 | // Button drawing
43 | for (const auto& b : m_Buttons)
44 | target.draw(b.second);
45 | }
46 |
47 | void Menu::InitBorder() {
48 | m_border.setSize(m_Texts["best_time"].getSize() + sf::Vector2f(25.0f, 15.0f));
49 | m_border.setOrigin((m_Texts["best_time"].getSize() + sf::Vector2f(25.0f, 15.0f)) / 2.0f);
50 | m_border.setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, 325.0f));
51 | m_border.setFillColor(sf::Color(224, 165, 0, 70));
52 | m_border.setOutlineColor(sf::Color(224, 165, 0));
53 | m_border.setOutlineThickness(4);
54 | }
55 |
56 | void Menu::AnimateTexts() {
57 | m_textAnimTimer.Update(i_dt);
58 | }
59 |
60 | void Menu::InitTimer() {
61 | m_textAnimTimer.SetFunction(0.20f, [&]() {
62 | constexpr float pos[10] =
63 | {
64 | 100.0f,
65 | 110.0f,
66 | 120.0f,
67 | 130.0f,
68 | 140.0f,
69 | 130.0f,
70 | 120.0f,
71 | 110.0f,
72 | 100.0f,
73 | 90.0f,
74 | };
75 |
76 | m_Texts["title"].setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, pos[m_iterator]));
77 |
78 | m_iterator++;
79 | if (m_iterator > 9)
80 | m_iterator = 0;
81 | });
82 | }
83 |
84 | void Menu::UpdateButtons() {
85 | for (auto& b : m_Buttons)
86 | b.second.Update(GetMousePos());
87 | }
88 |
89 | void Menu::InitButtons() {
90 | std::initializer_list> init =
91 | {
92 | { "start", Button("START", sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT) / 2.0f, m_FontManager.Get("default")) },
93 | { "settings", Button("SETTINGS", sf::Vector2f(WINDOW_WIDTH / 2.0f, 550 ), m_FontManager.Get("default")) },
94 | { "exit", Button("EXIT", sf::Vector2f(WINDOW_WIDTH / 2.0f, 650 ), m_FontManager.Get("default")) },
95 | };
96 |
97 | m_Buttons = init;
98 |
99 | auto& transition = Transition::Get();
100 |
101 | m_Buttons["start"].SetFunction([&]() {
102 | transition.SetFunction([&]() {
103 | i_isRunning = false;
104 | i_machine.AddStateAtBottom(new Game(i_machine));
105 | MusicController::Get().GetMusic("menu").stop();
106 | transition.Start(Mode::Unveil);
107 | });
108 |
109 | transition.Start(Mode::Veil);
110 | });
111 |
112 | m_Buttons["settings"].SetFunction([&]() {
113 | transition.SetFunction([&]() {
114 | i_machine.AddStateAtTop(new Settings(i_machine));
115 | transition.Start(Mode::Unveil);
116 | });
117 |
118 | transition.Start(Mode::Veil);
119 | });
120 |
121 | m_Buttons["exit"].SetFunction([&]() {
122 | transition.SetFunction([&]() { i_isRunning = false; });
123 | transition.Start(Mode::Veil);
124 | });
125 | }
126 |
127 | void Menu::InitSprites() {
128 | {
129 | auto& s = m_Sprites["background"];
130 | s.setTexture(m_TextureManager.Get("background"));
131 | }
132 | }
133 |
134 | void Menu::InitTexts() {
135 | // TITLE
136 | {
137 | auto& t = m_Texts["title"];
138 | t.setString("DEATHJUMP!");
139 | t.setCharacterSize(200);
140 | }
141 |
142 | {
143 | int n = (int)Extern::best_time;
144 | int count = 0;
145 | while (n != 0) { // AMAOGUSUGUASGF
146 | n = n / 10;
147 | count++;
148 | }
149 |
150 | std::stringstream ss;
151 | ss.precision(count + 2);
152 | ss << Extern::best_time;
153 | //ss << "s";
154 |
155 | auto& t = m_Texts["best_time"];
156 | t.setString("BEST TIME: " + ss.str());
157 | t.setCharacterSize(80);
158 | }
159 |
160 | for (auto& t : m_Texts)
161 | t.second.setFont(m_FontManager.Get("default"));
162 |
163 | m_Texts["title"].setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, 120.0f));
164 |
165 | m_Texts["best_time"].setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, 325.0f));
166 | }
167 |
168 | void Menu::InitAssets() {
169 | //TEXTURES//
170 | {
171 | m_TextureManager.Load("background", "res/textures/menu.png");
172 | }
173 |
174 | //FONTS//
175 | {
176 | m_FontManager.Load("default", "res/fonts/upheavtt.ttf");
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/The Platformer/States/State/Menu/Menu.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../States/Machine/State Machine.hpp"
3 | #include "../States/State/Settings/Settings.hpp"
4 | #include "../States/State/Game/Game.hpp"
5 |
6 | #include "Text.hpp"
7 | #include "Timer.hpp"
8 | #include "../UI/Button.hpp"
9 | #include "../Effects/Transition/Transition.hpp"
10 |
11 | class Menu : public State {
12 | public:
13 | Menu(StateMachine& machine);
14 | ~Menu();
15 |
16 | virtual void FixedUpdate();
17 | virtual void Update();
18 | virtual void Render(sf::RenderTarget& target);
19 |
20 | private:
21 | AssetManager m_TextureManager;
22 | AssetManager m_FontManager;
23 |
24 | std::unordered_map m_Texts;
25 | std::unordered_map m_Buttons;
26 |
27 | // Sprites
28 | std::unordered_map m_Sprites;
29 |
30 | sf::RectangleShape m_border;
31 |
32 | Timer m_textAnimTimer;
33 | int m_iterator = 0;
34 |
35 | void InitBorder(); // yes
36 |
37 | void AnimateTexts();
38 | void InitTimer();
39 |
40 | void UpdateButtons();
41 | void InitButtons();
42 |
43 | void InitSprites();
44 |
45 | void InitTexts();
46 | void InitAssets();
47 | };
--------------------------------------------------------------------------------
/The Platformer/States/State/Pause/Pause.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Pause.hpp"
3 |
4 | #include "../States/State/Menu/Menu.hpp"
5 |
6 | #include "Key Check.hpp"
7 |
8 | Pause::Pause(StateMachine& machine)
9 | : State(machine)
10 | {
11 | InitAssets();
12 | InitSprites();
13 | InitTexts();
14 | InitButtons();
15 | InitTimer();
16 | }
17 |
18 | Pause::~Pause() {
19 |
20 | }
21 |
22 | void Pause::FixedUpdate() {
23 |
24 | }
25 |
26 | void Pause::Update() {
27 | UpdateButtons();
28 | AnimateTexts();
29 |
30 | if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) && KeyCheck::Key('/')) { // '/' <- is escape keyy XDDDD
31 | MusicController::Get().GetMusic("main_track").setPitch(1.0f);
32 | i_isRunning = false;
33 | }
34 | }
35 |
36 | void Pause::Render(sf::RenderTarget& target) {
37 | // Sprites drawing
38 |
39 | auto& shader = ShaderLibrary::Get().GetShader("blur");
40 | shader.setUniform("u_blur_radius", 0.008f);
41 |
42 | for (const auto& s : m_Sprites)
43 | target.draw(s.second, &ShaderLibrary::Get().GetShader("blur"));
44 |
45 | // Text drawing
46 | for (const auto& t : m_Texts)
47 | target.draw(t.second);
48 |
49 | // Button drawing
50 | for (const auto& b : m_Buttons)
51 | target.draw(b.second);
52 | }
53 |
54 | void Pause::AnimateTexts() {
55 | m_textAnimTimer.Update(i_dt);
56 | }
57 |
58 | void Pause::InitTimer() {
59 | m_textAnimTimer.SetFunction(0.20f, [&]() {
60 | constexpr float pos[10] =
61 | {
62 | 100.0f,
63 | 110.0f,
64 | 120.0f,
65 | 130.0f,
66 | 140.0f,
67 | 130.0f,
68 | 120.0f,
69 | 110.0f,
70 | 100.0f,
71 | 90.0f,
72 | };
73 |
74 | m_Texts["title"].setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, pos[m_iterator]));
75 |
76 | m_iterator++;
77 | if (m_iterator > 9)
78 | m_iterator = 0;
79 | });
80 | }
81 |
82 | void Pause::UpdateButtons() {
83 | for (auto& b : m_Buttons)
84 | b.second.Update(GetMousePos());
85 | }
86 |
87 | void Pause::InitButtons() {
88 | std::initializer_list> init =
89 | {
90 | { "resume", Button("RESUME", sf::Vector2f(WINDOW_WIDTH / 2.0f, 400), m_FontManager.Get("default")) },
91 | { "settings", Button("SETTINGS", sf::Vector2f(WINDOW_WIDTH / 2.0f, 500), m_FontManager.Get("default")) },
92 | { "exit_to_menu", Button("EXIT TO MENU", sf::Vector2f(WINDOW_WIDTH / 2.0f, 600), m_FontManager.Get("default")) },
93 | };
94 |
95 | m_Buttons = init;
96 |
97 | auto& transition = Transition::Get();
98 |
99 | m_Buttons["resume"].SetFunction([&]() {
100 | MusicController::Get().GetMusic("main_track").setPitch(1.0f);
101 | i_isRunning = false;
102 | });
103 |
104 | m_Buttons["settings"].SetFunction([&]() {
105 | transition.SetFunction([&]() {
106 | i_machine.AddStateAtTop(new Settings(i_machine));
107 | transition.Start(Mode::Unveil);
108 | });
109 |
110 | transition.Start(Mode::Veil);
111 | });
112 |
113 | m_Buttons["exit_to_menu"].SetFunction([&]() {
114 | transition.SetFunction([&]() {
115 | i_machine.ClearAndPush(new Menu(i_machine));
116 | MusicController::Get().GetMusic("main_track").setPitch(1.0f);
117 | MusicController::Get().GetMusic("main_track").stop();
118 | transition.Start(Mode::Unveil);
119 | });
120 |
121 | transition.Start(Mode::Veil);
122 | });
123 | }
124 |
125 | void Pause::InitSprites() {
126 | {
127 | auto& s = m_Sprites["background"];
128 | s.setTexture(m_TextureManager.Get("background"));
129 | }
130 | }
131 |
132 | void Pause::InitTexts() {
133 | // TITLE
134 | {
135 | auto& t = m_Texts["title"];
136 | t.setString("PAUSED");
137 | t.setCharacterSize(200);
138 | }
139 |
140 | for (auto& t : m_Texts)
141 | t.second.setFont(m_FontManager.Get("default"));
142 |
143 | m_Texts["title"].setPosition(sf::Vector2f(WINDOW_WIDTH / 2.0f, 120.0f));
144 |
145 | }
146 |
147 | void Pause::InitAssets() {
148 | //TEXTURES//
149 | {
150 | m_TextureManager.Load("background", "res/textures/menu.png");
151 | }
152 |
153 | //FONTS//
154 | {
155 | m_FontManager.Load("default", "res/fonts/upheavtt.ttf");
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/The Platformer/States/State/Pause/Pause.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../States/Machine/State Machine.hpp"
3 | #include "../States/State/Settings/Settings.hpp"
4 |
5 | #include "Text.hpp"
6 | #include "Timer.hpp"
7 | #include "../UI/Button.hpp"
8 | #include "../Effects/Transition/Transition.hpp"
9 |
10 | class Pause : public State {
11 | public:
12 | Pause(StateMachine& machine);
13 | ~Pause();
14 |
15 | virtual void FixedUpdate();
16 | virtual void Update();
17 | virtual void Render(sf::RenderTarget& target);
18 |
19 | private:
20 | AssetManager m_TextureManager;
21 | AssetManager m_FontManager;
22 |
23 | std::unordered_map m_Texts;
24 | std::unordered_map m_Buttons;
25 |
26 | // Sprites
27 | std::unordered_map m_Sprites;
28 |
29 | Timer m_textAnimTimer;
30 | int m_iterator = 0;
31 |
32 | void AnimateTexts();
33 | void InitTimer();
34 |
35 | void UpdateButtons();
36 | void InitButtons();
37 |
38 | void InitSprites();
39 |
40 | void InitTexts();
41 | void InitAssets();
42 | };
--------------------------------------------------------------------------------
/The Platformer/States/State/Settings/Settings.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Settings.hpp"
3 |
4 | Settings::Settings(StateMachine& machine)
5 | : State(machine)
6 | {
7 | InitAssets();
8 | InitButtons();
9 | InitSeekerBars();
10 | InitParticleEmitter();
11 | InitColorPickers();
12 |
13 | InitSprites();
14 | InitTexts();
15 | }
16 |
17 | Settings::~Settings() {
18 | for (auto& s : m_SeekerBars)
19 | delete s.second;
20 |
21 | for (auto& p : m_pickers)
22 | delete p;
23 |
24 | delete m_emitter;
25 | }
26 |
27 | void Settings::FixedUpdate() {
28 |
29 | }
30 |
31 | void Settings::Update() {
32 | UpdateButtons();
33 | UpdateSeekerBars();
34 | UpdateParticleEmitter();
35 | UpdateColorPickers();
36 | }
37 |
38 | void Settings::Render(sf::RenderTarget& target) {
39 | auto& shader = ShaderLibrary::Get().GetShader("blur");
40 | shader.setUniform("u_blur_radius", 0.008f);
41 |
42 | for (const auto& s : m_Sprites)
43 | target.draw(s.second, &shader);
44 |
45 | for (const auto& b : m_Buttons)
46 | target.draw(b.second);
47 |
48 | for (const auto& s : m_SeekerBars)
49 | target.draw(*s.second);
50 |
51 | for (const auto& t : m_Texts)
52 | target.draw(t.second);
53 |
54 | for (const auto& p : m_pickers)
55 | target.draw(*p);
56 |
57 | target.draw(*m_emitter);
58 | }
59 |
60 | void Settings::UpdateColorPickers() {
61 | for (auto& p : m_pickers)
62 | p->Update(GetMousePos());
63 | }
64 |
65 | void Settings::InitColorPickers() {
66 | m_pickers.push_back(new ColorPicker(Extern::particle_birth_color, sf::Vector2f(270.0f, 740.0f)));
67 | m_pickers.push_back(new ColorPicker(Extern::particle_death_color, sf::Vector2f(480.0f, 740.0f)));
68 | }
69 |
70 | void Settings::UpdateParticleEmitter() {
71 | m_emitter->AddParticles();
72 | m_emitter->Update(i_dt);
73 | m_emitter->SetBirthColor(Extern::particle_birth_color);
74 | m_emitter->SetDeathColor(Extern::particle_death_color);
75 | }
76 |
77 | void Settings::InitParticleEmitter() {
78 | m_emitter = new ParticleEmitter(Extern::particle_birth_color, Extern::particle_death_color, 75);
79 | m_emitter->SetLifeTimeRange(3.5f, 8.5f);
80 | m_emitter->SetDirection(sf::Vector2f(1, 0));
81 | m_emitter->SetPosition(sf::Vector2f(725.0f, 750.0f));
82 | m_emitter->SetParticleMax(100);
83 | }
84 |
85 | void Settings::InitTexts() {
86 | // TITLE
87 | {
88 | auto& t = m_Texts["sound"];
89 | t.setString("SOUND VOLUME");
90 | t.setCharacterSize(90);
91 | }
92 |
93 | {
94 | auto& t = m_Texts["music"];
95 | t.setString("MUSIC VOLUME");
96 | t.setCharacterSize(90);
97 | }
98 |
99 | {
100 | auto& t = m_Texts["player_particle"];
101 | t.setString("PLAYER PARTICLE");
102 | t.setCharacterSize(90);
103 | }
104 |
105 | {
106 | auto& t = m_Texts["primary"];
107 | t.setString("PRIMARY");
108 | t.setCharacterSize(40);
109 | }
110 |
111 | {
112 | auto& t = m_Texts["secondary"];
113 | t.setString("SECONDARY");
114 | t.setCharacterSize(40);
115 | }
116 |
117 | for (auto& t : m_Texts)
118 | t.second.setFont(m_FontManager.Get("default"));
119 |
120 | m_Texts["sound"].setPosition(sf::Vector2f(815.0f, 100.0f));
121 |
122 | m_Texts["music"].setPosition(sf::Vector2f(815.0f, 320.0f));
123 |
124 | m_Texts["player_particle"].setPosition(sf::Vector2f(815.0f, 560.0f));
125 |
126 | m_Texts["primary"].setPosition(sf::Vector2f(270.0f, 671.0f));
127 |
128 | m_Texts["secondary"].setPosition(sf::Vector2f(480.0f, 810.0f));
129 | }
130 |
131 | void Settings::UpdateSeekerBars() {
132 | for (auto& s : m_SeekerBars)
133 | s.second->Update(GetMousePos());
134 | }
135 |
136 | void Settings::InitSeekerBars() {
137 | std::initializer_list> init =
138 | {
139 | { "sound", new SeekerBar(sf::Vector2f(350.0f, 180.0f), m_FontManager.Get("default"), 10, Extern::sound_volume / 8) },
140 | { "music", new SeekerBar(sf::Vector2f(350.0f, 400.0f), m_FontManager.Get("default"), 10, Extern::music_volume / 8) },
141 | };
142 |
143 | m_SeekerBars = init;
144 |
145 | auto& soundVolume = Extern::sound_volume;
146 |
147 | m_SeekerBars["sound"]->SetLeftFunction([&soundVolume]() {
148 | if (soundVolume > 0)
149 | soundVolume -= 8;
150 | });
151 |
152 | m_SeekerBars["sound"]->SetRightFunction([&soundVolume]() {
153 | if (soundVolume < 80)
154 | soundVolume += 8;
155 | });
156 |
157 | auto& musicVolume = Extern::music_volume;
158 |
159 | m_SeekerBars["music"]->SetLeftFunction([&musicVolume]() {
160 | if (musicVolume > 0)
161 | musicVolume -= 8;
162 | });
163 |
164 | m_SeekerBars["music"]->SetRightFunction([&musicVolume]() {
165 | if (musicVolume < 80)
166 | musicVolume += 8;
167 | });
168 | }
169 |
170 | void Settings::InitSprites() {
171 | {
172 | auto& s = m_Sprites["background"];
173 | s.setTexture(m_TextureManager.Get("background"));
174 | }
175 | }
176 |
177 | void Settings::UpdateButtons() {
178 | for (auto& b : m_Buttons)
179 | b.second.Update(GetMousePos());
180 | }
181 |
182 | void Settings::InitButtons() {
183 | std::initializer_list> init =
184 | {
185 | { "back", Button("BACK", sf::Vector2f(180.0f, 80.0f), m_FontManager.Get("default")) },
186 | };
187 |
188 | m_Buttons = init;
189 |
190 | auto& transition = Transition::Get();
191 |
192 | m_Buttons["back"].SetFunction([&]() {
193 | transition.SetFunction([&]() {
194 | i_isRunning = false;
195 | transition.Start(Mode::Unveil);
196 | });
197 | transition.Start(Mode::Veil);
198 | });
199 | }
200 |
201 | void Settings::InitAssets() {
202 | //TEXTURES//
203 | {
204 | m_TextureManager.Load("background", "res/textures/menu.png");
205 | }
206 | //FONTS//
207 | {
208 | m_FontManager.Load("default", "res/fonts/upheavtt.ttf");
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/The Platformer/States/State/Settings/Settings.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../States/Machine/State Machine.hpp"
3 |
4 | #include "../UI/Button.hpp"
5 | #include "../UI/Seeker Bar.hpp"
6 | #include "../UI/Color Picker.hpp"
7 | #include "../Effects/Transition/Transition.hpp"
8 |
9 | #include "../Effects/Particle Emitter/Particle Emitter.hpp"
10 |
11 | class Settings : public State {
12 | public:
13 | Settings(StateMachine& machine);
14 | ~Settings();
15 |
16 | virtual void FixedUpdate();
17 | virtual void Update();
18 | virtual void Render(sf::RenderTarget& target);
19 |
20 | private:
21 | AssetManager m_TextureManager;
22 | AssetManager m_FontManager;
23 |
24 | std::unordered_map m_Buttons;
25 | // we have pointer type in here because destructor was destroying objects and new prevented it
26 | std::unordered_map m_SeekerBars;
27 | std::unordered_map m_Sprites;
28 |
29 | std::unordered_map m_Texts;
30 | std::vector m_pickers;
31 |
32 | ParticleEmitter* m_emitter;
33 |
34 | void UpdateColorPickers();
35 | void InitColorPickers();
36 |
37 | void UpdateParticleEmitter();
38 | void InitParticleEmitter();
39 |
40 | void InitTexts();
41 |
42 | void UpdateSeekerBars();
43 | void InitSeekerBars();
44 |
45 | void InitSprites();
46 |
47 | void UpdateButtons();
48 | void InitButtons();
49 |
50 | void InitAssets();
51 | };
--------------------------------------------------------------------------------
/The Platformer/The Platformer.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #include "resource.h"
4 |
5 | #define APSTUDIO_READONLY_SYMBOLS
6 | /////////////////////////////////////////////////////////////////////////////
7 | //
8 | // Generated from the TEXTINCLUDE 2 resource.
9 | //
10 | #include "winres.h"
11 |
12 | /////////////////////////////////////////////////////////////////////////////
13 | #undef APSTUDIO_READONLY_SYMBOLS
14 |
15 | /////////////////////////////////////////////////////////////////////////////
16 | // Polish (Poland) resources
17 |
18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PLK)
19 | LANGUAGE LANG_POLISH, SUBLANG_DEFAULT
20 | #pragma code_page(1250)
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_ICON1 ICON "res\\textures\\icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | VS_VERSION_INFO VERSIONINFO
64 | FILEVERSION 1,0,0,1
65 | PRODUCTVERSION 1,0,0,1
66 | FILEFLAGSMASK 0x3fL
67 | #ifdef _DEBUG
68 | FILEFLAGS 0x1L
69 | #else
70 | FILEFLAGS 0x0L
71 | #endif
72 | FILEOS 0x40004L
73 | FILETYPE 0x1L
74 | FILESUBTYPE 0x0L
75 | BEGIN
76 | BLOCK "StringFileInfo"
77 | BEGIN
78 | BLOCK "041504b0"
79 | BEGIN
80 | VALUE "CompanyName", "Snapi"
81 | VALUE "FileDescription", "DEATHJUMP!"
82 | VALUE "FileVersion", "1.0.0.1"
83 | VALUE "InternalName", "DEATHJUMP.exe"
84 | VALUE "LegalCopyright", "Copyright (C) 2021"
85 | VALUE "OriginalFilename", "DEATHJUMP.exe"
86 | VALUE "ProductName", "DEATHJUMP"
87 | VALUE "ProductVersion", "1.0.0.1"
88 | END
89 | END
90 | BLOCK "VarFileInfo"
91 | BEGIN
92 | VALUE "Translation", 0x415, 1200
93 | END
94 | END
95 |
96 | #endif // Polish (Poland) resources
97 | /////////////////////////////////////////////////////////////////////////////
98 |
99 |
100 |
101 | #ifndef APSTUDIO_INVOKED
102 | /////////////////////////////////////////////////////////////////////////////
103 | //
104 | // Generated from the TEXTINCLUDE 3 resource.
105 | //
106 |
107 |
108 | /////////////////////////////////////////////////////////////////////////////
109 | #endif // not APSTUDIO_INVOKED
110 |
111 |
--------------------------------------------------------------------------------
/The Platformer/The Platformer.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {2d062fc7-4469-4f89-87af-e22cd693a961}
25 | The_Platformer
26 | 10.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v143
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 | false
78 |
79 |
80 | true
81 |
82 |
83 | false
84 |
85 |
86 |
87 | Level3
88 | true
89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
90 | true
91 |
92 |
93 | Console
94 | true
95 |
96 |
97 |
98 |
99 | Level3
100 | true
101 | true
102 | true
103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
104 | true
105 |
106 |
107 | Console
108 | true
109 | true
110 | true
111 |
112 |
113 |
114 |
115 | Level3
116 | true
117 | SFML_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
118 | true
119 | $(SolutionDir)\Engine\src;$(ProjectDir)\Precompiled Headers;$(SolutionDir)\..\VSSFML-STATIC\include
120 | MultiThreadedDebug
121 | Use
122 | stdcpp17
123 |
124 |
125 | Console
126 | true
127 | $(SolutionDir)\..\VSSFML-STATIC\extlibs\libs-msvc\x64;$(SolutionDir)\..\VSSFML-STATIC\lib\Debug;%(AdditionalLibraryDirectories)
128 | opengl32.lib;openal32.lib;freetype.lib;winmm.lib;gdi32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;legacy_stdio_definitions.lib;sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;sfml-audio-s-d.lib;sfml-network-s-d.lib;%(AdditionalDependencies)
129 |
130 |
131 |
132 |
133 | Level3
134 | true
135 | true
136 | true
137 | SFML_STATIC;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
138 | true
139 | $(SolutionDir)\Engine\src;$(ProjectDir)\Precompiled Headers;$(SolutionDir)\..\VSSFML-STATIC\include
140 | MultiThreaded
141 | Use
142 | stdcpp17
143 |
144 |
145 | Console
146 | true
147 | true
148 | true
149 | $(SolutionDir)\..\VSSFML-STATIC\extlibs\libs-msvc\x64;$(SolutionDir)\..\VSSFML-STATIC\lib\Release
150 | opengl32.lib;openal32.lib;freetype.lib;winmm.lib;gdi32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;legacy_stdio_definitions.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib;sfml-audio-s.lib;sfml-network-s.lib;%(AdditionalDependencies)
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 | Use
165 | Use
166 |
167 |
168 |
169 |
170 | Create
171 | Create
172 |
173 |
174 | NotUsing
175 | NotUsing
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 | {bed87c3e-8d9d-43c0-8223-d214d79ccd8c}
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
--------------------------------------------------------------------------------
/The Platformer/The Platformer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files
56 |
57 |
58 | Source Files
59 |
60 |
61 | Source Files
62 |
63 |
64 | Source Files
65 |
66 |
67 | Source Files
68 |
69 |
70 | Source Files
71 |
72 |
73 | Source Files
74 |
75 |
76 | Source Files
77 |
78 |
79 | Source Files
80 |
81 |
82 | Source Files
83 |
84 |
85 | Source Files
86 |
87 |
88 | Source Files
89 |
90 |
91 | Source Files
92 |
93 |
94 | Source Files
95 |
96 |
97 | Source Files
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | Header Files
117 |
118 |
119 | Header Files
120 |
121 |
122 | Header Files
123 |
124 |
125 | Header Files
126 |
127 |
128 | Header Files
129 |
130 |
131 | Header Files
132 |
133 |
134 | Header Files
135 |
136 |
137 | Header Files
138 |
139 |
140 | Header Files
141 |
142 |
143 | Header Files
144 |
145 |
146 | Header Files
147 |
148 |
149 | Header Files
150 |
151 |
152 | Header Files
153 |
154 |
155 | Header Files
156 |
157 |
158 | Header Files
159 |
160 |
161 | Header Files
162 |
163 |
164 | Header Files
165 |
166 |
167 | Header Files
168 |
169 |
170 | Header Files
171 |
172 |
173 | Header Files
174 |
175 |
176 | Header Files
177 |
178 |
179 | Header Files
180 |
181 |
182 | Header Files
183 |
184 |
185 | Header Files
186 |
187 |
188 | Header Files
189 |
190 |
191 | Header Files
192 |
193 |
194 | Header Files
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 | Resource Files
204 |
205 |
206 |
207 |
208 | Resource Files
209 |
210 |
211 | Resource Files
212 |
213 |
214 | Resource Files
215 |
216 |
217 | Resource Files
218 |
219 |
220 | Resource Files
221 |
222 |
223 | Resource Files
224 |
225 |
226 |
227 |
228 | Resource Files
229 |
230 |
231 |
--------------------------------------------------------------------------------
/The Platformer/The Platformer.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/The Platformer/UI/Button.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Button.hpp"
3 |
4 | #include "Key Check.hpp"
5 | #include "../Effects/Music controller/Music Controller.hpp"
6 |
7 | Button::Button
8 | (
9 | std::string text,
10 | sf::Vector2f position,
11 | const sf::Font& font
12 | )
13 | {
14 | m_label.setString(text);
15 |
16 | InitLabel(position, font);
17 | InitBody(position);
18 | }
19 |
20 | Button::~Button() {
21 |
22 | }
23 |
24 | void Button::Update(const sf::Vector2f& mousePos) {
25 | const sf::Color color = (m_body.getGlobalBounds().contains(mousePos) ? m_pressedColor : m_defaultColor);
26 |
27 | m_label.setFillColor(color);
28 | m_body.setOutlineColor(color);
29 |
30 | m_isPressed = color == m_pressedColor && sf::Mouse::isButtonPressed(sf::Mouse::Left) && KeyCheck::Button('L');
31 |
32 |
33 | if (m_isPressed && m_fun) {
34 | MusicController::Get().GetSound("button").play();
35 | m_fun();
36 | }
37 | }
38 |
39 | void Button::SetFunction(std::function fun) { m_fun = fun; }
40 |
41 | const bool Button::Pressed() { return m_isPressed; }
42 |
43 | const sf::Vector2f Button::GetSize() const {
44 | return m_body.getSize();
45 | }
46 |
47 | void Button::InitLabel(const sf::Vector2f& position, const sf::Font& font) {
48 | m_label.setFont(font);
49 | m_label.setCharacterSize(90);
50 | m_label.setSmooth(false);
51 |
52 | m_label.setPosition(position);
53 | }
54 |
55 | void Button::InitBody(const sf::Vector2f& position) {
56 | const sf::Vector2f size = m_label.getSize() + sf::Vector2f(30.0f, 20.0f);
57 |
58 | m_body.setFillColor(sf::Color(100, 100, 100, 80));
59 |
60 | m_body.setSize(size);
61 | m_body.setOrigin(size / 2.0f);
62 | m_body.setPosition(position);
63 |
64 | m_body.setOutlineThickness(4);
65 | }
66 |
67 | void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const {
68 | target.draw(m_body);
69 | target.draw(m_label);
70 | }
71 |
--------------------------------------------------------------------------------
/The Platformer/UI/Button.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 | #include "Text.hpp"
4 |
5 | class Button : public sf::Drawable {
6 | public:
7 | Button() = default;
8 | Button(std::string text, sf::Vector2f position, const sf::Font& font);
9 | ~Button();
10 |
11 | void Update(const sf::Vector2f& mousePos);
12 |
13 | void SetFunction(std::function fun);
14 |
15 | // Accessors
16 | const bool Pressed();
17 | const sf::Vector2f GetSize() const;
18 |
19 | private:
20 | Text m_label;
21 | sf::RectangleShape m_body;
22 |
23 | bool m_isPressed = false;
24 |
25 | std::function m_fun = 0;
26 |
27 | const sf::Color m_pressedColor = sf::Color(100, 100, 100, 255);
28 | const sf::Color m_defaultColor = sf::Color(255, 255, 255, 255);
29 |
30 | void InitLabel(const sf::Vector2f& position, const sf::Font& font);
31 | void InitBody(const sf::Vector2f& position);
32 |
33 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
34 | };
--------------------------------------------------------------------------------
/The Platformer/UI/Color Picker.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Color Picker.hpp"
3 |
4 | #include "Key Check.hpp"
5 |
6 | ColorPicker::ColorPicker
7 | (
8 | sf::Color& color,
9 | sf::Vector2f position
10 | )
11 | : m_color(&color)
12 | {
13 | InitBody(position);
14 | m_colorWheel = new ColorWheel(position);
15 | }
16 |
17 | ColorPicker::~ColorPicker() {
18 | delete m_colorWheel;
19 | }
20 |
21 | void ColorPicker::Update(const sf::Vector2f& mousePos) {
22 | if (m_wheelVisible) {
23 | if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && !m_keyCheck) {
24 | m_wheelVisible = false;
25 |
26 | if (m_colorWheel->getGlobalBounds().contains(mousePos)) {
27 | sf::Vector3f color = m_colorWheel->GetPixel(mousePos);
28 | *m_color = sf::Color(color.x, color.y, color.z, 255);
29 | m_body.setFillColor(*m_color);
30 | }
31 | }
32 | }
33 | else {
34 | bool pressed = m_body.getGlobalBounds().contains(mousePos) && sf::Mouse::isButtonPressed(sf::Mouse::Left) && !m_keyCheck;
35 |
36 | if (pressed) {
37 | m_wheelVisible = true;
38 | }
39 | }
40 |
41 | if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
42 | m_keyCheck = true;
43 | else
44 | m_keyCheck = false;
45 | }
46 |
47 | void ColorPicker::InitBody(const sf::Vector2f& position) {
48 | const sf::Vector2f size = sf::Vector2f(75.0f, 75.0f);
49 |
50 | m_body.setSize(size);
51 | m_body.setOrigin(size / 2.0f);
52 | m_body.setPosition(position);
53 | m_body.setFillColor(*m_color);
54 | m_body.setOutlineThickness(3);
55 | }
56 |
57 | void ColorPicker::draw(sf::RenderTarget& target, sf::RenderStates states) const {
58 | if (m_wheelVisible)
59 | target.draw(*m_colorWheel);
60 | else
61 | target.draw(m_body);
62 |
63 | // for some reson i couldn't write ? expression here B))
64 | }
65 |
--------------------------------------------------------------------------------
/The Platformer/UI/Color Picker.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "Color Wheel.hpp"
5 |
6 | // this class is completly piece of garbage and i should harm mysefl for writing it
7 |
8 | class ColorPicker : public sf::Drawable {
9 | public:
10 | ColorPicker(sf::Color& color, sf::Vector2f position);
11 | ~ColorPicker();
12 |
13 | void Update(const sf::Vector2f& mousePos);
14 | private:
15 | sf::RectangleShape m_body;
16 |
17 | sf::Color* m_color;
18 |
19 | ColorWheel* m_colorWheel;
20 |
21 | bool m_keyCheck = false; // (must be specyfic for this class)
22 |
23 | bool m_wheelVisible = false;
24 | void InitBody(const sf::Vector2f& position);
25 |
26 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
27 | };
--------------------------------------------------------------------------------
/The Platformer/UI/Color Wheel.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Color Wheel.hpp"
3 |
4 | // do not fucking look in here i will kill you
5 | ColorWheel::ColorWheel(sf::Vector2f position) {
6 |
7 | sf::Image image;
8 |
9 | image.create(256, 256);
10 |
11 | for (int y = 0; y < 200; y++) {
12 | for (int x = 255; x >= 0; x--) {
13 | sf::Vector3f color;
14 |
15 | float sub = 0.0f;
16 |
17 | if (x < 32) {
18 | color = Lerp(sf::Vector3f(255, 0, 0), sf::Vector3f(255, 0, 0), ((float)x - sub) / 32.0f);
19 | }
20 | else if (x >= 32 && x < 64) {
21 | sub = 32.0;
22 | color = Lerp(sf::Vector3f(255, 0, 0), sf::Vector3f(255, 255, 0), ((float)x - sub) / 32.0f);
23 | }
24 | else if (x >= 64 && x < 96) {
25 | sub = 64.0;
26 | color = Lerp(sf::Vector3f(255, 255, 0), sf::Vector3f(0, 255, 0), ((float)x - sub) / 32.0f);
27 | }
28 | else if (x >= 96 && x < 128) {
29 | sub = 96.0;
30 | color = Lerp(sf::Vector3f(0, 255, 0), sf::Vector3f(0, 255, 255), ((float)x - sub) / 32.0f);
31 | }
32 | else if (x >= 128 && x < 160) {
33 | sub = 128.0f;
34 | color = Lerp(sf::Vector3f(0, 255, 255), sf::Vector3f(0, 0, 255), ((float)x - sub) / 32.0f);
35 | }
36 | else if (x >= 160 && x < 192) {
37 | sub = 160.0f;
38 | color = Lerp(sf::Vector3f(0, 0, 255), sf::Vector3f(255, 0, 255), ((float)x - sub) / 32.0f);
39 | }
40 | else if (x >= 192 && x < 224) {
41 | sub = 192.0f;
42 | color = Lerp(sf::Vector3f(255, 0, 255), sf::Vector3f(255, 255, 255), ((float)x - sub) / 32.0f);
43 | }
44 | else if (x >= 224)
45 | color = sf::Vector3f(255.0f, 255.0f, 255.0f);
46 |
47 | image.setPixel(x, y, sf::Color(color.x, color.y, color.z, 255));
48 | }
49 |
50 | }
51 |
52 |
53 | for (int x = 255; x >= 0; x--) {
54 | sf::Color ccolor = image.getPixel(x, 199);
55 | sf::Vector3f color = sf::Vector3f(ccolor.r, ccolor.g, ccolor.b);
56 |
57 | for (int y = 200; y < 256; y++) {
58 | color = Lerp(color, sf::Vector3f(0.0f, 0.0f, 0.0f), ((float)y - 200) / 384.0f);
59 | image.setPixel(x, y, sf::Color(color.x, color.y, color.z, 255));
60 | }
61 | }
62 |
63 | m_texture.loadFromImage(image);
64 | m_body.setTextureRect(sf::IntRect(0, 0, 256, 256));
65 | m_body.setTexture(&m_texture);
66 | m_body.setSize(sf::Vector2f(256, 256));
67 | m_body.setOutlineThickness(3);
68 | m_body.setOrigin(sf::Vector2f(256, 256) / 2.0f);
69 | m_body.setPosition(position);
70 | }
71 |
72 | ColorWheel::~ColorWheel() {
73 |
74 | }
75 |
76 | sf::Vector3f ColorWheel::GetPixel(sf::Vector2f pos) {
77 | pos -= m_body.getPosition() - m_body.getSize() / 2.0f;
78 |
79 | if (pos.x < 0 || pos.x > 255)
80 | return sf::Vector3f();
81 |
82 | if (pos.y < 0 || pos.y > 255)
83 | return sf::Vector3f();
84 |
85 | sf::Color color = m_texture.copyToImage().getPixel(pos.x, pos.y);
86 |
87 | return sf::Vector3f(color.r, color.g, color.b);
88 | }
89 |
90 | sf::FloatRect ColorWheel::getGlobalBounds() {
91 | return m_body.getGlobalBounds();
92 | }
93 |
94 |
95 | sf::Vector3f ColorWheel::Lerp(const sf::Vector3f& x, const sf::Vector3f& y, const float& t) {
96 | return x * (1.f - t) + y * t;
97 | }
98 |
99 | void ColorWheel::draw(sf::RenderTarget& target, sf::RenderStates states) const {
100 | target.draw(m_body);
101 | }
102 |
--------------------------------------------------------------------------------
/The Platformer/UI/Color Wheel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | // yeah we don't need to know what is inside here c:
5 | class ColorWheel : public sf::Drawable {
6 | public:
7 | ColorWheel(sf::Vector2f position);
8 | ~ColorWheel();
9 |
10 | sf::Vector3f GetPixel(sf::Vector2f pos);
11 |
12 | sf::FloatRect getGlobalBounds();
13 |
14 | private:
15 | sf::Texture m_texture;
16 | sf::RectangleShape m_body;
17 |
18 | sf::Vector3f Lerp(const sf::Vector3f& x, const sf::Vector3f& y, const float& t);
19 |
20 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
21 | };
--------------------------------------------------------------------------------
/The Platformer/UI/Countdown.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/UI/Countdown.cpp
--------------------------------------------------------------------------------
/The Platformer/UI/Countdown.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "Fixed Clock.hpp"
5 |
6 | class Countdown : public sf::Drawable {
7 | public:
8 | Countdown(sf::Font* font);
9 | ~Countdown();
10 |
11 | void Update();
12 |
13 | unsigned CurrentFrame() const;
14 | private:
15 | sf::Font* font = 0;
16 |
17 | sf::Text counter;
18 |
19 | FixedClock clock;
20 |
21 | unsigned currentFrame = 0;
22 |
23 | sf::SoundBuffer buffers[4];
24 | std::unordered_map sounds;
25 |
26 | std::string str[4] =
27 | {
28 | "3",
29 | "2",
30 | "1",
31 | "GO!"
32 | };
33 |
34 | bool _IsRunning = true;
35 |
36 | void SetCounterOrigin();
37 |
38 | void InitCounter();
39 |
40 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
41 | };
--------------------------------------------------------------------------------
/The Platformer/UI/Health Bar.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Health Bar.hpp"
3 |
4 | HealthBar::HealthBar() {
5 | InitBody();
6 | }
7 |
8 | HealthBar::~HealthBar() {
9 |
10 | }
11 |
12 | void HealthBar::Change(bool x) {
13 |
14 | if (x && m_currentCoords < 3)
15 | m_currentCoords++;
16 | else if (!x && m_currentCoords > 0)
17 | m_currentCoords--;
18 |
19 | //m_currentCoords += x ? 1 : -1;
20 |
21 | m_sprite.setTextureRect(sf::IntRect(0, m_coords[m_currentCoords], 96, 32));
22 | }
23 |
24 | int HealthBar::GetHealthState() const {
25 | return 3 - m_currentCoords;
26 | }
27 |
28 | void HealthBar::InitBody() {
29 | m_texture.loadFromFile("res/textures/health.png"); // just shut the fuck up we don't talk about it
30 |
31 | m_sprite.setTexture(m_texture);
32 | m_sprite.setTextureRect(sf::IntRect(0, m_coords[m_currentCoords], 96, 32));
33 | m_sprite.setScale(sf::Vector2f(2.0f, 2.0f));
34 | m_sprite.setPosition(sf::Vector2f(65.0f, 35.0f));
35 | }
36 |
37 | void HealthBar::draw(sf::RenderTarget& target, sf::RenderStates states) const {
38 | target.draw(m_sprite);
39 | }
40 |
--------------------------------------------------------------------------------
/The Platformer/UI/Health Bar.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | class HealthBar : public sf::Drawable {
5 | public:
6 | HealthBar();
7 | ~HealthBar();
8 |
9 | void Change(bool x); // god please ; - ;
10 |
11 | int GetHealthState() const;
12 | private:
13 | sf::Sprite m_sprite;
14 | sf::Texture m_texture;
15 |
16 | unsigned m_currentCoords = 0;
17 |
18 | unsigned m_coords[3] =
19 | {
20 | 0,
21 | 32,
22 | 64
23 | };
24 |
25 | void InitBody();
26 |
27 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
28 | };
--------------------------------------------------------------------------------
/The Platformer/UI/Seeker Bar.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Seeker Bar.hpp"
3 |
4 | SeekerBar::SeekerBar
5 | (
6 | sf::Vector2f position,
7 | const sf::Font& font,
8 | const unsigned blocks,
9 | const unsigned currentBlock
10 | )
11 | : m_blocks(blocks), m_currentBlock(currentBlock)
12 | {
13 | for (unsigned i = 1; i <= m_blocks; i++) {
14 | const sf::Vector2f pos = sf::Vector2f(position.x + (m_size.x + 5) * i, position.y - m_size.y / 2.0f);
15 |
16 | AddQuad(pos);
17 | }
18 |
19 | InitButtons(position.y, font);
20 | }
21 |
22 | SeekerBar::~SeekerBar() {
23 | delete m_buttonLeft;
24 | delete m_buttonRight;
25 | }
26 |
27 | void SeekerBar::SetLeftFunction(std::function fun) {
28 | m_buttonLeft->SetFunction(fun);
29 | }
30 |
31 | void SeekerBar::SetRightFunction(std::function fun) {
32 | m_buttonRight->SetFunction(fun);
33 | }
34 |
35 | void SeekerBar::Update(const sf::Vector2f& mousePos) {
36 | m_buttonLeft->Update(mousePos);
37 | m_buttonRight->Update(mousePos);
38 |
39 | if (m_buttonLeft->Pressed()) {
40 | if (m_currentBlock > 0)
41 | m_currentBlock--;
42 | }
43 | else if (m_buttonRight->Pressed()) {
44 | if (m_currentBlock < m_blocks)
45 | m_currentBlock++;
46 | }
47 |
48 | for (int i = m_currentBlock; i < m_blocks; i++)
49 | SetQuadColor(i, sf::Color(180, 180, 180, 120));
50 |
51 | for (int i = 0; i < m_currentBlock; i++)
52 | SetQuadColor(i, sf::Color(220, 220, 220, 255));
53 | }
54 |
55 | void SeekerBar::SetCurrentBlock(const int block) {
56 | m_currentBlock = block;
57 | }
58 |
59 | void SeekerBar::AddQuad(const sf::Vector2f& pos) {
60 | std::array vertices;
61 |
62 | vertices[0].position = sf::Vector2f(pos.x, pos.y);
63 | vertices[1].position = sf::Vector2f(pos.x + m_size.x, pos.y);
64 | vertices[2].position = sf::Vector2f(pos.x + m_size.x, pos.y + m_size.y);
65 | vertices[3].position = sf::Vector2f(pos.x, pos.y + m_size.y);
66 |
67 | for (auto& v : vertices) {
68 | v.color = sf::Color(180, 180, 180, 255);
69 | m_vertices.push_back(v);
70 | }
71 | }
72 |
73 | void SeekerBar::SetQuadColor(size_t index, sf::Color color) {
74 | index *= 4;
75 |
76 | for (size_t i = 0; i < 4; i++)
77 | m_vertices[index + i].color = color;
78 | }
79 |
80 | void SeekerBar::InitButtons(const float& Y, const sf::Font& font) {
81 |
82 | const int offset = 50;
83 |
84 | {
85 | const sf::Vector2f pos = sf::Vector2f(m_vertices.front().position.x - offset, Y);
86 | m_buttonLeft = new Button("<", pos, font);
87 | }
88 |
89 | {
90 | const sf::Vector2f pos = sf::Vector2f(m_vertices[m_vertices.size() - 2].position.x + offset, Y);
91 | m_buttonRight = new Button(">", pos, font);
92 | }
93 | }
94 |
95 | void SeekerBar::draw(sf::RenderTarget& target, sf::RenderStates states) const {
96 | target.draw(m_vertices.data(), m_vertices.size(), sf::Quads);
97 | target.draw(*m_buttonLeft);
98 | target.draw(*m_buttonRight);
99 | }
100 |
--------------------------------------------------------------------------------
/The Platformer/UI/Seeker Bar.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "stdafx.h"
3 |
4 | #include "Button.hpp"
5 |
6 | class SeekerBar : public sf::Drawable {
7 | public:
8 | SeekerBar() = default;
9 | SeekerBar(sf::Vector2f position, const sf::Font& font, const unsigned blocks, const unsigned currentBlock);
10 | ~SeekerBar();
11 |
12 | void SetLeftFunction(std::function fun);
13 | void SetRightFunction(std::function fun);
14 |
15 | void Update(const sf::Vector2f& mousePos);
16 |
17 | void SetCurrentBlock(const int block);
18 | private:
19 | unsigned m_blocks = 0;
20 |
21 | int m_currentBlock;
22 |
23 | sf::Vector2i m_size = sf::Vector2i(73, 73);
24 | std::vector m_vertices;
25 |
26 | Button* m_buttonLeft = nullptr;
27 | Button* m_buttonRight = nullptr;
28 |
29 | void SetQuadColor(size_t index, sf::Color color);
30 | void AddQuad(const sf::Vector2f& position);
31 | void InitButtons(const float& Y, const sf::Font& font);
32 |
33 | virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
34 | };
--------------------------------------------------------------------------------
/The Platformer/UI/UI.hpp:
--------------------------------------------------------------------------------
1 | //#pragma once
2 | //#include "stdafx.h"
3 | //
4 | //class UI : public sf::Drawable {
5 | //public:
6 | // virtual void Update(const sf::Vector2f& mousePos) = 0;
7 | //
8 | // virtual void SetFunction(std::function fun) = 0;
9 | //};
--------------------------------------------------------------------------------
/The Platformer/main.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Application.hpp"
3 |
4 | int main() {
5 | sf::Clock deltaClock;
6 | sf::Clock fixedDeltaClock;
7 |
8 | float deltaTime = 0.0f;
9 | float fixedDeltaTime = 0.0f;
10 | double physicsElapsedTime = 0.0;
11 |
12 | Application application(deltaTime, fixedDeltaTime);
13 |
14 | deltaClock.restart();
15 | fixedDeltaClock.restart();
16 |
17 | while (application.IsRunning()) {
18 | /* Calculating time for fixed update to run */
19 | physicsElapsedTime += deltaTime;
20 | while (physicsElapsedTime > PHYSICS_STEP) {
21 | fixedDeltaTime = fixedDeltaClock.restart().asSeconds();
22 | if (fixedDeltaTime > PHYSICS_STEP * 5.0f)
23 | fixedDeltaTime = PHYSICS_STEP;
24 |
25 | application.FixedUpdate();
26 | physicsElapsedTime -= PHYSICS_STEP;
27 | }
28 |
29 | application.Update();
30 | application.Render();
31 |
32 | deltaTime = deltaClock.restart().asSeconds();
33 | }
34 |
35 | return EXIT_SUCCESS;
36 | }
--------------------------------------------------------------------------------
/The Platformer/openal32.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/openal32.dll
--------------------------------------------------------------------------------
/The Platformer/res/fonts/upheavtt.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/fonts/upheavtt.ttf
--------------------------------------------------------------------------------
/The Platformer/res/music/main.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/music/main.ogg
--------------------------------------------------------------------------------
/The Platformer/res/music/menu.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/music/menu.ogg
--------------------------------------------------------------------------------
/The Platformer/res/music/pause.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/music/pause.ogg
--------------------------------------------------------------------------------
/The Platformer/res/save:
--------------------------------------------------------------------------------
1 | 8
2 | 48
3 | 255 255 255
4 | 31 255 0
5 | 132.46
6 |
--------------------------------------------------------------------------------
/The Platformer/res/shaders/blurFragment.shader:
--------------------------------------------------------------------------------
1 | uniform sampler2D texture;
2 |
3 | uniform float u_blur_radius;
4 |
5 | void main()
6 | {
7 | vec2 offx = vec2(u_blur_radius, 0.0);
8 | vec2 offy = vec2(0.0, u_blur_radius);
9 |
10 | vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
11 | texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
12 | texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
13 | texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
14 | texture2D(texture, gl_TexCoord[0].xy + offy) * 2.0 +
15 | texture2D(texture, gl_TexCoord[0].xy - offx - offy) * 1.0 +
16 | texture2D(texture, gl_TexCoord[0].xy - offx + offy) * 1.0 +
17 | texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
18 | texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
19 |
20 | gl_FragColor = gl_Color * (pixel / 16.0);
21 | }
--------------------------------------------------------------------------------
/The Platformer/res/shaders/blurVertex.shader:
--------------------------------------------------------------------------------
1 | varying vec4 vert_pos;
2 |
3 | void main()
4 | {
5 | // transform the vertex position
6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
7 |
8 | gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
9 |
10 | gl_FrontColor = gl_Color;
11 | }
--------------------------------------------------------------------------------
/The Platformer/res/shaders/fogFragment.shader:
--------------------------------------------------------------------------------
1 | uniform float u_time;
2 | uniform vec2 u_resolution;
3 |
4 | #define PI 3.1415
5 |
6 | //const vec4 color = vec4(0.7, 0.19, 0.89, 0.73);
7 | //const vec4 color = vec4(0.7, 0.65, 0.8, 0.95);
8 | const vec4 color = vec4(0.8, 0.8, 0.8, 0.85);
9 | const float noise_scale = 20.0;
10 | const float alpha_power = 2.0;
11 | const int OCTAVES = 8;
12 |
13 | float rand(vec2 coord) {
14 | return fract(5.0 * sin(dot(coord, vec2(56.0, 78.0)) * 1000.0) * 1000.0);
15 | }
16 |
17 | float noise(vec2 coord) {
18 | vec2 i = floor(coord);
19 | vec2 f = fract(coord);
20 |
21 | float a = rand(i);
22 | float b = rand(i + vec2(1.0, 0.0));
23 | float c = rand(i + vec2(0.0, 1.0));
24 | float d = rand(i + vec2(1.0, 1.0));
25 |
26 | vec2 cubic = f * f * (3.0 - 2.0 * f);
27 |
28 | return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
29 | }
30 |
31 | float fbm(vec2 coord) {
32 | float value = 0.0;
33 | float scale = 0.5;
34 |
35 | for (int i = 0; i < OCTAVES; i++) {
36 | value += noise(coord) * scale;
37 | coord *= 2.0;
38 | scale *= 0.5;
39 | }
40 | return value;
41 | }
42 |
43 | float parabola(float x, float k) {
44 | return pow(cos(PI * x / 2.0), k);
45 | }
46 |
47 |
48 | void main()
49 | {
50 | vec2 UV = gl_FragCoord.xy / u_resolution.xy;
51 |
52 | vec2 coord = UV * noise_scale;
53 | vec2 motion = vec2(fbm(coord + vec2(u_time * -0.2, u_time * 0.2)));
54 | float final = fbm(coord + motion);
55 |
56 | float y = parabola(UV.y, 8.0);
57 | vec3 parabolaColor = vec3(y);
58 |
59 |
60 | gl_FragColor = vec4(color.rgb, min(parabolaColor, pow(final, alpha_power)) * color.a);
61 | }
--------------------------------------------------------------------------------
/The Platformer/res/shaders/fogVertex.shader:
--------------------------------------------------------------------------------
1 | varying vec4 vert_pos;
2 |
3 | void main()
4 | {
5 | // transform the vertex position
6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
7 |
8 | gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
9 |
10 | gl_FrontColor = gl_Color;
11 | }
--------------------------------------------------------------------------------
/The Platformer/res/shaders/lightFragment.shader:
--------------------------------------------------------------------------------
1 | uniform sampler2D texture;
2 |
3 | #define PI 3.1415
4 |
5 | //vec4 color = vec4(0.7, 0.4, 0.05, 0.75);
6 | const float alpha_power = 2.0;
7 |
8 | uniform float u_time;
9 | uniform float u_move;
10 | uniform vec4 color;
11 |
12 | void main()
13 | {
14 | vec2 uv = gl_TexCoord[0].xy * 2.0 - 1.0;
15 |
16 | float div = 0.5 * abs(sin(u_time + PI * u_move)) + 0.7;
17 |
18 | float distance = 1.0 - length(uv / div);
19 |
20 | /*if (distance < 0.5) {
21 | color.r = 0.85;
22 | color.g = 0.4;
23 | }*/
24 |
25 | if (distance < 0.0)
26 | discard;
27 |
28 | //distance = 1.0;
29 |
30 | gl_FragColor = vec4(color.rgb, pow(distance, alpha_power) * color.a);
31 | }
32 |
--------------------------------------------------------------------------------
/The Platformer/res/shaders/lightVertex.shader:
--------------------------------------------------------------------------------
1 | varying vec4 vert_pos;
2 |
3 | void main()
4 | {
5 | // transform the vertex position
6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
7 |
8 | gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
9 |
10 | gl_FrontColor = gl_Color;
11 | }
--------------------------------------------------------------------------------
/The Platformer/res/shaders/transitionFragment.shader:
--------------------------------------------------------------------------------
1 | uniform sampler2D texture;
2 |
3 | float diamondPixelSize = 50.f;
4 | uniform vec2 u_resolution;
5 | uniform float progress;
6 | void main()
7 | {
8 | vec2 uv = gl_FragCoord.xy / u_resolution.xy;
9 |
10 | uv *= 1.0 - uv.yx;
11 |
12 | float vig = uv.x * uv.y * 50.0;
13 |
14 | vig = pow(vig, 0.25);
15 |
16 | vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
17 |
18 | float UVx = gl_FragCoord.x / u_resolution.x;
19 | float UVy = gl_FragCoord.y / u_resolution.y;
20 |
21 | float xFraction = fract(gl_FragCoord.x / diamondPixelSize);
22 | float yFraction = fract(gl_FragCoord.y / diamondPixelSize);
23 |
24 | float xDistance = abs(xFraction - 0.5);
25 | float yDistance = abs(yFraction - 0.5);
26 |
27 | if (xDistance + yDistance + UVx + UVy > progress * 4.f) {
28 | discard;
29 | }
30 |
31 | gl_FragColor = gl_Color * vig * pixel;
32 | }
--------------------------------------------------------------------------------
/The Platformer/res/shaders/transitionVertex.shader:
--------------------------------------------------------------------------------
1 | varying vec4 vert_pos;
2 |
3 | void main()
4 | {
5 | // transform the vertex position
6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
7 |
8 | gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
9 |
10 | gl_FrontColor = gl_Color;
11 | }
--------------------------------------------------------------------------------
/The Platformer/res/sounds/1.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/1.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/2.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/2.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/3.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/3.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/blowUp.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/blowUp.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/button.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/button.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/ghost.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/ghost.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/go.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/go.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/pickUp.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/pickUp.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/playerCrouch.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/playerCrouch.wav
--------------------------------------------------------------------------------
/The Platformer/res/sounds/playerJump.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/sounds/playerJump.wav
--------------------------------------------------------------------------------
/The Platformer/res/textures/Bez nazwy-1.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/Bez nazwy-1.psd
--------------------------------------------------------------------------------
/The Platformer/res/textures/Bez nazwy-2.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/Bez nazwy-2.psd
--------------------------------------------------------------------------------
/The Platformer/res/textures/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/background.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/explo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/explo.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/fireball.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/fireball.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/ghost.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/ghost.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/health.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/health.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/heart.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/icon.ico
--------------------------------------------------------------------------------
/The Platformer/res/textures/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/icon.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/map — kopia.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/map — kopia.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/map.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/menu.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/player.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/player.png
--------------------------------------------------------------------------------
/The Platformer/res/textures/proj.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/proj.psd
--------------------------------------------------------------------------------
/The Platformer/res/textures/timer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xSnapi/deathjump/cca65c09e10553a5c8cebada7bd47a16031ef904/The Platformer/res/textures/timer.png
--------------------------------------------------------------------------------
/The Platformer/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by The Platformer.rc
4 | //
5 | #define IDI_ICON1 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------