diff --git a/src/Main.cpp b/src/Main.cpp index 1c15a25..e937a64 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -107,7 +107,6 @@ MainState m2; class SplashScreen : public State { Object bg; Object black; - int tick[2]; virtual void Create() { bg.create(0, 0, "data/powered.png"); AddObject(&bg); @@ -117,26 +116,15 @@ class SplashScreen : public State { black.alpha = 0; + Timer time; + Timer time2; + time2.start(1.0, [this](int dummy) {black.alpha += 1; return 0;}, true); + time.start(3.0, [](int dummy) {SwitchState(&m2); return 0;}); + playSound("data/flixel.ogg"); - // basic timer - tick[0] = Sec2Tick(1.0); - tick[1] = Sec2Tick(3.0); - //SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF ); } - int now[2] = {0, 0}; - virtual void Update(float dt) { - for (int i = 0; i < 2; i++) { - now[i]++; - } - if (!(now[0] < tick[0])) { - black.alpha += 1; - } - if (!(now[1] < tick[1])) { - SwitchState(&m2); - } - } }; SplashScreen m; diff --git a/src/Render.cpp b/src/Render.cpp index 40b8f9a..06b2b3b 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include #include #include @@ -87,6 +89,9 @@ void Render::Object::Draw(float dt) { if (alpha > 100) alpha = 100; + if (alpha < 0) + alpha = 0; + SDL_SetTextureAlphaMod(this->_tex, (this->alpha/100)*255); } @@ -152,6 +157,7 @@ void Render::TextObject::Draw(float dt) { eff.color = color; eff.scale.x = scale.x; eff.scale.y = scale.y; + FC_SetFilterMode(font, (antialiasing ? FC_FILTER_LINEAR : FC_FILTER_NEAREST)); FC_DrawEffect(font, renderer, x-offset.x, y-offset.y, eff, text.c_str()); SDL_Rect rec = FC_GetBounds(font, x-offset.x, y-offset.y, alignment, eff.scale, text.c_str()); @@ -221,6 +227,19 @@ bool Render::Init(string window_name) { return true; } +vector Render::_sec; +vector> Render::_call; +vector Render::_repeats; +vector Render::_ticks; + +template +void remove_a(std::vector& vec, size_t pos) +{ + typename std::vector::iterator it = vec.begin(); + std::advance(it, pos); + vec.erase(it); +} + bool Render::Update() { int lastUpdate = SDL_GetTicks(); bool run = true; @@ -241,6 +260,32 @@ bool Render::Update() { current_state->Update(dT); + // I know this is a shitty way to do this + // but bear with me + // it was hard to work with lambdas properly man + // let me have this just one please :) + if (_sec.size() > 0) { + for (int i = 0; i < _sec.size(); i++) { + if (_ticks[i] != -1) + _ticks[i]++; + + if (_sec[i] != -1) { + if (!(_ticks[i] < Sec2Tick(_sec[i]))) { + if (_call[i] != NULL) + _call[i](NULL); + if (!_repeats[i] && _repeats[i] != NULL) + { + _ticks[i] = -1; + _sec[i] = -1; + _call[i] = NULL; + _repeats[i] = NULL; + } + } + } + // cout << i << endl; + } + } + lastUpdate = current; current_state->Draw(dT); @@ -266,6 +311,10 @@ bool Render::Update() { void Render::SwitchState(State* state) { if (current_state != nullptr) { + _ticks = {}; + _call = {}; + _repeats = {}; + _sec = {}; for (int i = 0; i < current_state->get_obj().size(); i++) { SDL_DestroyTexture(current_state->get_obj()[i]->_tex); } diff --git a/src/Render.hpp b/src/Render.hpp index 6c58e03..f1846a0 100644 --- a/src/Render.hpp +++ b/src/Render.hpp @@ -1,8 +1,10 @@ #ifndef _RENDER_H #define _RENDER_H #include +#include #include #include +#include #include #include #include @@ -132,10 +134,29 @@ namespace Render { FC_AlignEnum alignment = FC_ALIGN_LEFT; SDL_Color color; string text = ""; + bool antialiasing = false; private: int font_size = 20; }; + template + using Func = std::function; + + extern vector _sec; + extern vector> _call; + extern vector _repeats; + extern vector _ticks; + + class Timer { + public: + void start(float seconds, Func callback, bool repeat = false) { + _sec.push_back(seconds); + _call.push_back(callback); + _repeats.push_back(repeat); + _ticks.push_back(0); + } + }; + /* * A state is where you would contain said objects. */ @@ -195,11 +216,12 @@ namespace Render { void SwitchState(State* state); extern SDL_Event event; - extern State* current_state; extern HWND hwnd; extern HWND consoleD; + extern State* current_state; + extern array audioArray; extern anshub::AudioOut music; extern string currentMusic;