Placeholder Image

字幕列表 影片播放

  • We'll see if this is gonna live.

  • It looks like it's gone life, just double checking.

  • Everything would like to somebody to give me some feedback as to whether the audio is okay and you can hear me.

  • That would be nice on welcome.

  • Yes to the 100 k live party, Thank you very much.

  • I see there's been quite a few people waiting this afternoon.

  • So hello to everybody in the chat.

  • If you see me looking at different windows, it's because I've got various chaps from different platforms.

  • Exxon, Ojai.

  • We've got some people recognize some familiar names already.

  • That's good.

  • S O.

  • This is to celebrate Swell 2019.

  • And it's been a good year for the channel.

  • It's been a great year for the community.

  • We just saw a community showcase, loads of cool things on dhe.

  • I think what we're going to do today is a code it yourself, which has become a bit of a tradition on this channel.

  • Whenever we've got a milestone to celebrate, I subject myself to this ritual humiliation off writing bugs live.

  • So what we're going to do is code a sh mop or a shooting up on it's going to be in the vein of those like crazy Japanese ones with bullets all over the place on.

  • We'll see how far we get because I'm not going to stream for hours and hours and hours, so we'll see how far we get today.

  • Hopefully, we'll get a nice framework in place.

  • And that's really what I'm aiming for because I've got a little prototype have put together.

  • So I'm not coding it completely from scratch.

  • We shouldn't be getting two lost like we did in the 50 k.

  • Remember getting lost there?

  • That was embarrassing.

  • But what I'm hoping to provide is this framework, which is really extensible for creating your own shooting up.

  • So I'll just have a quick glance at some of the chaps just to see what's going on.

  • Well, it's quite a few people have turned up already.

  • That's that's really good.

  • Eso thank you to those with lots of nice messages.

  • I'm not going t read them all out Now I will say some things before we start.

  • There is a prize draw.

  • The link should be below the video that you're currently watching.

  • There are 4 25 great British pound steam vouchers up for grabs.

  • It's za looking dip draw on.

  • You've got to answer a silly question, which is to also be on the screen.

  • I think for you to see read only my messages.

  • There you go, Red cap, right?

  • So I think we'll just get started.

  • So the idea is going to be a shooting up like a side scrolling, shooting up with lots and lots of bullets.

  • But I was quite keen to have a think about how we structure an engine.

  • For that.

  • They'll be a few of the announcements as well.

  • I'm going to keep getting distracted until we get settled.

  • Thanks for the congrats.

  • What are we doing?

  • We're programming a shooting up game in this style off 1942 which is that really horrible one for the nest.

  • But we'll be adding a bit more Flor to It's certainly a lot more particles because we like perfect ALS in these life specials.

  • I know some of you like to code along.

  • That's fine.

  • I will be probably going at quite a pace, but I think the gist will be quite acceptable for most of you on DDE.

  • I'm going to be leaning quite a bit on.

  • So what's his so called modern C plus plus in order to get things done?

  • And this has come out of a drive of what?

  • Of witnessing some conversations on the discord for about people not necessarily exploiting some of the things that modern C++ has to offer.

  • And hopefully I can demonstrate through the course of this video that if you really do lean on the tools, you can get things working very quickly, as much as possible.

  • I'm trying Thio Keep up with the chap, but it is going a little bit faster.

  • If I do miss your messages, they're all recorded.

  • And that's one of the reasons I like to put the chat on the screen so I can go back and look at the mall later.

  • I do like to try and read them all, because sometimes you suggest some really wonderful things.

  • There's a few moderators in the chat already.

  • In fact, I'll just make this guy moderator.

  • Now I can see that he's here.

  • The Andi I think we'll get started, so I'm going to be using the pixel game engine now.

  • You should all be very familiar with this from the channel, the pixel game engine, rather excitingly lows of announcements on it.

  • It's going to get a bit of an update next year.

  • I got some plans for it.

  • It will be considered pixel game engine, too, but it will be 100% backward compatible with pixel game engine one.

  • There's a few reasons, but I'll save that for for the new year.

  • But anyway, yesterday were using pixel game engine what 11 final announcement to make?

  • Because I'll make this a stars and I'll make it at the end as well.

  • Let me just bring in this window here so you can see through.

  • The community has decided that a one man coder community blawg platform is a good idea on dhe.

  • I tend to agree with them that so I'm now hosting this at community 10.11 co dot com.

  • On if the idea is that the community can write articles on get them up there dead logs or reviews of gains technology, anything that interests us is a community.

  • Really.

  • It's early days, yet there's not very many articles on it, but if you want to write something and get it seen because that gets a little bit of traffic.

  • Hopefully.

  • Now, you know, they've got a bit of a platform to push what the community is developing.

  • Maybe, you know, be nice to get this sort of underway and get people involved.

  • So if you if you want to write some articles register, reach out on the discord one way or another, contact me on, we can see about getting them posted.

  • Its got things like source code highlighting and images and things.

  • S o just wanted to get that in there before.

  • We should not close that down now.

  • Right.

  • Are we ready?

  • I think I'm ready for a mouthful of water.

  • Quite a few people here and I don't often stream on YouTube.

  • I tend to stream on twitch.

  • Twitch is a little bit more accessible for streaming.

  • Right.

  • So we've got a basic pixel game engine application appear I'm using 6 40 by 4 80 resolution on my pixel to screen ratio is going to be too on.

  • All it does is create an empty window.

  • Now, if we're going to create a shooting up, I think the first thing we're going to need is a ship so I will be gone soon.

  • Occasionally my prototype.

  • But I just want to make sure I get the variable names that I come up with consistent in the first place S o for the ship.

  • All I really care about is where the players position is s o.

  • I'm going to use a O l f l c vector floating point to DIY type.

  • And I used these quite a lot.

  • Now on it.

  • Call Aunt VI.

  • Play it.

  • Paul's very simple stuff on.

  • I'm going to need a sprite to draw what the player ship looks like.

  • It's gonna move my microphone slightly.

  • So do let me know if it's a problem on bridges, and I will see spring type here.

  • Create appointed to SP R Player now because I'm doing this live and I want to know quite a bit to get through tonight I will be cutting some corners regarding initializing variables and deleting things.

  • But, you know, give me a break.

  • Eso want to load that spite And I've created four graphics actually got them from an asset pack on humble bundle on.

  • I'm just going to use these basic graphics for tonight s I want to load this sprite, and I've got them in a subdirectory.

  • GI effects And I've called it 100 K player, one PNG.

  • So we've got the Sprite, and I think we'll add some rudimentary control in on user update to move that sprite around on the screen.

  • So we're gonna start very simply here.

  • I'm will build on it as we as we go through the video.

  • Hopefully, this will be available as a VOD straightaway if you if you're late or you just want things to slow down a little bit.

  • So I'm going to control the ship with the W A S and D Keys S o.

  • If we get key, we'll see w now I'm going don't to respond to the events.

  • I want to respond to the keys actually being held down.

  • That gives it a more really time field.

  • So if that's held down, if it w I wanted the player to move towards the top screen.

  • So player past, get all the typos now, can't edit these out.

  • Player past minus now.

  • How fast are they going to move?

  • Well, I don't know yet, so I think we'll have another variable which is the player speed because we might want to tune that later.

  • Let's just default that it's something ridiculous is probably far too high for now.

  • F place speech.

  • So I want to adjust the wine, coordinate, play speed Now, whenever we're doing movement.

  • And if you watch the channel on gathering the people that are here tonight or not, brand new to the channel, so you'll know that we use f elapsed time Thio modulate the movement across the screen.

  • So we got it going up the screen.

  • There you have it going down this screen down being positive.

  • Of course, when we hold down the S ky on, we probably want the same for the X axis as well.

  • So it will be the A and D Keys A and deal day on instead of why change those by X?

  • Very nice.

  • So very simple.

  • I got that the right way around A is going left.

  • So yes, that's going to be reducing the value of a quick glances at the chat fruit pastels or jelly tucks.

  • I really do like both, but I think you know occasionally want to treat myself to jelly tots.

  • That's an exceptionally British right s.

  • So now I've got to the player movement.

  • Let's just draw the play.

  • And the reason I'm showing this first is it's also a nice demonstration of just how simple we can do things using the pixel game engine s.

  • Oh, well, we'll basically have in our main loop here, the top will have user input.

  • You know what?

  • We'll flag these input in the middle here will have all of the mechanics and movement.

  • I'm going to call those.

  • Not that I'm going to call these gubbins.

  • Oh, just got a subscriber via twitch.

  • Thank you, Lord Chrissy, thank you very much.

  • We'll have Gubbins for there and then we'll have a display in the bottom.

  • Gubbins is an English word.

  • I let I let some of you look that up.

  • Oh, hey, clarified.

  • Nice to see that, right?

  • What was I doing?

  • I was drawing a ship.

  • Got distracted by a subscriber on twitch.

  • I'm drawing the player, and that's very simple because it's just going to be drawing the sprite at the location that we've just been creating.

  • So take the player.

  • Pause, variable.

  • Andi, I'll give it this Sprite player on.

  • I'm not going to scale it anything.

  • So that's it.

  • So I think right now Oh, yeah, we'll do one thing before we draw this flight will also clear the screen.

  • Now we're going to be in space, so that's very simple.

  • We're going to clear it to Black.

  • Well, thank you very much, Garrett.

  • It's good to see again.

  • Gareth.

  • Right?

  • So it's just compile that.

  • Make sure we've got everything set up correctly.

  • So all I've done is create a standard Windows.

  • This is a console mode application, but doesn't it?

  • Yeah, it does need to be a councilman application.

  • I think.

  • Andi just include the pixel game engine head of far.

  • I've gone ahead and included a few standard, lively files, which I know I'm going to be using later on.

  • Let's let's just see what does this look like already?

  • Nothing at all.

  • And that's because my player has not been initialized to somewhere useful.

  • That's so I'll initialize that thio here put him roughly in the middle of the screen.

  • Eso have screen with divided by two on screen height, also divided by do I don't need the bracket V player Past has been initialized.

  • We've got movement player.

  • Speed might be far too high, but we'll see you play a lot of input.

  • The player pulse that withdrawing the mocha Several.

  • Oh, dear.

  • First error on, let's because I know yes, This is something that started to frustrate me a little bit.

  • It's a C compiler has become very, very trigger happy about things like this.

  • So we might see a lot of casts tonight.

  • Why can't I see a ship not called up loading up the wrong sprite?

  • That's probably not going to help, is it?

  • Where is my spunk?

  • If x 100 k play it, It's not Player one.

  • Yeah, that's what I've done wrong.

  • They're a great start.

  • There we go.

  • It's the beauty of editing videos.

  • There we go.

  • So we've got the place sprite on.

  • I'm moving him around with the W A S D keys.

  • Now, I don't want the white rectangle around my sprite, so I'm going to tell the pixel game engine to draw the sprite using mask mode s So we just set that.

  • That's the set pixel mode.

  • We'll see pixel.

  • That mask on what that's going to do is any pixels that have any transparency it's not going to draw them.

  • So it's faster than Alfa blending.

  • It's a little slower than just drawing the Sprite normally.

  • So whenever you change the pixel, no, it's always good to set it back at some point, too.

  • So that should just now give us our nice Sprite outline.

  • There we go.

  • Perfect.

  • Got some movement on the screen right now.

  • We can't really tell what's going on now.

  • I think, to give a sort of a bit of context here so we can see in the background that things are actually moving.

  • I want some something in the background that moves so we can We can look at the relative movement between the ship and the background on.

  • I'm going to do that using some stars.

  • So I'm just catching up with some of the some of the chats.

  • It they are going a little bit quick for me to keep up with, so I'll just occasionally glimpse and hopefully we'll be looking.

  • I mentioned before that A ll the chance of recorded in the video so I could go back and have a look at that and I will read them all a bit strange.

  • Like that right?

  • So we're going to have some stars to give the impression off movement.

  • And I'm going to create an array of stars and very unusually because people shouted me now for not using modern.

  • See, I'm going to use standard array on all of my stars are also going to be a two D coordinates on I'm goingto have I don't know 100 stars.

  • Maybe we'll see.

  • Let's call that a Ray stars on dhe.

  • I'm going to initialize this just with random coordinates, for the most part, because I don't know where my stars are going to be, so I'll do this initialization in on user creates.

  • Let's do that.

  • It could use a little auto for Luke, uh, through my array of stars.

  • That's one of the advantages of using this standard Array just set the value to some random number based on the screen dimensions now going to have to use our twenties round.

  • I'm not going to get stuck into all of the complexity off finding and Miss n Twister and all that sort of nonsense.

  • So what I'm going to do is just around the screen whipped rand mod that's wanting to do rand marred the screen wit.

  • There we go for the X and will do the same for the Why.

  • Just making sure you can see these things on the screen as he can not coding in an area that's covered with overlay s.

  • So we'll have rend marred screen height.

  • There we go.

  • So a single line there were literate through all of my stars.

  • Little red Wiggly wife got little red wiggly.

  • I messed up my brackets.

  • No, because I didn't call.

  • It s.

  • Did I know we go?

  • Yes, perfect s.

  • So hopefully that should have now created a whole bunch of stars in random locations on the screen.

  • So let's draw the stars.

  • We're going to draw them behind the player s O to draw our stars.

  • You know what?

  • We'll just use the same thing again.

  • We'll take our auto little range loop there.

  • And for all of the stars were going to call the draw function on the pixel Ace is going to be white.

  • So I think that's all I need to do.

  • Yes, very simple, because now the drawer routines actually take in the vector type as one of the standards.

  • So does not give us some stars.

  • It does give us some stars, but there's nothing for them.

  • I think we need more more stars.

  • That's all have 1000 stars.

  • Why not see what that looks like?

  • That's better.

  • It looks a bit a bit more like what I need it to be.

  • So we're drawing some stars, but they're a bit static.

  • I want them to move around.

  • S so let's make them move around.

  • So I'll just I'm keeping the logic and the update for everything quite distinct at the moment on.

  • The reason for that will become more apparent later because there will be some times where I want to update the physics and perhaps update the stars at the same time.

  • So for now, you know what?

  • Actually, no.

  • I'm going to draw.

  • I'm just What am I doing?

  • I want to draw the stars.

  • We want to update the movements.

  • Yeah, Okay.

  • Why not?

  • This starts not going to be involved in any of the collision detection, so I may as well just do them at the same place.

  • So I'm going to want my stars to move.

  • So basically, it's an auto Scully always going to be scrolling upwards through the universe.

  • So I'm going to want to speed at which the universe is moving left world speed on dhe.

  • I'll just pick a number for now.

  • 20.

  • And so I want all of my stars to scroll down words by that speed before they get dropped.

  • So I could just do it like this.

  • All I want to do is alter the y coordinate because of the X coordinate can stay in the same place s So if I do that by F World speed times a few laps times that will update the white cord of the star.

  • The problem is they'll all fall off the bottom of the screen and we'll never see them again.

  • So instead, I want to check for when that happened.

  • So if the star has gone off the bottom of the screen, so just check by comparing it to screen heights, and we're probably going to need some casting in it, then we'll read will choose a new X value for the star.

  • I'm just going to borrow this line of code of picks.

  • We've already got it choosing you X value for the star.

  • But I'm going to set the height to be zero double check.

  • Yeah, not look sensible.

  • Let's have a look.

  • So all of my star start scrolling down, and when they fall off the bottom, they get a new X coordinate.

  • It looks like fresh starts, and this stops are seeing sort of repeated patterns in the stars in the background.

  • So that's quite nice.

  • It looks a little flat.

  • So I think what I'm going to do is try and add some pseudo depth to it.

  • Hopefully, you can see these stars coming through because I'm only streaming in 7 20 p because I don't have the best Internet in the world.

  • And I don't want the streams to be to blocking and stop it.

  • Okay.

  • S o.

  • I want to have some depth to that now.

  • That means I want if we want depth, basically the stars of further away, I want them to move a little slower.

  • So I need to choose a proportion of the stars to actually move slower.

  • Which means I can't really just iterated through the loop in this way.

  • I need to do it slightly more old school because I want to know what the index of the stars.

  • And basically what I'm going to do is choose, say, the 1st 100 stars.

  • They're going to move at a slightly slower speed than the 2nd 100 stars.

  • So in order to do that, I need the index for the start.

  • So let's slice t I equals zero.

  • I is less than our ray of stars dot size plus plus and we'll grab a staff because I like just working directly with it.

  • We'll use a little auto reference here.

  • Yes, auto reference here s equals R ray of stars elements.

  • I basically we're just duplicating what the loop was doing before.

  • But now I know which element numerically I'm working with because now I can choose a different speed for certain starts.

  • So if I'm working at, let's say the 1st 100 stars, that's what I'm trying to think through in my head.

  • So the 1st 100 stars, I want them to move slightly slower than the remaining 100 stars.

  • OK, getting there s oh, it's just a bias.

  • Our speed here by the I value.

  • So if our I is less than, let's say, the 1st 100 stars.

  • If that's true, then I want to move those a little bit slower than all of the others, which I can makes basically slowing it down because I'm not applying it by a number less than one.

  • So if I'm not slowing it down, I want them to will be the actual speed we specified before.

  • So let's just see how well does that work?

  • Well, there's certainly sort of a death characteristic there.

  • Maybe not enough stars.

  • Maybe you want to change that 200 step, I'll say 300.

  • Let's be optimistic.

  • So that, to me that's a little bit more depth to what's going up might also help to shade the stars a slightly different color, too.

  • So based on the same equation, I'm going to choose a different color.

  • So if they're the ones that are moving slower, then I'm going to use well, see gray, so they're a bit further away.

  • They're not quite a bright well, something to use.

  • Well, see, White Capital LLC.

  • Oh, well, see white.

  • The take a quick look.

  • That's a bit better to my eyes, at least on my screen, that looks a little bit more distinctive.

  • right.

  • So we've now got a ship flowing through space flying flowing through space, and we've got something in the background that suggests that we're moving.

  • And the nice thing is, we can change the speed of this movement like changing this value.

  • So if I wanted to move everything at twice the speed, it's all relative to what is our world propagation speed.

  • There we go.

  • So a little bit quicker this time make the deepest stars fade a bit.

  • Well, I could make them a slightly darker grey.

  • Do I have that as an option?

  • Tohave a very dark grey.

  • Yes, I do have very dark grey.

  • There we go.

  • So stars in the background look quite distinctly different now.

  • Maybe that maybe that's better, actually.

  • Yeah, my fella.

  • Right.

  • Whilst we've got loads of people here, I'll just repeat some of the announcements.

  • A maid rite of stuff.

  • There is a prize drawer.

  • There's a link below this video.

  • Therefore, £25 steam vouchers up to grab a big thanks to everybody that supported the channel this year because, you know, it's been a fantastic ride, certainly.

  • And the community has just got stronger and stronger not specifically around me, but specifically around the idea of helping each other to code.

  • And I think that's that's the really important message to deliver, right?

  • We've got stars, stars are done.

  • So now I think we're onto the slightly more interesting stuff.

  • How do we construct a level in this world?

  • Well, what we need to think about what we've got going on in the world, Perhaps pull up some one note.

  • So sorry for just blinding everybody there.

  • Have some slight and see if this works, right?

  • Yes, totally, completely bleached out my face on the camera there.

  • So when we've got, I'm going to draw these sideways because it gives me a bit more space.

  • But eso we know we've got our little ship here.

  • Try not to make this look too rude.

  • So that's our ship, and that's going to be flying through space.

  • And we know that what we're going to encounter our enemies of some description on the idea is that the enemies are going to shoot out bullets on the play is going to have to avoid the bullets and shoot back.

  • How would we?

  • Normally one no said doesn't have a dark mood.

  • I don't think How would we normally go about setting something like this so well?

  • Usually when I write games, nearly all of the videos I've done so far everything tends to be tile based.

  • So you perhaps have a huge world, and you'd allocate a specific tile to be the enemy.

  • And because we're moving through the world than the enemies don't really move, they'll just propagate towards the place that having a tile based system is probably going to be too restrictive.

  • The second option could be to have Theo entire world simulated all the time, so all of our objects could have an accident.

  • Why coordinate on every single frame?

  • Every object is updated, depending on its movement pattern, because I think it'll be a bit boring if everything's just moving in one direction.

  • You know, we want things to sort of move strangely like this, perhaps.

  • Or, you know, we have one that comes in and then moves across the screen, or perhaps another one, which does some sort of crazy movement just to confuse the place.

  • So we know we've got different types of movement that we require, and I don't want to be updating all of these movement characteristics for every single object because most of the time we're never going to see them.

  • It's a waste of processing resources on Give them that.

  • I suspect what we're going to really want is millions and millions and millions of bullets.

  • Physics may start to become a resource that we need to look after because we don't just want the enemy's firing in a boring straight line.

  • We want them firing in all sorts of crazy, interesting patents, so spiral E bullets, pulses of rings of bullets that come out at some way to make the challenge for the play.

  • So for all of my objects that are going to be considered enemies, I'm going to want something that defines how they're going to move around the screen and something that defines what the firing pattern is as well as what they look like and how much health they have.

  • Other things such as that.

  • But I want this to be really flexible on that was, that's really what this video is going to be about.

  • How do we make a freckle?

  • But how do we make a flexible framework to that?

  • People can extend really easily, so I know there's going to be a handful of people coding along.

  • And after this video, a lot of people might also have a go on implementing something similar.

  • It'll be great to see just how crazy some people can come up with the patterns, so we're not going to be using a tile based system.

  • I'm not going to be simulating the entire world all the time.

  • What my approach is going to pay to get rid of those.

  • Instead, what I'm going to have is a list on Good to have all of my enemies in a list.

  • I understand it work out on the on the Who fear How going to visualize this in one Notre?

  • I'm not quite sure.

  • So as the player is scrolling through the world now, this is always going to happen.

  • We know we're up to in world.

  • We can basically keep track of that coordinate.

  • Where are we up to?

  • On the idea is being We don't have a big queue off different enemies, so these are going to be cued up one at a time, and they all don't have a starting trigger time on going to be in order, of course, and that means when our world time call on W.

  • T.

  • Is equal to or greater than the trigger time for the object of the front of the queue.

  • Then the object gets entered into the game space because there's no point in simulating the things that we can't see on the screen.

  • Not necessarily.

  • We might just make this appear slightly before it becomes on the screen so it can scroll into it nicely.

  • But the ideas will have all of these things stored in advance.

  • But that doesn't tell us what we're story.

  • So we know that for each enemy, we're going to want to have something that defined its movement.

  • We know we want something that defines its fire pattern.

  • We know we want something that describes what it looks like, and we know we're going to want something that defines its health on dhe, all the other characteristics.

  • It's a strange isn't it other sorts of characteristics that we might want in our enemy, and I want to be able to sort of set these up very easily.

  • I don't want to have to create a bespoke level editor or anything like that in order to do it.

  • So what I'm going to do is create a framework which allows us to construct these objects in this queue.

  • And the game is really just playing.

  • What is going on with this cute and that might sound tremendously dull.

  • But as with most games, really, the stuff that goes on behind the scenes is not as good as the stuff that happens on the screen, right?

  • I'll stop blinding You'il with that stuff.

  • Quick chat catch up S O s.

  • A.

  • Hello to all of those people that have joined lots of chat going on.

  • It also gives me a chance.

  • Have a mouthful of water, too.

  • Oh, that's better.

  • You'll be picking up all sorts of ambient sound today because I've got my mic slightly lower.

  • So I've got the ample amplified turned up a bit higher.

  • It just keeps it out of the way whilst I'm trying to do this.

  • So what we've just described is that we've got something that defines what an enemy is, and so I'm going to create a structure which will be our enemy definition.

  • There we go.

  • On our cue, will store all of these enemy definitions on when it's ready to turn them into enemies.

  • Well, will do just that.

  • There the will have a different structure called enemy, which is the on screen entity doing its thing, and it will be defined by what is in this enemy definition.

  • So we said that we know that the enemy's air goingto happen at a certain point in time.

  • So the first thing a lab is a variable that is our trigger time.

  • I'll just set default that to zero.

  • So when world time catches up with the trigger time, we're going to convert this enemy definition into an enemy that the enemy definition needs to tell us what the spite looks like s so I'm going to use use a U.

  • N.

  • 32 for this.

  • I've only got three sprites for this particular video, but that's going to be our Sprite I D, which now is probably a good time to actually load those Sprite.

  • So I'll create a smaller ray off sprites despite star that is SP R enemy on.

  • We want three of them.

  • Let's go down here on load those.

  • We'll just do some vertical curse a ring enemy one 12 and three on the's are also going to be a Sprite enemy.

  • Well, don't start counting it wall.

  • There we go.

  • They don't want to.

  • So we've got now three enemy sprites loaded in on.

  • We're going to represent each of those spiked with this.

  • Identify this end spite I d of the things that our enemy might have is some health.

  • So we might weaken, reuse the same enemy spikes.

  • But sometimes we might want them to be stronger or last longer.

  • Whatever.

  • I don't know, we also need something else and that his word is the enemy actually appear on this screen.

  • Well, we know for the Y cornet, it's always going to be at the top of the screen.

  • That's where the enemy's air going to come in from that the X coordinate can change, and that will allow us to have patterns of enemies.

  • So I'm going to include another variable here f offset, and this is going to be a normalized variable into how far into the screen along the X axis should our enemy appear.

  • So if it's set to zero, it's the far left.

  • If it set toe one.

  • It's the far right of its 10.5.

  • It's in the middle of the screen that's gonna be normalized.

  • Value on that just allows us to make the game a little bit less resolution dependent just catching up with some of the discussion.

  • Can the OLC spite load A PNG?

  • Yes, it pretty much only works with PMG files.

  • This isn't the console game engine.

  • This is the pixel game engine, slightly different, so we know our enemy definition will eventually get turned into something called an enemy.

  • So I'm going to create another that stroked cold enemy on dhe.

  • I don't want to lose this definition When I create the enemy, I'm going to copy this definition into what the enemy is.

  • But our enemies have a position in specs, so it will give these vector for themselves called Paul's on.

  • We'll give them the desperately definition enemy definition, death call what, and I'm going to make it so that the enemies are somewhat responsible for updating themselves.

  • So rather than me having to manually sort of check what the enemy's doing, it's going to be responsible for looking after its own physics.

  • So for now I'm going to create this a placeholder function which will pass in the F elapsed time value.

  • We'll come back to this and probably had a little bit more to it later.

  • Now we said, we're going to store all of these definitions in a queue.

  • Well, a list in this case, and we're going to be using lists quite a bit.

  • So let's create a list and it's going to be off the enemy definitions and I'm going to call that list spawned.

  • I was going to make sure that that's what I called it before because, uh, yes, list spawned.

  • Sounds good on.

  • It's going to be this list that defines what are level really is.

  • So let's have a look at how we would go defining the level so thought so.

  • I'm just going to use in initialize a listener.

  • You could wrap this up in your own function to go and create bespoke levels in the case of a reset or whatever.

  • But for now, I'm just going to assume that once you've run out of enemies, you've run out of enemies.

  • Andi, if you get killed, well, we're probably not gonna get us far as implementing death But we'll see s so for each type of enemy that's coming into the game, I want to populate this s enemy definition structure.

  • So I can see here that the first elements that we're going to add is how long before?

  • And I had to do some experiments on this.

  • So I'm just going to grab some numbers, so we're not too busy looking around later.

  • How long before do we start the enemy appearing on the screen?

  • In this case, it's going to be 100.

  • It was a double.

  • Wasn't it wasn't a fluke We're going to have.

  • It's going to be 100 sort of game units before the enemy appears.

  • So this is not necessarily time, but it's more sort of this this artificial game unit, world position, location on.

  • We're going to use a sprite.

  • I d.

  • That was the next parameter, wasn't it?

  • Yep.

  • Sprite.

  • I d will give it some health.

  • That was a float on the last one.

  • Where do we want it to appear on the screen?

  • What would probably wanted to appear halfway along the X axis?

  • No, don't put the semi colon in there.

  • So we've got a single enemy in our list.

  • Off enemies we need to workout were on this list were up to in our world now, and that's quite easy because we've got our world speed here.

  • I'm going to create another double value called our world position willed Part default.

  • That's 20 to start with, but every frame update the world.

  • Paul's changes.

  • We've got F world speed times f elapsed time.

  • So this this auto scroll effect has the effect off continuously moving through the world.

  • It's going to slowly in current our world position.

  • No, no, Lou, be a lister isn't not quite an array.

  • Now s So now we've got this permanently increasing world parts value.

  • What we can do is compare that with the items on our Q and see if we need to turn any of our enemy definitions into enemies.

  • And there might be several enemies all at once.

  • So I want to check First of all that my list of spawns is not empty because of its empty.

  • Then there's nothing left to do, so it's not empty, and our current world position is greater than or equal to whatever is at the front of our spawn list.

  • Okay, then I'm going to convert this definition into an actual enemy, which means we need a new list.

  • We're using lots of lists and we'll have this'll ist will be off our enemy structure list enemies.

  • I lost my place.

  • There we go S o.

  • If we want to create a new enemy, Fine.

  • That's why we're going to need to do.

  • He will call it on.

  • We want to just copy over the definition to begin with East up Death equals at the current front of our lists of lists spawns upfront.

  • Just copy that over.

  • It might be a little bit redundant.

  • Some of the information on their book It's just going to be at the front of our cue.

  • Now we want to set the enemy's position so we know that it's always going to have the Y value set to the top of the screen.

  • But the X value is going to change a little bit, so I want to set up a This is an ol see vector float pointing the floating point vector to type.

  • So the 1st 1 is going to be our X axis.

  • So I grabbed the definition.

  • You know, I just grabbed the key.

  • Don't death don't offset.

  • At times, our screen wit starts taking that normalized offset and putting it somewhere in screen space.

  • I don't need that way.

  • Go.

  • That's for our X coordinate north.

  • I'm going to just split these out over a couple of lines so we can see the difference between X and why on our white corn, it is always going to be 00 Although it's probably best not to set that directly to 00 it's the enemy will just sort of pop in at the top of the screen.

  • So I want to take the height of the sprite that we've loaded and subtract.

  • That s so we've got our Sprite array of enemies.

  • We know that we've got our e dot deaf dot i d Yes, spite.

  • I'd even better said that's going to get the height from that sprite.

  • That's all we need to assess.

  • It means the enemy is not going to quite pop in from the front, and I'll just convert that over to a float which, whilst I'm here, is now making me think Well, the exposition is probably better if it's not the top left of the Sprite.

  • Instead, we probably want to set it to somewhere in the middle of the Sprite That way, so it's Ah, that offset on will subtract from all of that.

  • Come on, do the same sort of thing enemy For this time.

  • We want the wit divided by two.

  • So, yes, that that will put us in the middle off the sprite.

  • Definitely going to get some casting problems shouting at me in a minute.

  • So we've set the position for our enemy.

  • Once we've got it off the front of our cue, we can simply pop it off the front.

  • We're done with the definition, but we no need to add to the enemy to our list list of enemies.

  • Don't close to the back.

  • E There we go.

  • Right.

  • So now we've got two things that we need to think about.

  • Got up Q.

  • Which will spawn our enemies when we when we get up to them in the world on, we also need to think about how we can display our enemies too.

  • So let's go down to where we're drawing things that the enemies themselves are going to.

  • Elsa, have Alfa components.

  • So we probably do want to stay within this masked section.

  • Now what?

  • We want to draw all of our enemies.

  • Let's do that.

  • So this is going to be for auto.

  • He and list of our enemies draw Sprite.

  • The position is, of course, e dot Paul's on the Springs will be Sprite enemy.

  • He don't death, not 10 Sprite I D.

  • So that allows us to make sure we're drawing the sprite associated with that enemy.

  • Very nice now.

  • So far, all that will happen is our enemies will pop into existence.

  • They need to somehow move on.

  • That's what we've not gotten yet.

  • We've not included.

  • How do our enemies move around the screen?

  • I just have a mouthful of water could reveal my third going.

  • This is C plus.

  • Plus, it's catching up with some of the chaps.

  • Quite the loss of chance.

  • It's good stuff.

  • Don't forget there is a price drawer.

  • You can win £25 steam vouchers.

  • Just enter the price drawer.

  • There's a link below the video, so now we're going to get to the fun stuff.

  • How do we implement the movement and firing patterns?

  • Because so far All we've said is at a certain time after the players started and on enemy ship has popped into the screen.

  • That's all we've got.

  • Doesn't say anything about how the enemy ship moves around.

  • Well, this is the bit that I wanted to be kind of extensible because I think would be fun for the community to take some of this code and go away and create the most extreme and crazy, futile games you can think off.

  • And I'm going to use that something which is a little unusual, perhaps on our channel.

  • But I'm going to use some modern c++.

  • I'm going to use the standard function type so instead of what you might normally expect me to do, is go and create different classes and use polymorphism to sort of encapsulate all of this movement behavior.

  • I don't need to do that.

  • Really.

  • All I want to do is have a function associated with the movement and a function associated with how the enemy's fire on when we need to update the enemy's position.

  • We can call that function and that function will represent that movement pattern.

  • So that's why we've got this a little update function in here.

  • I'm going to instead of just having a big switch case statement in this update, I'm going to allow us to basically link in a function that describes the movement directly into the enemy eso.

  • In my enemy definition, I'm going to add a standard function pointer on the type is going to be.

  • It's going to return.

  • Void doesn't need to return anything at all, but it's going to take in a reference to the enemy itself.

  • Now we just need to forward declare that enemy appear and to make you in taking a reference to the enemy that's currently being updated on dhe.

  • I'm going to pass in some additional parameters.

  • I just wanna make sure I get the order consistent with what these parameters are.

  • Right.

  • So they're going to be the F collapse time, because that's what we needed down below.

  • And I'm also going to pass in the current world speed that worth were moving around at.

  • I'm going to call that scroll speed.

  • I'm doing this wrong.

  • After that, things are just going to be float.

  • So we've got these two floats Wait that someone's passing a lambda function that represents this particular movement type.

  • I'm going to call that funk move.

  • Not that it moves in a funky way just yet.

  • On when we booked date to the enemy's position.

  • All I need to do is call that the definition that we've associated with that enemy and call the funk move function that we associate with it, in which case it's going to be the enemy on.

  • Then it's going to be the elapsed time that we've passed in here, and I also need to know the scroll speed because the world is scrolling at a speed that we've chosen.

  • It's no good letting the enemies just move around, not knowing that speed or else they won't move relative to the rest of the game.

  • So I want to include this F scroll speed Perimeter two F.

  • Scott Smith, and that's going to also have to come in through our update function.

  • Hopefully, when we start visualizing things in a minute, this will make a lot more sense.

  • Yes, I've got my update.

  • When we're going to look through the list of enemies were basically is going to call the update functions on.

  • They will look after themselves regarding movement on firing, but right now we're just dealing with movements.

  • So let's have a look at adding in a very basic movement function.

  • I'm going to define these movement functions in my own music rate function.

  • So I was going to stick all of that load in code and prep code off there will keep the list of spawns down here and in between, I'm goingto have some blander functions on.

  • These are going to be movement patterns on.

  • They're going to look very much like what we've just defined, rather conveniently so autumn will prefix thes With move on, this one will just have moved none.

  • So I think it's important that we have just basically go with the flow, travel down the screens that will be movement none, and basically, it's just going to move in a straight line down confusing.

  • Remember, the world is moving all the time behind the scenes.

  • So if we want the enemy to move at the same speed of the world, it's not actually needing to move adults.

  • That's why we're calling it.

  • No, this is going to take in reference to the enemy.

  • It's going to take in tthe e f elapsed time and it's going to take in the scroll speed.

  • That's not how you define a lambda function.

  • David.

  • There we go.

  • I'm just going to cheat them.

  • We'll capture everything for now.

  • Sure, the purists out there can share it with me on discord later.

  • So if we've got no movement but we want the enemy to move relative to the rest of the world, then we need to look date.

  • It's y co ordinate accordingly.

  • In this case, it is going to be f scroll speed times f collapse type simply enough.

  • So how do we associate this pattern with the enemy that we've created?

  • Well, here we've got our enemy.

  • It's going to be spawned at that location.

  • But let's pass in because in our enemy definition appear the next parameter is this move function.

  • So I can now define this in here.

  • Move?

  • No.

  • So if you didn't know you could wrap up Lambda functions like there were variables and objects.

  • Well, you can s so that's going to associate with this particular instance of this spawning enemy, this movement pattern.

  • So I think we'll try and start to visualize some of these things now So once we've emptied our cue off anything that's relevant.

  • So all of our definitions that have just become enemies with any to start up dating some of the physics of what the enemy's need to d'oh consult my prototype here, make sure I'm getting things in the right order.

  • Yes, very good.

  • So well, no updates, the enemies.

  • And the nice thing about this approach is everything slowly becomes one liners.

  • So for Auto, we want to get auto reference e list of enemies.

  • We just want to update them.

  • So he update well, passing our F elapsed time.

  • And if scroll speed, we actually called it something else, and we call

We'll see if this is gonna live.

字幕與單字

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

B1 中級

10萬直播黨!自編代碼。SHMUP (100K Live Party! Code-It-Yourself: SHMUP)

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