olcPixelGameEngine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello I'd like to introduce the one loan coder pixel game engine [Music] [Applause] not long after starting this channel I created a header file called the OLC console game engine and this was a little utility file that allowed me to harness the Windows command prompt in such a way that we could display graphics and accept user input and I used it to create many game demos and algorithm demos and I think the response to this game engine has been really quite fantastic there's quite a lot of people using it and I think the simplicity of using it really appeals there's very little boilerplate to do you just include the header file and you start writing the code that matters as my youtube channel has evolved the demands I've been putting on the console game engine have been growing and growing and it has been a little bit of a competition in some way to see just what can I do next with the command prompt the recent coding is self 3d graphics engine series as highlighted sword the limitations that I'm facing with the console primarily it doesn't do graphics and instead we've had to resort to approximating graphics in interesting ways we saw in the webcam at the console video and subsequently some of the community's efforts to make that even better that you can approximate graphics quite realistically but on the whole the performance begins to really slow down and in the texturing path of the 3d graphics engine series we began to see performance issues due to how the windows subsystem renders the console there are a lot more interesting algorithms I'd like to display on this channel but I do need some sort of higher fidelity graphics in order to do so yes there will be predominantly graphical algorithms but I'm a little bit conscious of the fact that the videos are becoming about how do we do graphics in the console rather than focusing on the algorithms underneath and so I decided to create the one line coda pixel game engine the pixel game engine like the console game engine before it is a single header file solution and I've decided to create my own license to use it Oh lc3 it's a variation of the bsd 3 license fundamentally it's the same but it does insist that you give me a little bit of a nod if you use the code in something now I want to get this clear straight away I'm not going to stop using the console game engine it's still appropriate for a lot of things that I want to do if my applications are predominantly text-based I'll use the console game engine if the predominantly graphics based I'll use the pixel game engine and one of the things that I've tried to do mainly due to the success of the console game engine is emulate as much functionality of the console game engine as possible so it's a very very similar experience for the user in fact you can take most of my existing code and port it over very trivially and we'll see some examples of that later on one of the things I've tried to get right from the start this time and remember when I started this YouTube channel I never really expected it to gain any kind of subscriber base at all so compiling on other platforms wasn't a priority however this header file has been compiled in Linux first and I took this approach to really try and ensure the maximum compatibility we can have with as many users and operating systems as possible I've also tried to rely on libraries which are effectively standard with any development install and so compiling code that uses the pixel game engine should be quite simple I've also made an effort to support code blocks on Windows now I appreciate not everybody has access to visual studio on Windows and one of the most frequent comments is how do I get your code to work on code blocks so I guess there are parts of the world where code blocks is still quite popular so the pixel game engine should compile on code blocks to in the standard Windows environment you no longer have to do anything at all to get the project to run it will self load the libraries on Visual Studio in code blocks you need to add four libraries but it's quite clearly highlighted which four they are and you will have them in your default code box installation I've also worked on quite a bit to get it to the character type agnostic so it doesn't really matter whether you're using Unicode or not now the first major change is all of the pixel game engine code exists in an OLC namespace and i've adopted this approach to allow me to add extensions later on that can exist within this namespace without contaminating the rest of you programs instead of characters the fundamental unit you operate upon is the pixel which is a 32-bit full color pixal and so yes the pixel game engine supports transparency in the console game engine we had something called an oli t' well we have a no LC sprite again this time it's just called sprite and it loads a PNG file so the pixel game engine works with PNG files fundamentally underneath I will walk us through a little demonstration later on but I just want to highlight some of the features of the header file so you'll see there's a lot of familiarity with the console game engine you first need to construct an instance of the pixel game engine and you give it a width and a height and instead of this time giving it a font width and a height you give it a pixel width and a height so this means that pixels in the pixel game engine don't necessarily have to have a one-to-one relationship with screen pixels and this will allow us to have this retro blocky effect which I quite like but we don't have to have a retro blocky effect in fact we can have very high definition algorithms - next we see two very familiar functions to the console game engine on user create and on user update these function exactly the same as they did before if you didn't know the console game engine also has on user destroy but I don't think I've used it in any videos the nature of interacting with user input is exactly the same we can check if the window is focused we can get the state of a key and we can get the state of a mouse we can interrogate the primary display of the pixel game engine exactly the same as with the console game engine with the functions screen width and screen height there are a few more now which we may go into detail in in later videos and if you have any familiarity with the console game engine you'll recognize a lot of these functions straight away we can draw single pixels draw lines draw circle outlines fill circles have now I did a draw rectangle function and a fill rectangle function now we've got the draw triangle and fill triangle which we've exploited a lot of recently and draw a spite and draw partial sprite so hopefully you can see that very little has changed from how the user interacts with the pixel game engine ironically one of the more complicated things to do now is actually draw text but I have provided a draw string function and we may look at the implementation of that later too as we scroll down the OLC pixel game engine header file we discover a gap everything above this gap has been the declarations and everything below it has been the definitions so this means we can create the object oriented programming alternatives to the pixel game engine very trivially now I think I'll do a separate video at some point in the future on the actual mechanics behind how the pixel game engine works but it's very very similar to the console game engine the only difference this time is it needs to create Windows for the platforms that it supports when I introduced the console game engine I created a very quick demonstration to display noise on the screen it's just kind of the console game engine hello world equivalent so I'll do the same for the pixel game engine starting with a blank source file in a blank project I'm going to include the pixel game engine header file now I need to create a class that derives from the pixel game engine so I'll call the class example which inherits publicly from OLC pixel game engine now remember the OLC is a separate namespace now when we create a new class is typical to override the constructor so I'll do just this and as with the console game engine you have the opportunity to name your application typically there are two functions we always want to override the first is on user create in this instance we don't need to create any resources so I'm just going to return true to say that this function successfully completed the main function where all of the guts of the game engine lies is on user update which takes in a floating point variable called F elapsed time again we'll make it return true to say please don't terminate the application with those two basic functions now declared will implement the main function so the first thing is to create an instance of our class now before we used to call a function called construct console in exactly the same way this time we just call a construct function and we're going to give it the screen width the screen height that we want and the dimensions per pixel in this case I'm going to choose 4 and 4 so a pixel in the pixel game engine is represented by 4 screen pixels on your display if the construction returns successfully then we want to start the application so hopefully you can see already that it's exactly the same as how we did things with the console game engine before we add any body to unused update let's just run it in C and so as before with the console game engine you can see the name of your application and the frame rate appearing in the title bar so here we are not needing to do any updates to the display by default the engine is clicking over on my machine at about 5 and a half thousand frames per second let's make it display all of the pixels as random colors so I'm going to go through all of the pixels in turn by using two for loops individual pixels can be drawn to using the draw function exactly the same as the console game engine so specify the location of the pixel and this is where things change a little bit previously we would have used a character and a color so we wanted to display the pixel as the letter A for example in the console game engine we could do that here that's no longer an option because the pixel is now purely a graphical thing there is no text associated with it and so we have a variety of ways of specifying the look of a pixel built into the header file are loads of constant colors already so if you wanted to display everything green we can just use the name space and find the constant green but if we want to set the pixel values directly we'll just quickly use the struct and we can construct an instance of pixel by passing it to the RG and B values colors in the pixel game engine are represented with RGB being between 0 and 255 it's a 32-bit color system we'll worry about alpha later on so I wanted to pick a random number between 0 and 255 for the red pixel and cut and paste for the green pixel cut and paste for the blue pixel and we're done just fix this little error up here let's take a look and so there we have a screen full of noisy pixels and it's quite pleasing because the pixels have a certain size now as I said in the previous video when I was introducing the console game engine I reckon the youtube encryption algorithm has completely collapsed at this point we can make things look a little bit more Pixley so let's say for example I choose a screen size of just 64 by 64 very small but I choose a pixel size of 16 by 16 much bigger pixels so hopefully here I've demonstrated that the way that you use the pixel game engine is exactly the same as the way they use the console game engine you just have to think in terms of pixel values instead of characters now I've pulled in one of the programs I used when I first create the console game engine to demonstrate it it was generating mazes let's take a quick look just to refresh our memories as we can see it uses a search algorithm to create a maze of any size so I feel it's only appropriate that we try and convert this over to the pixel game engine just to see how trivial it is so the first thing is to change over the header file to pixel game engine and we'll need to inherit from a slightly different class fortunately Visual Studio will show you all the places where things don't quite add up so this MS app named variable has now simply changed to s app name and we don't really care about it being in Unicode anymore we'll leave all of the functioning Mae's code exactly the same so it's only when we get to the drawing stuff do we need to think about things a little differently so the clear the screen we used to draw a filled rectangle we now use the fill rect function for this and this shows you how long ago this video was we didn't even use screen width and screen height back then so we'll change those and since we're clearing the screen previously we would draw a space instead now what we're going to do is draw a black pixel again the next error exists while we're drawing something so here we were drawing a solid white pixel well by default the draw function will draw a solid white pixel but let's just be explicit white and this one looks like a blue pixel in the main function our last remaining error is the construct console function that doesn't exist anymore it's just called construct so we've really only made a handful of little cosmetic changes let's take a look and you can see it performs in exactly the same way if not a little bit faster I'm going to do the same again but now with the final episode of the Cody self graphics engine series where we looked at texturing so I'm going to load up the Spyro the Dragon level and displace in the pixel game engine fundamentally the code is unchanged the only differences are where we've been drawing and getting user input so using we haven't looked at yet instead of specifying now a particular key code native to the operating system you specify an OLC key code but functionally it's exactly the same whereas we used to specify WS a and D as characters we now use them as constants from the engine all of the mechanics code of actually rendering the 3d graphics is exactly the same before I launch it one quick thing we now work with PNG graphics instead of the SPR file so let's take a look and here we see it's the spyro level exactly the same as it was before but now looks a lot more detail yes the artifacts and glitches are still where please look at that video for an explanation but we can see the performance is quite nice about two hundred and forty ish frames per second depending on what it's looking at now that we have fewer limitations on what we can do with screens we can increase the resolution of things so I'm going to set the Spiro to be technically high def 1280 by 720 and in this instance I've set the pixel width and height to 1 so that matches screen pixel width and height so even though it's called the pixel game engine in this instance it's not necessarily deliberately rendering pixels and as you can see that looks pretty crispy and performs quite acceptable too in a way I hope that this further justifies that from the graphics engine series even though things looked a little bit rougher and read around the edges the underlying principles were sound and all we had was a restriction on how we rendered things I'll just quickly show one last thing and that is how to enable transparency per pixel because I know some of you will want to just get stuck in straight away so when you want transparency enabled you can specify the pixel mode to be alpha don't worry this is all documented in the header file on what this does and then I'm going to draw a sprite at the location of the mouse coordinates the PNG file contains alpha information already I've chosen to specify the pixel mode separately because performing alpha blending calculations is a little more costly not much but it is more so in most cases you don't need it but where you do need it you can enable it explicitly let's take a look so here I've got following the mouse cursor the one lone coda logo and you can see it's got some transparent elements to it and it overlays nicely with the scenery in the background this should make making games very simple indeed because you can use any art package that can output PNG files to create assets for the game the OLC pixel game engine exists in a new repo on my github and at the moment doesn't contain very much other than the header file itself and a couple of little example programs to get you going I'll add more as time permits I'll try and convert over as many of my existing video programs as possible what I will try and remind you is that there is a wiki tab on the pixel game engine and this is where I'm going to be placing more accurate documentation traditionally with all new projects at the moment they go nowhere but I think most of you will be able to get something out of this engine without much help now I don't have Linux natively on my machine but I do have a version of Debian running in VirtualBox and I just wanted to show that I've taken exactly the same CPP file that we've created this is the one you've just seen in Visual Studio and I'm going to compile it using a very simple compiled string this is also included in the header file we might get a warning about string stream yeah yeah yeah I'll fix that that's actually nothing to do with the header file that's to do with the textured demo and let's run that and you'll see Itzik behaves exactly the same the frame rate is significantly less because it's a virtual machine running on my machine and I'm also recording all of this using OBS but nonetheless you can see performs and behaves exactly the same way and because yes there are some masochists out there that enjoy using code blocks everything should be compatible with that too so here I've loaded up the code I do apologize for your eyes being burnt out of their sockets right now it's just how it is so I've compiled it and we'll run it and it's exactly the same in code blocks too and so there you have it the OLC pixel game engine header file it's available on the game open I'm hoping that people will adopt it and start doing interesting projects with it too I'll be using it to create some videos in the future but I'm still going to work with the console game engine as well I'm not abandoning it at all since this is a new project there will likely be some bugs and glitches that need ironing out so I'm hoping that the community might find some of these and you know let me know about them so I can do something about it anyway a quick little video if you've enjoyed it give me a big thumbs up have a think about subscribing come and have a chat on the discord and I'm can't wait to see all of the pixel game engine games you guys come up with take care
Info
Channel: javidx9
Views: 133,714
Rating: undefined out of 5
Keywords: one lone coder, onelonecoder, learning, programming, tutorial, c++, beginner, olcconsolegameengine, command prompt, ascii, game, game engine, olcpixelgameengine, pixel graphics, pixel game engine, indy development, retro games
Id: kRH6oJLFYxY
Channel Id: undefined
Length: 20min 16sec (1216 seconds)
Published: Sun Sep 09 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.