Placeholder Image

字幕列表 影片播放

  • Hello, a really quick and out of sequence video this week.

  • I'm going to be talking mostly about the console or the command prompt on why you see it so much in my videos.

  • Well, I like the command prompt because it's so simple to use.

  • I don't need to load any third party libraries.

  • We don't need anything for graphics or sound, as you've seen with my synthesizer videos and first person shooter videos.

  • We don't need complicated user input tools, and we don't need really need to use any third party libraries at all.

  • And that's what I like.

  • I'm trying to deliver the algorithms and concepts to my viewers.

  • I don't want anything to get in the way.

  • I don't want to get anything like the boilerplate code stand between me on the idea that I'm trying to present.

  • Now the regulars will also know that I start with a blank in main function like this and simply add a while loop to represent a gamely.

  • And you also know that in addition to the game loop, I always add a screen buffer and used the set console active screen buffer function so I can treat the console is basically an array of pixels, and I used the function right Consul Output character to update the screen.

  • And we know from the first person shooter video this happens.

  • It's several 1000 frames per second, and the point of this video is I am doing these things a lot.

  • And if a programmer is doing the same thing repeatedly, then it should be wrapped up unpackaged away.

  • And so this video is going to introduce a little class that I've written, which does exactly that.

  • This is just to make the future videos a little more easy to understand.

  • So to that end, I've created a simple class called the OLC Consul Game engine, and this class does the following.

  • First, the user can call the construct console function with a width and a height, and this specifies how many characters there are across the screen on down the screen.

  • When we can also specify the font size in pixels, it then goes away on attempts to create a console with those properties.

  • The class comes with a start function, which creates a threat on this thread, effectively becomes our game loop, so this replaces the wild one In fact, we can look at the thread here, and the first thing that said does is call on on user, create function, and we'll see how the user does this later.

  • The third contains a while loop, which axes are game loop, and it also handles some timing in the background.

  • If you remember from some other videos that actually we use the timing to make sure the motion is smooth and fair across different platforms, I then handle the input.

  • Now.

  • My other videos have always used get a sink Qi state, and this is no different.

  • Except this time I'm creating an array which stores all of the keys and its stores for that one instance of the loop.

  • Has it just been pressed?

  • Has it just been released, or is the key currently held down By then?

  • Call a user function called on news update, and I passed to that the elapsed time and finally I update the title bar of the console and output the screen buffer according to the parameters that we specified in the construct console function.

  • Using the class couldn't be simpler.

  • The first thing we need to do is include the file to actually define our base class L.

  • L C Council game engine.

  • Then I'm going to create a second class called Demo, which inherits from that, so we'll just need to fill in the obvious things.

  • They're such as the constructor, along with our constructor.

  • We'll need to override the two virtual methods because council game engine is abstract.

  • So to do that, I'm just going to paste in here.

  • Once I've created before we have the on user create, we'll load and create any resources that are game might need.

  • Now.

  • This is important because the thread calls this functions of the thread owns those resources.

  • The second function is our on news update, and this is where all the fun stuff will happen.

  • So we get a copy of the elapsed time with that function.

  • Using the class couldn't be simpler.

  • The first thing we need to do is construct the council, and we need to specify the width and height.

  • So I'm going to specify 160 characters wide by 100 characters high, which is quite a large console.

  • But I'm going to specify that the font size used is eight by eight pixels and then all I need to do is call game.

  • Don't start so that compiled and we'll run it.

  • And what we see is a bright pink console with a frame rate at the corner and some stuff in the title.

  • Bright pink.

  • Oh, here you say, What's going on?

  • Well, that's because this class also allows the console to specify the color's off the characters and to some of you now might get a feel for I'm going with this.

  • The class also includes some drawing routines, so I can draw to a specific character here with an X and Y coordinate.

  • It uses the Unicode symbol for the character, so this is a solid block on.

  • We can specify the color by default.

  • It's It's bright white, and I've created some Phil algorithms have created algorithms to draw strings to certain locations.

  • I've got clipping algorithms because I can also draw lines, and I have just lifted the brazen IMS line algorithm direct from Wikipedia here, Nothing too special.

  • So let's see what this could do.

  • I'm going to add a loop within a loop here to my own news update function.

  • So I've got a loop of the school sue the width and height.

  • So we're going to every character on the screen.

  • I'm going to draw the hash symbol on.

  • I'm choosing a random color for it.

  • Let's see what that looks like.

  • And there we go.

  • And now YouTube compression will be falling apart.

  • However, it's running at a good, healthy frame rate on DA, we can see that the console has been automatically sized according to the parameters that we chose.

  • Now let's have a look at some interactivity.

  • I'm gonna create a little player, which you control with the cursor keys, So I need to stall the place position.

  • I'm going to use floating point values, and we used the on create function here to default them.

  • In fact, I'm going to default them to 10 by 10.

  • Instead of drawing lots of random stuff to the screen, The first thing I'm going to do is clear the screen, and I'll use the Phil Command that I've got for them.

  • So we're feeling from the top left, which would be 00 and we're using the variables screen with and screen height, and I want to fill the screen with spaces.

  • I want to blank it out.

  • More specify the cooler to be zero to represent the play.

  • I'm just going to use a simple white rectangle on to do that.

  • I'm going to use the fill function again on I'm going to use the player.

  • Coordinates is the top left, and I'm going to assume it's a fixed size of five by five.

  • We used the update function to also handle the input.

  • Handling input is very simple indeed.

  • Now, because all we need to do is check the M keys or a with specific key code that we're interested in on.

  • We see its state.

  • So if any of these keys left right open down are held, we alter the player coordinates accordingly, and we can do it regardless off computer performance, because we're using the elapsed time to modify our values.

  • Let's see how this works so we can see the player white rectangle.

  • I'm pressing the right key.

  • It moves right.

  • I'm pressing the left key down key and up key, and simultaneously I compressed keys together as well.

  • So, using this very simple framework, we can create quite compelling game demos on.

  • We can talk about how the game works and not have to worry about how we present it to the screen.

  • One of the reasons I'm keen to do this because I know some of you think Oh, no, we're moving away from the simple format is it allows me to demonstrate really cool algorithms very simply such as this, and you'll see a lot more of this in the next video.

  • I'm gonna be looking at mazes and for those of you, have become accustomed to my videos.

  • Don't worry.

  • I'll still be coding most things from scratch.

  • Just occasionally, it helps to have some pre built code so we can get the videos off to a quick er staff.

  • As always, the code's gonna be available on Get hope and I'll see you next time.

  • Take care.

Hello, a really quick and out of sequence video this week.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

命令提示符控制檯遊戲引擎 (Command Prompt Console Game Engine)

  • 3 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字