olcPixelGameEngine v2.28
The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects
Loading...
Searching...
No Matches
olcPGEX_SplashScreen.h
Go to the documentation of this file.
1/*
2 olcPGEX_SplashScreen.h
3
4 +-------------------------------------------------------------+
5 | OneLoneCoder Pixel Game Engine Extension |
6 | Splash Screen v1.0 |
7 +-------------------------------------------------------------+
8
9 NOTE: UNDER ACTIVE DEVELOPMENT - THERE ARE BUGS/GLITCHES
10
11 What is this?
12 ~~~~~~~~~~~~~
13 This extension produces an animated splashscreen and copyright notice
14 at the beginning of a PGE application, for the purposes of remaining
15 OLC-3 compliant should it be ambiguous in your deployment.
16
17 License (OLC-3)
18 ~~~~~~~~~~~~~~~
19
20 Copyright 2018 - 2024 OneLoneCoder.com
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions
24 are met:
25
26 1. Redistributions or derivations of source code must retain the above
27 copyright notice, this list of conditions and the following disclaimer.
28
29 2. Redistributions or derivative works in binary form must reproduce
30 the above copyright notice. This list of conditions and the following
31 disclaimer must be reproduced in the documentation and/or other
32 materials provided with the distribution.
33
34 3. Neither the name of the copyright holder nor the names of its
35 contributors may be used to endorse or promote products derived
36 from this software without specific prior written permission.
37
38 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
50 Links
51 ~~~~~
52 YouTube: https://www.youtube.com/javidx9
53 Discord: https://discord.gg/WhwHUMV
54 Twitter: https://www.twitter.com/javidx9
55 Twitch: https://www.twitch.tv/javidx9
56 GitHub: https://www.github.com/onelonecoder
57 Homepage: https://www.onelonecoder.com
58
59 Author
60 ~~~~~~
61 David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022, 2023, 2024
62
63 Revisions:
64 1.00: Initial Release
65*/
66
67#pragma once
68
69#include "olcPixelGameEngine.h"
70
71namespace olc
72{
73 class SplashScreen : public olc::PGEX
74 {
75 public:
77
78 protected:
79 virtual void OnAfterUserCreate() override;
80 virtual bool OnBeforeUserUpdate(float& fElapsedTime) override;
81
82 private:
84 std::vector<std::pair<olc::vf2d, olc::vf2d>> vBoom;
85 olc::vf2d vScale;
86 olc::vf2d vPosition;
87 float fParticleTime = 0.0f;
88 float fAspect = 0.0f;
89 bool bComplete = false;
90 };
91
92
93}
94
95#ifdef OLC_PGEX_SPLASHSCREEN
96#undef OLC_PGEX_SPLASHSCREEN
97
98namespace olc
99{
100 SplashScreen::SplashScreen() : olc::PGEX(true)
101 {
102 }
103
105 {
106 const char logo[] =
107 "000000000000000000000000000000000000000000000000000000000000000000005"
108 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED1EE"
109 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED5EEE"
110 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE@E@000"
111 "0000000000000000000000000000000000000000000000000000000000001E1D:ZZZZ"
112 "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ1D5BZZZZZZ"
113 "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ5@E:P0002Z0"
114 "02ZZX000000000000ZP0000000000000000000000000000ZX000Z002XE1DX?o`o:Poo"
115 "800SooaE5@E1ED5BX?ol5E@E0E1ED?oo5@E1ED5DE1D5E@ZQEEBPEE2QD5BSooclZ?olQ"
116 "AB?oo5DEEDEEDE:SooaEEAE5DEEDoolEADEEDEAE5AEEBZ5EE:5EE:5@E:?oo?bXoob55"
117 "8o3lEAEEAD5ADZ?oo5@E5EEAD5Cl01E5AD5AE5DE5@E:X01DXEEDXE1DXo3lo:Sl0800S"
118 "ooaE1ED5EE5BXo00EEDEEE5EE?oo5EE5EE5DEEDEEDZQEEBQD5BQD5BSl?cl0?`0ZZZ?o"
119 "o5D5E@EEDE03loaEEAEEDEEDoolEED5EDEAEEAEEBZ5EE:5@E:5@E:?oo?oloob008o00"
120 "EAEEAD01EE?co5EE5EEAD03l01DE@05AE5AE5@0:XE000EEDXE1DXooloocoo8DDSlZQE"
121 "5EE5EE5EDoolE1DE4E5EE?oo5AE5EE5DE5DEEDZQEEAAEEBQD5BPoo3oo3olQAB?bZ5DE"
122 "1D5EDEE@ooaD5AD1D5EDoolE1DEE@EAD5@EEBZ5EE51ED:5@E:P000000020080:X0000"
123 "00000000000000000000000000000000000:X0000002XE1DZZZZZZZZZZZZZZZZZZZZZ"
124 "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZQD5@ZZZZZZZZZZZZZZZZZZZZZZ"
125 "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZX5@E@00000000000000000000000"
126 "00000000000000000000000000000000000000001E1EEEEEEEEEEEEEEEEEEEEEEEEEE"
127 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED5EEEEEEEEEEEEEEEEEEEEEEEEEEE"
128 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE@5EEEEEEEEEEEEEEEEEEEEEEEEEEEE"
129 "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED0000000000000000000000000000000"
130 "0000000000000000000000000000000000000";
131
132 spr.Create(203, 24);
133 int px = 0, py = 0;
134 for (size_t b = 0; b < 1624; b += 4)
135 {
136 uint32_t sym1 = (uint32_t)logo[b + 0] - 48;
137 uint32_t sym2 = (uint32_t)logo[b + 1] - 48;
138 uint32_t sym3 = (uint32_t)logo[b + 2] - 48;
139 uint32_t sym4 = (uint32_t)logo[b + 3] - 48;
140 uint32_t r = sym1 << 18 | sym2 << 12 | sym3 << 6 | sym4;
141
142 for (int i = 0; i < 12; i++)
143 {
145 switch ((r & 0xC00000) >> 22)
146 {
147 case 0: p = olc::Pixel(0, 0, 0, 255); break;
148 case 1: p = olc::Pixel(255, 255, 255, 255); break;
149 case 2: p = olc::Pixel(255, 120, 26, 255); break;
150 case 3: p = olc::Pixel(79, 193, 255, 255); break;
151 }
152 spr.Sprite()->SetPixel(px, py, p);
153 if (++px == 203) { py++; px = 0; }
154 r <<= 2;
155 }
156 }
157
158 spr.Decal()->Update();
159 vBoom.resize(spr.Sprite()->width * spr.Sprite()->height);
160 vScale = { float(pge->ScreenWidth()) / 500.0f, float(pge->ScreenWidth()) / 500.0f };
161 fAspect = float(pge->ScreenWidth()) / float(pge->ScreenHeight());
162 vPosition = olc::vf2d(
163 (250 - spr.Sprite()->width) / 2.0f,
164 (250 - spr.Sprite()->height) / 2.0f / fAspect);
165 for (int y = 0; y < spr.Sprite()->height; y++)
166 for (int x = 0; x < spr.Sprite()->width; x++)
167 vBoom[y * spr.Sprite()->width + x] = std::make_pair(
168 vPosition + olc::vf2d(float(x), float(y)),
169 olc::vf2d(
170 (float(rand()) / float(RAND_MAX)) * 10.0f - 5.0f,
171 (float(rand()) / float(RAND_MAX)) * 10.0f - 5.0f)
172 );
173 }
174
175 bool SplashScreen::OnBeforeUserUpdate(float& fElapsedTime)
176 {
177 if (bComplete) return false;
178
179 fParticleTime += fElapsedTime;
180
181 for (int y = 0; y < spr.Sprite()->height; y++)
182 for (int x = 0; x < spr.Sprite()->width; x++)
183 {
184
185
186 if (fParticleTime < 1.0f)
187 {
188
189 }
190 else if (fParticleTime < 2.0f)
191 {
192 vBoom[y * spr.Sprite()->width + x].first =
193 olc::vf2d(
194 (250 - spr.Sprite()->width) / 2.0f + float(x),
195 (250 - spr.Sprite()->height) / 2.0f / fAspect + float(y)
196 ) +
197 olc::vf2d(
198 (float(rand()) / float(RAND_MAX)) * 0.5f - 0.25f,
199 (float(rand()) / float(RAND_MAX)) * 0.5f - 0.25f);
200 }
201 else if(fParticleTime < 5.0f)
202 {
203 vBoom[y * spr.Sprite()->width + x].first += vBoom[y * spr.Sprite()->width + x].second * fElapsedTime * 20.0f;
204 }
205 else
206 {
207 bComplete = true;
208 }
209
210 pge->DrawPartialDecal(vScale * vBoom[y * spr.Sprite()->width + x].first * 2.0f, spr.Decal(), olc::vf2d(float(x), float(y)), { 1, 1 }, vScale * 2.0f, olc::PixelF(1.0f, 1.0f, 1.0f, std::min(1.0f, std::max(4.0f - fParticleTime, 0.0f))));
211 }
212
213 olc::vi2d vSize = pge->GetTextSizeProp("Copyright OneLoneCoder.com 2024");
214 pge->DrawStringPropDecal(olc::vf2d(float(pge->ScreenWidth()/2) - vSize.x/2, float(pge->ScreenHeight()) - vSize.y * 3.0f), "Copyright OneLoneCoder.com 2024", olc::PixelF(1.0f, 1.0f, 1.0f, 0.5f), olc::vf2d(1.0, 2.0f));
215 return true;
216 }
217
218}
219
220#endif
void Update()
Definition olcPixelGameEngine.h:1615
static PixelGameEngine * pge
Definition olcPixelGameEngine.h:1627
void DrawStringPropDecal(const olc::vf2d &pos, const std::string &sText, const Pixel col=olc::WHITE, const olc::vf2d &scale={ 1.0f, 1.0f })
void DrawPartialDecal(const olc::vf2d &pos, olc::Decal *decal, const olc::vf2d &source_pos, const olc::vf2d &source_size, const olc::vf2d &scale={ 1.0f, 1.0f }, const olc::Pixel &tint=olc::WHITE)
int32_t ScreenWidth() const
olc::vi2d GetTextSizeProp(const std::string &s)
int32_t ScreenHeight() const
Definition olcPixelGameEngine.h:1125
void Create(uint32_t width, uint32_t height, bool filter=false, bool clamp=true)
olc::Sprite * Sprite() const
olc::Decal * Decal() const
Definition olcPGEX_SplashScreen.h:74
virtual void OnAfterUserCreate() override
virtual bool OnBeforeUserUpdate(float &fElapsedTime) override
bool SetPixel(int32_t x, int32_t y, Pixel p)
int32_t height
Definition olcPixelGameEngine.h:1060
int32_t width
Definition olcPixelGameEngine.h:1059
Definition olcPixelGameEngine.h:593
Pixel PixelF(float red, float green, float blue, float alpha=1.0f)
v_2d< float > vf2d
Definition olcPixelGameEngine.h:894
static const Pixel RED(255, 0, 0)
Definition olcPixelGameEngine.h:924
T x
Definition olcPixelGameEngine.h:604
T y
Definition olcPixelGameEngine.h:606