├── tools
└── wasm
│ ├── README.md
│ ├── basic_template.html
│ └── pge2wasm.bat
├── examples
├── TEST_Patches.cpp
├── TEST_Shaders.cpp
├── TEST_Animate2D.cpp
├── TEST_Camera2D.cpp
├── TEST_Hardware3D.cpp
└── TEST_QuickGUI.cpp
├── extensions
├── olcPGEX_Shaders.h
├── olcPGEX_SplashScreen.h
├── olcPGEX_Wireframe.h
├── olcPGEX_Graphics2D.h
├── olcPGEX_PopUpMenu.h
├── olcPGEX_RayCastWorld.h
├── olcPGEX_Sound.h
├── olcPGEX_TransformedView.h
└── olcPGEX_Network.h
├── utilities
├── olcUTIL_Camera2D.h
├── olcUTIL_DataFile.h
├── olcUTIL_Palette.h
├── olcUTIL_QuadTree.h
├── olcUTIL_Animate2D.h
└── olcUTIL_Container.h
├── .gitignore
├── olcExampleProgram.cpp
├── LICENCE.md
├── contributions
└── README.md
└── README.md
/tools/wasm/README.md:
--------------------------------------------------------------------------------
1 | Coming Soon, information on using olc::PixelGameEngine in web browsers
2 |
--------------------------------------------------------------------------------
/examples/TEST_Patches.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/examples/TEST_Patches.cpp
--------------------------------------------------------------------------------
/examples/TEST_Shaders.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/examples/TEST_Shaders.cpp
--------------------------------------------------------------------------------
/examples/TEST_Animate2D.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/examples/TEST_Animate2D.cpp
--------------------------------------------------------------------------------
/examples/TEST_Camera2D.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/examples/TEST_Camera2D.cpp
--------------------------------------------------------------------------------
/examples/TEST_Hardware3D.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/examples/TEST_Hardware3D.cpp
--------------------------------------------------------------------------------
/examples/TEST_QuickGUI.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/examples/TEST_QuickGUI.cpp
--------------------------------------------------------------------------------
/extensions/olcPGEX_Shaders.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/extensions/olcPGEX_Shaders.h
--------------------------------------------------------------------------------
/utilities/olcUTIL_Camera2D.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/utilities/olcUTIL_Camera2D.h
--------------------------------------------------------------------------------
/utilities/olcUTIL_DataFile.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/utilities/olcUTIL_DataFile.h
--------------------------------------------------------------------------------
/utilities/olcUTIL_Palette.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/utilities/olcUTIL_Palette.h
--------------------------------------------------------------------------------
/utilities/olcUTIL_QuadTree.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/utilities/olcUTIL_QuadTree.h
--------------------------------------------------------------------------------
/utilities/olcUTIL_Animate2D.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/utilities/olcUTIL_Animate2D.h
--------------------------------------------------------------------------------
/utilities/olcUTIL_Container.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneLoneCoder/olcPixelGameEngine/HEAD/utilities/olcUTIL_Container.h
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | /.vs
6 | /utilities/olcUTIL_AffineView.h
7 | /utilities/olcUTIL_Maths.h
8 | /utilities/olcUTIL_GameMode.h
9 | /utilities/olcUTIL_Sparkles.h
10 |
--------------------------------------------------------------------------------
/olcExampleProgram.cpp:
--------------------------------------------------------------------------------
1 | #define OLC_PGE_APPLICATION
2 | #include "olcPixelGameEngine.h"
3 |
4 | class Example : public olc::PixelGameEngine
5 | {
6 | public:
7 | Example()
8 | {
9 | sAppName = "Example";
10 | }
11 |
12 | public:
13 | bool OnUserCreate() override
14 | {
15 | // Called once at the start, so create things here
16 | return true;
17 | }
18 |
19 | bool OnUserUpdate(float fElapsedTime) override
20 | {
21 | // called once per frame
22 | for (int x = 0; x < ScreenWidth(); x++)
23 | for (int y = 0; y < ScreenHeight(); y++)
24 | Draw(x, y, olc::Pixel(rand() % 255, rand() % 255, rand()% 255));
25 | return true;
26 | }
27 | };
28 |
29 |
30 | int main()
31 | {
32 | Example demo;
33 | if (demo.Construct(256, 240, 4, 4))
34 | demo.Start();
35 |
36 | return 0;
37 | }
38 |
--------------------------------------------------------------------------------
/LICENCE.md:
--------------------------------------------------------------------------------
1 | # License (OLC-3)
2 |
3 | Copyright 2018-2023 OneLoneCoder.com
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions
7 | are met:
8 |
9 | 1. Redistributions or derivations of source code must retain the above
10 | copyright notice, this list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions or derivative works in binary form must reproduce
13 | the above copyright notice. This list of conditions and the following
14 | disclaimer must be reproduced in the documentation and/or other
15 | materials provided with the distribution.
16 |
17 | 3. Neither the name of the copyright holder nor the names of its
18 | contributors may be used to endorse or promote products derived
19 | from this software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
--------------------------------------------------------------------------------
/tools/wasm/basic_template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Emscripten-Generated Code
9 |
18 |
19 |
20 |
21 |
37 | {{{ SCRIPT }}}
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/contributions/README.md:
--------------------------------------------------------------------------------
1 | # 3rd Party Contributions
2 |
3 | These source code contributions enhance the functionality of the olcPixelGameEngine header file. They are not supported by OneLoneCoder.com or javidx9 so use them at your own risk! Though this is a nice community and to get listed here you have to be trusted...
4 |
5 | ## PixelGameEngine Extensions (PGEX)
6 | * Adds a "stencil buffer" like viewport to drawing functions
7 | * https://github.com/gorbit99/olcPGEX_ViewPort
8 | * Cross Platform Controller Support
9 | * https://github.com/gorbit99/olcPGEX_Gamepad
10 | * General Font Rendering
11 | * https://github.com/gorbit99/olcPGEX_TTF
12 | * Widens support for audio files into olcPGEX_Sound.h
13 | * https://github.com/gorbit99/olcPGEX_AudioConvert
14 | * Sprite Animation, Sprite State Machine and Sprite Sheet Manipulation
15 | * https://github.com/matt-hayward/olcPGEX_AnimatedSprite
16 | * Additional colour constants
17 | * https://github.com/matt-hayward/olcPGEX_AdditionalColours
18 | * Various Sprite Handling & Camera Control Utilities
19 | * https://github.com/justinrichardsmusic/PGEv2_Extensions
20 | * DearImGUI Integration
21 | * https://github.com/dandistine/olcPGEDearImGui
22 | * Pre-loaded Font Rendering
23 | * https://github.com/Oso-Grande/olcPGEX_Font
24 | * Arc Drawing
25 | * https://github.com/AlterEgoIV/olcPGEX_Arc
26 | * Audio/Video Playback
27 | * https://github.com/Piratux/olcPGEX_Media
28 |
29 | ## MacOS Support
30 | * These will potentially be absorbed into main build
31 | * https://github.com/MumflrFumperdink/olcPGEMac
32 |
33 | ## Android & IOS Support
34 | * Fiddlier to setup, but pretty cool once going
35 | * https://github.com/Johnnyg63/OLCPGEMobileVisualStudio
36 |
37 | ## Build Systems
38 | * Meson (https://mesonbuild.com/index.html)
39 | * https://github.com/jpakkane/pixeldemo
40 | * CMake script
41 | * https://github.com/plane000/olcPixelGameEngine/blob/master/CMakeLists.txt
42 | * CMake script for all includes Emscripten/WASM/Webby stuff
43 | * https://github.com/L0huis/PGE-CMake
44 |
45 | ## Utilities
46 | * Additional fonts and font handling tools
47 | * https://github.com/gorbit99/OLC-Font
48 | * Convert olcConsoleGameEngine ".spr" files into olc::Sprite types
49 | * https://github.com/gorbit99/SprConverter
50 |
51 | ## Customisations
52 | * Version with SDL backend, and native controller support
53 | * https://github.com/Allersnj/olcPixelGameEngineSDL
54 |
55 | ## Cool Projects
56 | Have you made something using olcPixelGameEngine? Contact me to get a link to it here!
57 |
--------------------------------------------------------------------------------
/tools/wasm/pge2wasm.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | :: Convenience Utility to build projects using olc::PixelGameEngine, using
3 | :: Emscripten, producing WASM based output.
4 | ::
5 | :: OneLoneCoder.com 2021 - Released under OLC-3 license
6 | ::
7 | :: v1.00: Initial Release
8 |
9 | setlocal enabledelayedexpansion enableextensions
10 |
11 | :: Customize here ===========================================
12 |
13 | :: Location of Emscripten SDK
14 | set EMSDK="e:\pge_ems\emsdk\"
15 |
16 | :: Location of olc::PixelGameEngine header file
17 | set OLCPGE=".\"
18 | set OLCPGE="e:\pge_dev\olcPixelGameEngine_dev\Deploy"
19 |
20 | :: ==========================================================
21 |
22 | set WORKINGDIR=%CD%
23 |
24 | if not exist %EMSDK% (
25 | echo Error: No Emscripten SDK folder found!
26 | goto :fail
27 | )
28 |
29 | if not exist %OLCPGE% (
30 | echo Error: Invalid PGE Location!
31 | goto :fail
32 | )
33 |
34 | if "%1"=="build" goto :build
35 | if "%1"=="run" goto :run
36 | if "%1"=="clean" goto :clean
37 | goto :error
38 |
39 | :build
40 | :: Configure path variables
41 | cd %EMSDK%
42 | call emsdk_env.bat
43 |
44 | :: Create working folder
45 | cd %WORKINGDIR%
46 | if not exist ".\WASM" (
47 | echo Creating .\WASM output folder
48 | mkdir ".\WASM"
49 | )
50 |
51 | :: Grab all cpp files if no specific file is given
52 | if "%~2"=="" goto :graball
53 | set CPP=%~2
54 | goto :embuild
55 |
56 | :graball
57 | echo Gathering *.cpp files from
58 | echo %CD%
59 | set CPP=
60 | for %%x in (%CD%\*.cpp) do set CPP=!CPP! %%x
61 | set CPP=%CPP:~1%
62 |
63 | :embuild
64 |
65 | echo %CPP%
66 | if exist "./assets" (
67 | echo Starting Build with assets...
68 | call em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 %CPP% -o .\WASM\pge.html -I %OLCPGE% --preload-file .\assets
69 | ) else (
70 | echo Starting Build without assets...
71 | call em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 %CPP% -o .\WASM\pge.html -I %OLCPGE%
72 | )
73 |
74 | echo Build Completed
75 | goto :success
76 |
77 | :run
78 | :: Configure path variables
79 | cd %EMSDK%
80 | call emsdk_env.bat
81 | cd %WORKINGDIR%
82 | emrun .\WASM\pge.html
83 | goto :success
84 |
85 | :clean
86 | if exist ".\WASM" (
87 | rmdir /s /q .\WASM
88 | )
89 | goto :success
90 |
91 | :error
92 | echo Error: Incorrect Input
93 | goto :fail
94 |
95 | :success
96 | echo Exit With Success
97 | goto :leave
98 |
99 | :fail
100 | echo Exit with Failure
101 | goto :leave
102 |
103 | :leave
104 | exit
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hang on! I'm looking for Javidx9's video source code! It's moved here: https://github.com/OneLoneCoder/Javidx9
5 |
6 | # Shameless Promotion
7 | There is a feature rich and working fork of this repo aimed at Android & IOS development: https://github.com/Johnnyg63/OLCPGEMobileVisualStudio
8 |
9 | # olcPixelGameEngine
10 | The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects.
11 |
12 | **You only need the one file - olcPixelGameEngine.h - included in your project!**
13 |
14 | Provides a fast, richly featured, cross platform pixel drawing and user interface framework for
15 | * The development of games
16 | * Visualisation of algorithms
17 | * Prototyping and experimentation
18 | * Education
19 |
20 | olcPixelGameEngine is easily extended! for example:
21 | * 2D Affine transforms
22 | * 3D Software renderer
23 | * Controller input
24 | * Sound
25 | * Hardware interfaces
26 |
27 | olcPixelGameEngine is easy to port! Runs on:
28 | * Windows (all)
29 | * Linux / Raspberry Pi / ChromeOS
30 | * MacOS (coming soon to official, but already available in "Contributors")
31 | * PSP & Switch (Not supported by OneLoneCoder)
32 |
33 | olcPixelGameEngine has been reimplemented in other languages!
34 | * C#
35 | * Rust
36 | * Lua
37 | * Java
38 |
39 | olcPixelGameEngine is actively maintained and developed!
40 |
41 | olcPixelGameEngine is used by 100s, if not 1000s of programmers at all levels of ability!
42 |
43 |
44 | # Documentation
45 | Please see https://github.com/OneLoneCoder/olcPixelGameEngine/wiki
46 |
47 | # License (OLC-3)
48 | Copyright 2018 - 2024 OneLoneCoder.com
49 |
50 | Redistribution and use in source and binary forms, with or without
51 | modification, are permitted provided that the following conditions
52 | are met:
53 |
54 | 1. Redistributions or derivations of source code must retain the above
55 | copyright notice, this list of conditions and the following disclaimer.
56 |
57 | 2. Redistributions or derivative works in binary form must reproduce
58 | the above copyright notice. This list of conditions and the following
59 | disclaimer must be reproduced in the documentation and/or other
60 | materials provided with the distribution.
61 |
62 | 3. Neither the name of the copyright holder nor the names of its
63 | contributors may be used to endorse or promote products derived
64 | from this software without specific prior written permission.
65 |
66 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
67 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
68 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
69 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
70 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
71 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
72 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
73 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
74 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
75 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
76 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77 |
--------------------------------------------------------------------------------
/extensions/olcPGEX_SplashScreen.h:
--------------------------------------------------------------------------------
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 |
71 | namespace olc
72 | {
73 | class SplashScreen : public olc::PGEX
74 | {
75 | public:
76 | SplashScreen();
77 |
78 | protected:
79 | virtual void OnAfterUserCreate() override;
80 | virtual bool OnBeforeUserUpdate(float& fElapsedTime) override;
81 |
82 | private:
83 | olc::Renderable spr;
84 | std::vector> 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 |
98 | namespace olc
99 | {
100 | SplashScreen::SplashScreen() : olc::PGEX(true)
101 | {
102 | }
103 |
104 | void SplashScreen::OnAfterUserCreate()
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 | {
144 | olc::Pixel p = olc::RED;
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 2025");
214 | pge->DrawStringPropDecal(olc::vf2d(float(pge->ScreenWidth()/2) - vSize.x/2, float(pge->ScreenHeight()) - vSize.y * 3.0f), "Copyright OneLoneCoder.com 2025", 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
--------------------------------------------------------------------------------
/extensions/olcPGEX_Wireframe.h:
--------------------------------------------------------------------------------
1 | /*
2 | olcPGEX_Wireframe.h
3 |
4 | +-------------------------------------------------------------+
5 | | OneLoneCoder Pixel Game Engine Extension |
6 | | Wireframe v1.0 |
7 | +-------------------------------------------------------------+
8 |
9 | NOTE: UNDER ACTIVE DEVELOPMENT - THERE ARE BUGS/GLITCHES
10 |
11 | What is this?
12 | ~~~~~~~~~~~~~
13 | This extension provides drawing routines giving simple wireframe
14 | shapes and models constructed in a transform hierachy
15 |
16 | License (OLC-3)
17 | ~~~~~~~~~~~~~~~
18 |
19 | Copyright 2018 - 2022 OneLoneCoder.com
20 |
21 | Redistribution and use in source and binary forms, with or without
22 | modification, are permitted provided that the following conditions
23 | are met:
24 |
25 | 1. Redistributions or derivations of source code must retain the above
26 | copyright notice, this list of conditions and the following disclaimer.
27 |
28 | 2. Redistributions or derivative works in binary form must reproduce
29 | the above copyright notice. This list of conditions and the following
30 | disclaimer must be reproduced in the documentation and/or other
31 | materials provided with the distribution.
32 |
33 | 3. Neither the name of the copyright holder nor the names of its
34 | contributors may be used to endorse or promote products derived
35 | from this software without specific prior written permission.
36 |
37 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 |
49 | Links
50 | ~~~~~
51 | YouTube: https://www.youtube.com/javidx9
52 | Discord: https://discord.gg/WhwHUMV
53 | Twitter: https://www.twitter.com/javidx9
54 | Twitch: https://www.twitch.tv/javidx9
55 | GitHub: https://www.github.com/onelonecoder
56 | Homepage: https://www.onelonecoder.com
57 |
58 | Author
59 | ~~~~~~
60 | David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022
61 |
62 | Revisions:
63 | 1.00: Initial Release
64 |
65 | */
66 |
67 | #pragma once
68 | #ifndef OLC_PGEX_WIREFRAME_H
69 | #define OLC_PGEX_WIREFRAME_H
70 |
71 | #include "olcPixelGameEngine.h"
72 |
73 | namespace olc
74 | {
75 | #ifndef OLC_MAT3_DESC
76 | #define OLC_MAT3_DESC
77 | template
78 | struct mat3_generic
79 | {
80 | std::array m{ 0 };
81 | constexpr size_t idx(size_t r, size_t c) const { return r * 3 + c; }
82 | T& operator()(size_t row, size_t col) { return m[idx(row, col)]; }
83 | const T& operator()(size_t row, size_t col) const { return m[idx(row, col)]; }
84 | mat3_generic() { identity(); }
85 | mat3_generic(const mat3_generic& m) = default;
86 | mat3_generic& operator=(const mat3_generic& m) = default;
87 |
88 | void clear() { std::fill(m.begin(), m.end(), T(0)); }
89 | void identity() { clear(); (*this)(0, 0) = 1; (*this)(1, 1) = 1; (*this)(2, 2) = 1; }
90 |
91 | void translate(float x, float y) { identity(); auto& m = (*this); m(2, 0) = x; m(2, 1) = y; }
92 | void translate(const olc::v2d_generic& v) { translate(v.x, v.y); }
93 | void scale(float x, float y) { identity(); auto& m = (*this); m(0, 0) = x; m(1, 1) = y; }
94 | void scale(const olc::v2d_generic& v) { return scale(v.x, v.y); }
95 | void rotate(float a) { identity(); auto& m = (*this); m(0, 0) = cos(a); m(0, 1) = sin(a); m(1, 0) = -m(0, 1); m(1, 1) = m(0, 0); }
96 |
97 | olc::v2d_generic operator * (const olc::v2d_generic& v) const
98 | {
99 | auto& m = *this;
100 | olc::v2d_generic vOut;
101 | vOut.x = m(0, 0) * v.x + m(1, 0) * v.y + m(2, 0) * T(1);
102 | vOut.y = m(0, 1) * v.x + m(1, 1) * v.y + m(2, 1) * T(1);
103 | T z = m(0, 2) * v.x + m(1, 2) * v.y + m(2, 2) * T(1);
104 | return (vOut / z);
105 | }
106 |
107 | mat3_generic operator * (const mat3_generic& rhs) const
108 | {
109 | auto& m = *this;
110 | mat3_generic out;
111 | for (size_t c = 0; c < 3; c++)
112 | for (size_t r = 0; r < 3; r++)
113 | out(r, c) = m(r, 0) * rhs(0, c) + m(r, 1) * rhs(1, c) + m(r, 2) * rhs(2, c);
114 | return out;
115 | }
116 | };
117 |
118 | typedef mat3_generic Matrix2D;
119 | #endif
120 |
121 | namespace wire
122 | {
123 | typedef std::vector Mesh;
124 | //Mesh NullMesh;
125 |
126 | class Model
127 | {
128 | public:
129 | static constexpr uint8_t DRAW_ORIGIN = 0x01;
130 | static constexpr uint8_t DRAW_NODES = 0x02;
131 | static constexpr uint8_t DRAW_MEASURES = 0x04;
132 | public:
133 | Model() = default;
134 |
135 | public:
136 | void Attach(Model* child, const olc::vf2d& position = { 0.0f, 0.0f }, const float angle = 0.0f);
137 | void SetRotation(const float angle);
138 | void SetPosition(const olc::vf2d& position);
139 | void UpdateInWorld(const Matrix2D& matParent);
140 | olc::vf2d LocalToWorld(const olc::vf2d& local);
141 | void SetMesh(const Mesh& mesh);
142 | const Mesh& GetWorldPoints() const;
143 | const std::vector& GetChildren() const;
144 |
145 | protected:
146 | Mesh vLocalPoints;;
147 | Mesh vWorldPoints;
148 | olc::Matrix2D matLocalTranslation;
149 | olc::Matrix2D matLocalRotation;
150 | olc::Matrix2D matLocal;
151 | olc::Matrix2D matWorld;
152 |
153 | protected:
154 | std::vector vChildren;
155 | };
156 |
157 |
158 |
159 | inline const Mesh MeshCircle(const float fRadius, const int nPoints = 100)
160 | {
161 | Mesh m;
162 | for (int i = 0; i < nPoints; i++)
163 | {
164 | float fTheta = (float(i) / float(nPoints)) * 2.0f * 3.14159f;
165 | m.push_back(olc::vf2d{ cos(fTheta), sin(fTheta) } *fRadius);
166 | }
167 | return m;
168 | }
169 |
170 | inline const Mesh MeshRectangle(const olc::vf2d& size, const olc::vf2d& offset = { 0.0f, 0.0f })
171 | {
172 | return { -offset, {-offset.x + size.x, -offset.y}, -offset + size, {-offset.x, -offset.y + size.y} };
173 | }
174 |
175 | inline const Mesh MeshGear(const int nTeeth, const float fOuterRadius, const float fInnerRadius)
176 | {
177 | Mesh m;
178 | for (int i = 0; i < nTeeth * 4; i++)
179 | {
180 | float fTheta = (float(i) / float(nTeeth * 4)) * 2.0f * 3.14159f;
181 | m.push_back(olc::vf2d{ cos(fTheta), sin(fTheta) } * 2.0f * (float((i / 2) % 2) ? fOuterRadius : fInnerRadius));
182 | }
183 | return m;
184 | }
185 |
186 | template
187 | void DrawModel(T& render, Model& m, const olc::Pixel col = olc::BLACK, const uint8_t flags = -1)
188 | {
189 | const auto& points = m.GetWorldPoints();
190 | for(size_t i = 0; i < points.size(); i++)
191 | render.DrawLine(points[i], points[(i+1)%points.size()], col);
192 |
193 | // Draw Nodes
194 | if (flags & Model::DRAW_NODES)
195 | for (size_t i = 0; i < points.size(); i++)
196 | render.FillCircle(points[i], render.ScaleToWorld({ 3,3 }).x, olc::RED);
197 |
198 | if (flags & Model::DRAW_ORIGIN)
199 | {
200 | render.FillCircle(m.LocalToWorld({ 0,0 }), render.ScaleToWorld({ 3,3 }).x, olc::BLUE);
201 | render.DrawLine(
202 | m.LocalToWorld({ 0,0 }),
203 | m.LocalToWorld(render.ScaleToWorld({ 10, 0 })),
204 | olc::BLUE);
205 | }
206 |
207 | // Draw Children
208 | for (auto& child : m.GetChildren())
209 | DrawModel(render, *child, col, flags);
210 | }
211 |
212 |
213 | }
214 | }
215 |
216 | #ifdef OLC_PGEX_WIREFRAME
217 | #undef OLC_PGEX_WIREFRAME
218 |
219 | namespace olc
220 | {
221 | namespace wire
222 | {
223 | void Model::SetMesh(const Mesh& mesh)
224 | {
225 | vLocalPoints = mesh;
226 | vWorldPoints.clear();
227 | vWorldPoints.resize(vLocalPoints.size());
228 | }
229 |
230 | void Model::SetRotation(const float angle)
231 | {
232 | matLocalRotation.rotate(angle);
233 | matLocal = matLocalRotation * matLocalTranslation;
234 | }
235 |
236 | void Model::SetPosition(const olc::vf2d& position)
237 | {
238 | matLocalTranslation.translate(position);
239 | matLocal = matLocalRotation * matLocalTranslation;
240 | }
241 |
242 | void Model::Attach(Model* child, const olc::vf2d& position, const float angle)
243 | {
244 | if (child != nullptr)
245 | {
246 | child->SetPosition(position);
247 | child->SetRotation(angle);
248 | vChildren.push_back(child);
249 | }
250 | }
251 |
252 | olc::vf2d Model::LocalToWorld(const olc::vf2d& local)
253 | {
254 | return matWorld * local;
255 | }
256 |
257 | const Mesh& Model::GetWorldPoints() const
258 | {
259 | return vWorldPoints;
260 | }
261 |
262 | const std::vector& Model::GetChildren() const
263 | {
264 | return vChildren;
265 | }
266 |
267 | void Model::UpdateInWorld(const Matrix2D& matParent)
268 | {
269 | // Propagate matrix transform
270 | matWorld = matLocal * matParent;
271 |
272 | // Transform vertices
273 | for (size_t i = 0; i < vLocalPoints.size(); i++)
274 | {
275 | vWorldPoints[i] = matWorld * vLocalPoints[i];
276 | }
277 |
278 | // Transform Children
279 | for (auto& child : vChildren)
280 | child->UpdateInWorld(matWorld);
281 | }
282 | }
283 | }
284 |
285 | #endif // OLC_PGEX_WIREFRAME
286 | #endif // OLC_PGEX_WIREFRAME_H
287 |
288 |
--------------------------------------------------------------------------------
/extensions/olcPGEX_Graphics2D.h:
--------------------------------------------------------------------------------
1 | /*
2 | olcPGEX_Graphics2D.h
3 |
4 | +-------------------------------------------------------------+
5 | | OneLoneCoder Pixel Game Engine Extension |
6 | | Advanced 2D Rendering - v0.5 |
7 | +-------------------------------------------------------------+
8 |
9 | What is this?
10 | ~~~~~~~~~~~~~
11 | This is an extension to the olcPixelGameEngine, which provides
12 | advanced olc::Sprite manipulation and drawing routines. To use
13 | it, simply include this header file.
14 |
15 | License (OLC-3)
16 | ~~~~~~~~~~~~~~~
17 |
18 | Copyright 2018 - 2019 OneLoneCoder.com
19 |
20 | Redistribution and use in source and binary forms, with or without
21 | modification, are permitted provided that the following conditions
22 | are met:
23 |
24 | 1. Redistributions or derivations of source code must retain the above
25 | copyright notice, this list of conditions and the following disclaimer.
26 |
27 | 2. Redistributions or derivative works in binary form must reproduce
28 | the above copyright notice. This list of conditions and the following
29 | disclaimer must be reproduced in the documentation and/or other
30 | materials provided with the distribution.
31 |
32 | 3. Neither the name of the copyright holder nor the names of its
33 | contributors may be used to endorse or promote products derived
34 | from this software without specific prior written permission.
35 |
36 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 |
48 | Links
49 | ~~~~~
50 | YouTube: https://www.youtube.com/javidx9
51 | Discord: https://discord.gg/WhwHUMV
52 | Twitter: https://www.twitter.com/javidx9
53 | Twitch: https://www.twitch.tv/javidx9
54 | GitHub: https://www.github.com/onelonecoder
55 | Homepage: https://www.onelonecoder.com
56 |
57 | Author
58 | ~~~~~~
59 | David Barr, aka javidx9, ©OneLoneCoder 2019
60 | */
61 |
62 | /*
63 | Matrices stored as [Column][Row] (i.e. x, y)
64 |
65 | |C0R0 C1R0 C2R0| | x | | x'|
66 | |C0R1 C1R1 C2R1| * | y | = | y'|
67 | |C0R2 C1R2 C2R2| |1.0| | - |
68 | */
69 |
70 |
71 |
72 | #ifndef OLC_PGEX_GFX2D
73 | #define OLC_PGEX_GFX2D
74 |
75 | #include
76 |
77 | #include "olcPixelGameEngine.h"
78 |
79 | #undef min
80 | #undef max
81 |
82 | namespace olc
83 | {
84 | // Container class for Advanced 2D Drawing functions
85 | class GFX2D : public olc::PGEX
86 | {
87 | // A representation of an affine transform, used to rotate, scale, offset & shear space
88 | public:
89 | class Transform2D
90 | {
91 | public:
92 | Transform2D();
93 |
94 | public:
95 | // Set this transformation to unity
96 | void Reset();
97 | // Append a rotation of fTheta radians to this transform
98 | void Rotate(float fTheta);
99 | // Append a translation (ox, oy) to this transform
100 | void Translate(float ox, float oy);
101 | // Append a scaling operation (sx, sy) to this transform
102 | void Scale(float sx, float sy);
103 | // Append a shear operation (sx, sy) to this transform
104 | void Shear(float sx, float sy);
105 |
106 | void Perspective(float ox, float oy);
107 | // Calculate the Forward Transformation of the coordinate (in_x, in_y) -> (out_x, out_y)
108 | void Forward(float in_x, float in_y, float &out_x, float &out_y);
109 | // Calculate the Inverse Transformation of the coordinate (in_x, in_y) -> (out_x, out_y)
110 | void Backward(float in_x, float in_y, float &out_x, float &out_y);
111 | // Regenerate the Inverse Transformation
112 | void Invert();
113 |
114 | private:
115 | void Multiply();
116 | float matrix[4][3][3];
117 | int nTargetMatrix;
118 | int nSourceMatrix;
119 | bool bDirty;
120 | };
121 |
122 | public:
123 | // Draws a sprite with the transform applied
124 | static void DrawSprite(olc::Sprite *sprite, olc::GFX2D::Transform2D &transform);
125 | };
126 | }
127 |
128 |
129 | #ifdef OLC_PGEX_GRAPHICS2D
130 | #undef OLC_PGEX_GRAPHICS2D
131 |
132 | namespace olc
133 | {
134 | void GFX2D::DrawSprite(olc::Sprite *sprite, olc::GFX2D::Transform2D &transform)
135 | {
136 | if (sprite == nullptr)
137 | return;
138 |
139 | // Work out bounding rectangle of sprite
140 | float ex, ey;
141 | float sx, sy;
142 | float px, py;
143 |
144 | transform.Forward(0.0f, 0.0f, sx, sy);
145 | px = sx; py = sy;
146 | sx = std::min(sx, px); sy = std::min(sy, py);
147 | ex = std::max(ex, px); ey = std::max(ey, py);
148 |
149 | transform.Forward((float)sprite->width, (float)sprite->height, px, py);
150 | sx = std::min(sx, px); sy = std::min(sy, py);
151 | ex = std::max(ex, px); ey = std::max(ey, py);
152 |
153 | transform.Forward(0.0f, (float)sprite->height, px, py);
154 | sx = std::min(sx, px); sy = std::min(sy, py);
155 | ex = std::max(ex, px); ey = std::max(ey, py);
156 |
157 | transform.Forward((float)sprite->width, 0.0f, px, py);
158 | sx = std::min(sx, px); sy = std::min(sy, py);
159 | ex = std::max(ex, px); ey = std::max(ey, py);
160 |
161 | // Perform inversion of transform if required
162 | transform.Invert();
163 |
164 | if (ex < sx)
165 | std::swap(ex, sx);
166 | if (ey < sy)
167 | std::swap(ey, sy);
168 |
169 | // Iterate through render space, and sample Sprite from suitable texel location
170 | for (float i = sx; i < ex; i++)
171 | {
172 | for (float j = sy; j < ey; j++)
173 | {
174 | float ox, oy;
175 | transform.Backward(i, j, ox, oy);
176 | pge->Draw((int32_t)i, (int32_t)j, sprite->GetPixel((int32_t)(ox+0.5f), (int32_t)(oy+0.5f)));
177 | }
178 | }
179 | }
180 |
181 | olc::GFX2D::Transform2D::Transform2D()
182 | {
183 | Reset();
184 | }
185 |
186 | void olc::GFX2D::Transform2D::Reset()
187 | {
188 | nTargetMatrix = 0;
189 | nSourceMatrix = 1;
190 | bDirty = true;
191 |
192 | // Columns Then Rows
193 |
194 | // Matrices 0 & 1 are used as swaps in Transform accumulation
195 | matrix[0][0][0] = 1.0f; matrix[0][1][0] = 0.0f; matrix[0][2][0] = 0.0f;
196 | matrix[0][0][1] = 0.0f; matrix[0][1][1] = 1.0f; matrix[0][2][1] = 0.0f;
197 | matrix[0][0][2] = 0.0f; matrix[0][1][2] = 0.0f; matrix[0][2][2] = 1.0f;
198 |
199 | matrix[1][0][0] = 1.0f; matrix[1][1][0] = 0.0f; matrix[1][2][0] = 0.0f;
200 | matrix[1][0][1] = 0.0f; matrix[1][1][1] = 1.0f; matrix[1][2][1] = 0.0f;
201 | matrix[1][0][2] = 0.0f; matrix[1][1][2] = 0.0f; matrix[1][2][2] = 1.0f;
202 |
203 | // Matrix 2 is a cache matrix to hold the immediate transform operation
204 | // Matrix 3 is a cache matrix to hold the inverted transform
205 | }
206 |
207 | void olc::GFX2D::Transform2D::Multiply()
208 | {
209 | for (int c = 0; c < 3; c++)
210 | {
211 | for (int r = 0; r < 3; r++)
212 | {
213 | matrix[nTargetMatrix][c][r] = matrix[2][0][r] * matrix[nSourceMatrix][c][0] +
214 | matrix[2][1][r] * matrix[nSourceMatrix][c][1] +
215 | matrix[2][2][r] * matrix[nSourceMatrix][c][2];
216 | }
217 | }
218 |
219 | std::swap(nTargetMatrix, nSourceMatrix);
220 | bDirty = true; // Any transform multiply dirties the inversion
221 | }
222 |
223 | void olc::GFX2D::Transform2D::Rotate(float fTheta)
224 | {
225 | // Construct Rotation Matrix
226 | matrix[2][0][0] = cosf(fTheta); matrix[2][1][0] = sinf(fTheta); matrix[2][2][0] = 0.0f;
227 | matrix[2][0][1] = -sinf(fTheta); matrix[2][1][1] = cosf(fTheta); matrix[2][2][1] = 0.0f;
228 | matrix[2][0][2] = 0.0f; matrix[2][1][2] = 0.0f; matrix[2][2][2] = 1.0f;
229 | Multiply();
230 | }
231 |
232 | void olc::GFX2D::Transform2D::Scale(float sx, float sy)
233 | {
234 | // Construct Scale Matrix
235 | matrix[2][0][0] = sx; matrix[2][1][0] = 0.0f; matrix[2][2][0] = 0.0f;
236 | matrix[2][0][1] = 0.0f; matrix[2][1][1] = sy; matrix[2][2][1] = 0.0f;
237 | matrix[2][0][2] = 0.0f; matrix[2][1][2] = 0.0f; matrix[2][2][2] = 1.0f;
238 | Multiply();
239 | }
240 |
241 | void olc::GFX2D::Transform2D::Shear(float sx, float sy)
242 | {
243 | // Construct Shear Matrix
244 | matrix[2][0][0] = 1.0f; matrix[2][1][0] = sx; matrix[2][2][0] = 0.0f;
245 | matrix[2][0][1] = sy; matrix[2][1][1] = 1.0f; matrix[2][2][1] = 0.0f;
246 | matrix[2][0][2] = 0.0f; matrix[2][1][2] = 0.0f; matrix[2][2][2] = 1.0f;
247 | Multiply();
248 | }
249 |
250 | void olc::GFX2D::Transform2D::Translate(float ox, float oy)
251 | {
252 | // Construct Translate Matrix
253 | matrix[2][0][0] = 1.0f; matrix[2][1][0] = 0.0f; matrix[2][2][0] = ox;
254 | matrix[2][0][1] = 0.0f; matrix[2][1][1] = 1.0f; matrix[2][2][1] = oy;
255 | matrix[2][0][2] = 0.0f; matrix[2][1][2] = 0.0f; matrix[2][2][2] = 1.0f;
256 | Multiply();
257 | }
258 |
259 | void olc::GFX2D::Transform2D::Perspective(float ox, float oy)
260 | {
261 | // Construct Translate Matrix
262 | matrix[2][0][0] = 1.0f; matrix[2][1][0] = 0.0f; matrix[2][2][0] = 0.0f;
263 | matrix[2][0][1] = 0.0f; matrix[2][1][1] = 1.0f; matrix[2][2][1] = 0.0f;
264 | matrix[2][0][2] = ox; matrix[2][1][2] = oy; matrix[2][2][2] = 1.0f;
265 | Multiply();
266 | }
267 |
268 | void olc::GFX2D::Transform2D::Forward(float in_x, float in_y, float &out_x, float &out_y)
269 | {
270 | out_x = in_x * matrix[nSourceMatrix][0][0] + in_y * matrix[nSourceMatrix][1][0] + matrix[nSourceMatrix][2][0];
271 | out_y = in_x * matrix[nSourceMatrix][0][1] + in_y * matrix[nSourceMatrix][1][1] + matrix[nSourceMatrix][2][1];
272 | float out_z = in_x * matrix[nSourceMatrix][0][2] + in_y * matrix[nSourceMatrix][1][2] + matrix[nSourceMatrix][2][2];
273 | if (out_z != 0)
274 | {
275 | out_x /= out_z;
276 | out_y /= out_z;
277 | }
278 | }
279 |
280 | void olc::GFX2D::Transform2D::Backward(float in_x, float in_y, float &out_x, float &out_y)
281 | {
282 | out_x = in_x * matrix[3][0][0] + in_y * matrix[3][1][0] + matrix[3][2][0];
283 | out_y = in_x * matrix[3][0][1] + in_y * matrix[3][1][1] + matrix[3][2][1];
284 | float out_z = in_x * matrix[3][0][2] + in_y * matrix[3][1][2] + matrix[3][2][2];
285 | if (out_z != 0)
286 | {
287 | out_x /= out_z;
288 | out_y /= out_z;
289 | }
290 | }
291 |
292 | void olc::GFX2D::Transform2D::Invert()
293 | {
294 | if (bDirty) // Obviously costly so only do if needed
295 | {
296 | float det = matrix[nSourceMatrix][0][0] * (matrix[nSourceMatrix][1][1] * matrix[nSourceMatrix][2][2] - matrix[nSourceMatrix][1][2] * matrix[nSourceMatrix][2][1]) -
297 | matrix[nSourceMatrix][1][0] * (matrix[nSourceMatrix][0][1] * matrix[nSourceMatrix][2][2] - matrix[nSourceMatrix][2][1] * matrix[nSourceMatrix][0][2]) +
298 | matrix[nSourceMatrix][2][0] * (matrix[nSourceMatrix][0][1] * matrix[nSourceMatrix][1][2] - matrix[nSourceMatrix][1][1] * matrix[nSourceMatrix][0][2]);
299 |
300 | float idet = 1.0f / det;
301 | matrix[3][0][0] = (matrix[nSourceMatrix][1][1] * matrix[nSourceMatrix][2][2] - matrix[nSourceMatrix][1][2] * matrix[nSourceMatrix][2][1]) * idet;
302 | matrix[3][1][0] = (matrix[nSourceMatrix][2][0] * matrix[nSourceMatrix][1][2] - matrix[nSourceMatrix][1][0] * matrix[nSourceMatrix][2][2]) * idet;
303 | matrix[3][2][0] = (matrix[nSourceMatrix][1][0] * matrix[nSourceMatrix][2][1] - matrix[nSourceMatrix][2][0] * matrix[nSourceMatrix][1][1]) * idet;
304 | matrix[3][0][1] = (matrix[nSourceMatrix][2][1] * matrix[nSourceMatrix][0][2] - matrix[nSourceMatrix][0][1] * matrix[nSourceMatrix][2][2]) * idet;
305 | matrix[3][1][1] = (matrix[nSourceMatrix][0][0] * matrix[nSourceMatrix][2][2] - matrix[nSourceMatrix][2][0] * matrix[nSourceMatrix][0][2]) * idet;
306 | matrix[3][2][1] = (matrix[nSourceMatrix][0][1] * matrix[nSourceMatrix][2][0] - matrix[nSourceMatrix][0][0] * matrix[nSourceMatrix][2][1]) * idet;
307 | matrix[3][0][2] = (matrix[nSourceMatrix][0][1] * matrix[nSourceMatrix][1][2] - matrix[nSourceMatrix][0][2] * matrix[nSourceMatrix][1][1]) * idet;
308 | matrix[3][1][2] = (matrix[nSourceMatrix][0][2] * matrix[nSourceMatrix][1][0] - matrix[nSourceMatrix][0][0] * matrix[nSourceMatrix][1][2]) * idet;
309 | matrix[3][2][2] = (matrix[nSourceMatrix][0][0] * matrix[nSourceMatrix][1][1] - matrix[nSourceMatrix][0][1] * matrix[nSourceMatrix][1][0]) * idet;
310 | bDirty = false;
311 | }
312 | }
313 | }
314 |
315 | #endif
316 | #endif
--------------------------------------------------------------------------------
/extensions/olcPGEX_PopUpMenu.h:
--------------------------------------------------------------------------------
1 | /*
2 | olcPGEX_PopUp.h
3 |
4 | +-------------------------------------------------------------+
5 | | OneLoneCoder Pixel Game Engine Extension |
6 | | Retro PopUp Menu 1.0 |
7 | +-------------------------------------------------------------+
8 |
9 | What is this?
10 | ~~~~~~~~~~~~~
11 | This is an extension to the olcPixelGameEngine, which provides
12 | a quick and easy to use, flexible, skinnable context pop-up
13 | menu system.
14 |
15 | License (OLC-3)
16 | ~~~~~~~~~~~~~~~
17 |
18 | Copyright 2018 - 2020 OneLoneCoder.com
19 |
20 | Redistribution and use in source and binary forms, with or without
21 | modification, are permitted provided that the following conditions
22 | are met:
23 |
24 | 1. Redistributions or derivations of source code must retain the above
25 | copyright notice, this list of conditions and the following disclaimer.
26 |
27 | 2. Redistributions or derivative works in binary form must reproduce
28 | the above copyright notice. This list of conditions and the following
29 | disclaimer must be reproduced in the documentation and/or other
30 | materials provided with the distribution.
31 |
32 | 3. Neither the name of the copyright holder nor the names of its
33 | contributors may be used to endorse or promote products derived
34 | from this software without specific prior written permission.
35 |
36 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 |
48 | Links
49 | ~~~~~
50 | YouTube: https://www.youtube.com/javidx9
51 | Discord: https://discord.gg/WhwHUMV
52 | Twitter: https://www.twitter.com/javidx9
53 | Twitch: https://www.twitch.tv/javidx9
54 | GitHub: https://www.github.com/onelonecoder
55 | Homepage: https://www.onelonecoder.com
56 |
57 | Author
58 | ~~~~~~
59 | David Barr, aka javidx9, ©OneLoneCoder 2019, 2020
60 | */
61 |
62 |
63 | /*
64 | Example
65 | ~~~~~~~
66 |
67 | #define OLC_PGEX_POPUPMENU
68 | #include "olcPGEX_PopUpMenu.h"
69 |
70 | NOTE: Requires a 9-patch sprite, by default each patch is
71 | 8x8 pixels, patches are as follows:
72 |
73 | | PANEL TL | PANEL T | PANEL TR | SCROLL UP | CURSOR TL | CURSOR TR |
74 | | PANEL L | PANEL M | PANEL R | SUBMENU | CURSOR BL | CURSOR BR |
75 | | PANEL BL | PANEL B | PANEL BR | SCROLL DOWN | UNUSED | UNUSED |
76 |
77 | You can find an example sprite here:
78 | https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/Videos/RetroMenu.png
79 |
80 | Constructing A Menu
81 | ~~~~~~~~~~~~~~~~~~~
82 |
83 | // Declaration (presumably inside class)
84 | olc::popup::Menu m;
85 |
86 | // Construction (root menu is a 1x5 table)
87 | m.SetTable(1, 5);
88 |
89 | // Add first item to root menu (A 1x5 submenu)
90 | m["Menu1"].SetTable(1, 5);
91 |
92 | // Add items to first item
93 | m["Menu1"]["Item1"];
94 | m["Menu1"]["Item2"];
95 |
96 | // Add a 4x3 submenu
97 | m["Menu1"]["Item3"].SetTable(4, 3);
98 | m["Menu1"]["Item3"]["Option1"];
99 | m["Menu1"]["Item3"]["Option2"];
100 |
101 | // Set properties of specific item
102 | m["Menu1"]["Item3"]["Option3"].Enable(false);
103 | m["Menu1"]["Item3"]["Option4"];
104 | m["Menu1"]["Item3"]["Option5"];
105 | m["Menu1"]["Item4"];
106 |
107 | // Add second item to root menu
108 | m["Menu2"].SetTable(3, 3);
109 | m["Menu2"]["Item1"];
110 | m["Menu2"]["Item2"].SetID(1001).Enable(true);
111 | m["Menu2"]["Item3"];
112 |
113 | // Construct the menu structure
114 | m.Build();
115 |
116 |
117 | Displaying a Menu
118 | ~~~~~~~~~~~~~~~~~
119 |
120 | // Declaration of menu manager (presumably inside class)
121 | olc::popup::Manager man;
122 |
123 | // Set the Menu object to the MenuManager (call once per pop)
124 | man.Open(&m);
125 |
126 | // Draw Menu at position (30, 30), using "patch sprite"
127 | man.Draw(sprGFX, { 30,30 });
128 |
129 |
130 | Interacting with menu
131 | ~~~~~~~~~~~~~~~~~~~~~
132 |
133 | // Send key events to menu
134 | if (GetKey(olc::Key::UP).bPressed) man.OnUp();
135 | if (GetKey(olc::Key::DOWN).bPressed) man.OnDown();
136 | if (GetKey(olc::Key::LEFT).bPressed) man.OnLeft();
137 | if (GetKey(olc::Key::RIGHT).bPressed) man.OnRight();
138 | if (GetKey(olc::Key::Z).bPressed) man.OnBack();
139 |
140 | // "Confirm/Action" Key does something, if it returns non-null
141 | // then a menu item has been selected. The specific item will
142 | // be returned
143 | olc::popup::Menu* command = nullptr;
144 | if (GetKey(olc::Key::SPACE).bPressed) command = man.OnConfirm();
145 | if (command != nullptr)
146 | {
147 | std::string sLastAction =
148 | "Selected: " + command->GetName() +
149 | " ID: " + std::to_string(command->GetID());
150 |
151 | // Optionally close menu?
152 | man.Close();
153 | }
154 |
155 | */
156 |
157 | #ifndef OLC_PGEX_POPUPMENU_H
158 | #define OLC_PGEX_POPUPMENU_H
159 |
160 | #include
161 |
162 | #include "olcPixelGameEngine.h"
163 |
164 | namespace olc
165 | {
166 | namespace popup
167 | {
168 | constexpr int32_t nPatch = 8;
169 |
170 | class Menu
171 | {
172 | public:
173 | Menu();
174 | Menu(const std::string n);
175 |
176 | Menu& SetTable(int32_t nColumns, int32_t nRows);
177 | Menu& SetID(int32_t id);
178 | Menu& Enable(bool b);
179 |
180 | int32_t GetID();
181 | std::string& GetName();
182 | bool Enabled();
183 | bool HasChildren();
184 | olc::vi2d GetSize();
185 | olc::vi2d& GetCursorPosition();
186 | Menu& operator[](const std::string& name);
187 | void Build();
188 | void DrawSelf(olc::PixelGameEngine& pge, olc::Sprite* sprGFX, olc::vi2d vScreenOffset);
189 | void ClampCursor();
190 | void OnUp();
191 | void OnDown();
192 | void OnLeft();
193 | void OnRight();
194 | Menu* OnConfirm();
195 | Menu* GetSelectedItem();
196 |
197 | protected:
198 | int32_t nID = -1;
199 | olc::vi2d vCellTable = { 1, 0 };
200 | std::unordered_map itemPointer;
201 | std::vector items;
202 | olc::vi2d vSizeInPatches = { 0, 0 };
203 | olc::vi2d vCellSize = { 0, 0 };
204 | olc::vi2d vCellPadding = { 2, 0 };
205 | olc::vi2d vCellCursor = { 0, 0 };
206 | int32_t nCursorItem = 0;
207 | int32_t nTopVisibleRow = 0;
208 | int32_t nTotalRows = 0;
209 | const olc::vi2d vPatchSize = { nPatch, nPatch };
210 | std::string sName;
211 | olc::vi2d vCursorPos = { 0, 0 };
212 | bool bEnabled = true;
213 | };
214 |
215 | class Manager : public olc::PGEX
216 | {
217 | public:
218 | Manager();
219 | void Open(Menu* mo);
220 | void Close();
221 | void OnUp();
222 | void OnDown();
223 | void OnLeft();
224 | void OnRight();
225 | void OnBack();
226 | Menu* OnConfirm();
227 | void Draw(olc::Sprite* sprGFX, olc::vi2d vScreenOffset);
228 |
229 | private:
230 | std::list