online games strategy games

online games strategy games, online, games, strategy, games

Hi, it’s carl. Let’s make games here. Let’s make the game loop so we can start a new project And we’ll call this 2d engine because that’s what it’s going to be it’s going to be start of our 2D game engine 2d game engine next Right once you create a new project you [need] to get SDL installed in your project links are in the description for how to do that for xcode and Visual Studio, and so I’m just going to quickly skip ahead you can watch the other videos if you need to watch that again So there we go. [it’s] still fine work, and we have our main function. We’re going [to] clear all [that] out Don’t need any of [that] right The whole idea of the game loop? Is it continuously? goes over everything we need to do so while Game is running We will Handle any user input Then we [walk] update all objects for exact for example positions ETC, ooh We don’t to be doing that positions Then we’ll render changes to the Display The whole idea is that we do this over and over again? Until the games not running anymore and we’ve quit all the characters died, so this is what we can implement So that’s my games All right, so first thing is we need to create a game class So great new C++. File like a cool game right So in the game header We are going to include [Stl]. So we’re going to need to [know] which is going to be responsible [for] initializing that for us Windows users won’t need this here. You’ll just be that, but if you’re on a mac Then you’ll need that right, so In our game class definition we’re going to define our game class, so class game curly braces with seMicolon on the end Right in here. We can have a public members and private members Right so things that can be publicly available to other classes from here They’re going to be the constructor which [we’re] [going] [to] use to construct the game object Deconstructor for when we close it right And as we said this [classes] Gotta be responsible Updating [and] Stl and everything else so what we’re going to have We’re going to have a method for initializing it And we’re going to have this taking Kant’s Char star which is basically a string then called title we want int [x] [position] And it in y position Then we can have it in width and also in inked for height Well one thing I’m going to do is also taking a ball called Fullscreen

online games strategy gamescalled Fullscreen This allows to easily flag whether we want the game to be fullscreen or not when we create the game All right after we’ve initialized we’re going to need to an update function this will list go through all our game objects and update them all we’ll need a void [renderer] and [I] have to update Brenda. We need to go to clean You do some memory management for us [ok] the game objects from memory once you’re finished with them We’re also going to need to handle events if we put them in order. We’re going to do them So we can initialize this then it will be handling events so avoid handle events right now To let the main function know that the game should still be running We’ll create another function called void running Now this will return Boolean absolute so ball running and then when in our wallet when we initialize it we can ask the game class are you running and If it’s true, then [it] will run the loop again, so we’ll handle the reds will update render So for all this to work our private variables are going to need a ball saying call it is running and then also we need an spL window and renderer, so [Sdl] window Called Window and a [SDl] Renderer which [we’ll] call renderer Right now we have all these what we’re going to do Is Define them all? Well, we’ve already [define] them So this is everything that our game class at this moment. They’re going to be responsible for we now Need to do the source code for each of these so in the game cPP file We are going to create game D constructor and constructor So we’ve got that Then we also need to Declare in it Which basically we’re just going to copy this out, so I? can just double click these and [that’s] xcode. Look not sure if you can in visual studio but If not, just type them out like that So we’re going to initialize our [SDL] We can have our update function This is where we would have the game update all these positions. We have a void render Are we going to have handle events apparently so void? game class Handle Events And Er, and we’ve also got a clean function. So void game clean So we’ve got one two three four five six seven functions. Make sure we’ve declared them or [note] we’ve missed running. So we’re going to do that Up today what we’ll do we running will just make it in line. So we’ll just make this return is running and The stuff done, [so] one two three [four] five six seven right? Now let’s add some code please Alright So let’s start with SDl right, so Firstly when we initialize this deal, we want to make sure that it initializes properly didn’t create any errors before we start creating windows And renderers so what can go is if we’re going to call SDL in it as we did before in the previous videos And we’re going to put in SDl to init everything

online games strategy gamesAnd we’re going to put in SDl to init everything Now if that is equal [to] 0 then we have successfully Initialized the SDL subsystems, so what we’re going to do We’re going to add some output to the console so you can see what’s going on behind the scenes [so] we’re just going to print out subsystems initialized And do that And see out not sorry Not see out end line Alright, that’s done now With Sdi initialized we’re going to create the window. So we’re going to take our window that we declared in our header file And we’re going to go [STl] Create window now. This is where we put in the title the exhibition the white petition the width height and Full screen which we can’t pass in it takes you in 32 flags, so we’ll deal with that one in a second So we’re going to [put] in title I’m going to get x position y [cost] and width and height which go with Hiked [right] four flags. We’ll leave that for moment what we can do Will create an int called flags equal to [zero]? And in here where it wants flags, we will pass in flags so if we want fullscreen we can adjust this flags value like such so if Fullscreen is true we can set flag equal to Sdl window full screen So when we initialize this game? We can [sort] [of] review like to be [fullscreen] or not just by passing your true or false into the argument Makes it nice and easy for us through with that line Right this job right there we go [and] last now I’ve got a problem here And declared use of that, so we don’t have a oh stream Okay, so I’m gonna change that there to iostream That’ll fix that problem All right now. We’ve got the standard there. We go. So that’s done then we’re going to crack the window Then we’re going to check make sure the windows been done properly so if window True [basically] anything other than zero then it means. It’s [being] created so we can output so see out window created and then n glance What system? We can now create the renderer so our Endre It’s going to be equal to STl [crike] Renderer and we going to pass in our window. We’ve just created and passing it index and flags and We can do the same make sure the renderer or let us know if the render has been created successfully or not And we’ll just copy this line here And [paste] that in there Change up to render Render is created if this Has all worked what we’re going to do is make is running equal to true

online games strategy games equal to true

online games strategy gamesequal to true otherwise so else We will set is running to False So even if Sdl doesn’t initialize correctly we all have brilliant is running set to False So we check for it in the main Loop see whether we should carry on running the game it will see that. It’s false and it [webber] in the game So [that’ll] be sdl. Initialized for us Next [thing] we wanted to do is handle any events so what we’re going to do first For this one. We are just going to look up for the event [SDl] quit I’m Sdm. Okay event. [we’ll] call it event Then we can pull that event with SDL [pull] event pass The reference event because it won’t so know exactly where it is Now what we can do is run a switch statement on this and find out what type of event it is So what we’re going to do is switch And this expression we get a check for event type Now if that event type is equal to sel quit – there we are going to set is running to False So when we click the x on the window will generate an event called SDl quit? which will then get found by [our] handle events and Stop the game from running on its next loop right One thing we want to do now is the render This is where we render our objects screen so First thing to do is to clear what’s in the renders buffer render as buffer so we can go SDl? render clear and passing the renderer And this is where we would add stuff to render and then we present Going to present render up Once we’ve done that When we [quit] the game we want to clean up after ourselves, so we’re going to go SDl and [note] Destroy, [I’m] going to Destroy the window passing our window And we’re also going to destroy our renderer Now we’re going to call [SDl]. Quit if you’ll close off all the subsystems, and then we will also put Will see out? game cleaned Alright one thing to do now if we want we’ve created the renderer In here before we render a created. We can you set the render draw color so Stl Set render draw color. [I’m] going to set this to white so I’m going [to] pick the render up So there we go now have that Update render clean so now we’ve implemented Start of our game class We can start using this in the main like now to create our game loop so in our main cPP file We’re going to make sure we include our game header file and First [all] we need to create an instance [of] game, so we’re going to create a game called Let’s make it a pointer game When we make that equal to a null pointer for now and In our main function. This is where we’ll declare it so a good game is equal to a new game Now for the game loop so not not much to it so [boil] now The condition is going to be if the game [2] is running So if the guys are [running] we’ll run our statements in which case, we’ll be

online games strategy gamesSo if the guys are [running] we’ll run our statements in which case, we’ll be Gay you want to handle our events? I’m going to go game We’re going to update our objects And your game and we’re going to go Render bought our objects to the scene now [we] will be stuck in this as long as running is equal to equal to true when it becomes False We’re going to quit a game which means we need to run game clean That’s it. That’s our game loop So press plane out without our game window game cleaned program ended with exit Code 0 That’s right because we didn’t initialize SDl. So is running never got to true So let’s initialize now so game I’m going to call that an init function now [this] [is] where we can put in our title x-position y-position With height and wherever we want the window to be so we call this I’m just going to call it virtue engine Opposition on screen I’m going to use Stl window Pause centered you just give us the center of the window, and that’s the size again here SDl Window pass centered I’ll reach the height on a via 800 wide by 600 hi door walk Fullscreen not at this moment Right now when we run it. We should get a game, so [we] [all] succeeded right there’s our game screen and You can see here we initiated Initialized [SDl] we’ve created our window and the renders kraid now. This is them pretty boring. You can’t really tell if [anything’s] working even though I assure you it is One way to test this Is to put something in our update loop that we can watch so we’re going to quit this And you can see the game it gets clean once we quit it now game update is where we handle? Or our game logic and things like that, so if we go into game In what we can do, we’re going to create a local variable No, we’re not yeah, so what we can do in Private just from to watch we’re going to put in a counter, so we call it in count And we’ll just call it that so What we can do now in our game and update We can basically get count plus plus Which basically every time this gets updated we can increment our counter by one? So what we can do so you can see this work ringo standard, and we’re just going to see out whatever the counter is and And I’m just going to initialize up to zero in here because I’ll be just some random variable So we’re going to do that and we’ll hit play now [what] we’ll see in our console. You can see that Counter is getting updated So what we’ve actually got happening here is in our main function We’ve initialized our window Now it’s true at the moment [handling] our events which we’re not doing anything at the moment [thing] calling games update function, which is here so the plan is from here is not really to have all the game logic in this update function but for This update function to have all the game objects We’re going to have so the player will have its own update function, and we’ll just call the players update function from here And we can keep it all separate and what we can do is from here, we can just exit that off and We’ve clean the game so Let’s try Make it Fullscreen So it’s going to do the same thing so in main when we start it which can set this value here to true And when we were in the game, we’ll have a full screen window Which here’s our window Now it’s full screen. We don’t have any controls So you’ll have to [use] alt [and] f4 to quit out or Mac command q will do that here [we] go we have our game loop which is working Next episode what we’re going to do is bring in an image and start [moving] it around the screen See you next week