Making a C++ Game with No Experience!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] whether you like it or not the 1980s were the golden years for video games games like pac-man and centipede and donkey kong were making their way into arcades all around the world and out of all these games released in the decade asteroids probably has to be my favorite okay it it wasn't released quite in 1980s but it's so close there's something about the way the ship controls like is in space even though it was programmed 40 years ago before the days of physics engines that amazes me today i'm setting myself the challenge to make asteroids under these conditions one i must use c plus plus a language that i'm in no way experience with two i must code all of the logic by myself i can't search anything related to asteroids besides gameplay and three i have to hard code all of the physics and this means no physics libraries at all that last one is going to be very difficult this is going to be the most difficult programming challenge i've ever done so without further ado let's begin the multimedia library i went with was sfml if you don't know a multimedia library is basically a way to easily control common game functions such as creating and rendering to a window the difference between this and say unity is that sfml is only going to help with the really low level stuff whereas we are left to do the rest on our own for example loading textures or implementing physics now because this library is pretty new to me i'm going to start out by creating one of these little like sorting algorithm visualizers that you may have seen on youtube setting things up in vs code is actually really easy thanks to this guy's github repo it has all the build tasks and search pre-configured so i'd have to play around with any commands when i want to build soon enough i got this first window rendering and loaded a sprite onto the screen then i got some blocks to display using this little snippet of code and soon enough we got the bubble sort working however inefficient it may be at this point i'd learned the basics of the library and i was pretty confident that i could move on to asteroids the first thing i did was work on the player sprite in illustrator and after a bit of tweaking i ended up with this little triangle i loaded into the game and next i encountered the first problem of which many more would come when centering the player you can see it's not quite in the center this is because in sfml sprites have their zero zero coordinate in the top left by default i failed to see this for a while but eventually solved it by subtracting half of the player's width and placing the player there although later i realized that you can just center the sprite's origin which is obviously the better way of doing it and i switched to that scaling down the player slightly i moved on to playing around with the keyboard inputs and managed to get the console to print each time a key is pressed i use this in conjunction with a rotate function to allow our ship to move this worked fine but you can see how the ship is sometimes faster and stuttering around this is because the game currently has no delta time delta time allows us to move stuff independent of the frame rate so what that basically means is let's define some speed variable and set it equal to 10. if our game is running at 5 fps this means in one second we will move 50 units however if our game is running at 60fps we'll move 600 units a second this is an issue let's try fixing this by multiplying our speed by the time since the last frame now our game running at 5 fps will travel 10 use per second and a game running at 60fps will travel 10 use per second this time since last frame is delta time and it's what we need to solve our bug this was surprisingly easy to implement though and i got it working pretty quickly and there we have it smooth rotations next up is movement towards the direction of the player's rotation i'm not going to explain how this works because there's a lot of geometry and trigonometry based knowledge required and it would take me a whole video to explain the basics to build it up to that so i'll just show you the code onto the actual movement code itself this was by far the hardest thing to implement as i'm pretty much coding the physics by hand the approach i went with was to have a gain value that increases when holding forward and decreases otherwise the game value increasing worked like a charm however the decreasing or drag of the ship was incredibly frustrating to get working normalization came in clutch though and i finally after about four or five hours of coding got a playable ship another thing that is really easy to implement is screen wrapping at first i thought i'd have to fix the velocities but fortunately it worked first try now on to bullets the bullets are pretty basic to be honest there's a bullet class that i instantiate when conditions are met basically when we're pressing the fire button and it's been a certain amount of time since the last bullet and then this bullet moves based on the ship's direction when it was fired this is then set in the constructor i did have a little bit of trouble at one point and made this though and i genuinely could not recreate this if i tried so kudos to the bullet class this was kind of a wake-up call though to how messy the code was and i decided to spend about an hour rewriting everything so it was object oriented anyway here's the bullets working next i added asteroids to the game i started out by making the initial sprite and the class for the asteroids i quickly got them set up spawning next i made it so they choose a random position around the edge of the screen to spawn at then i got the asteroids wrapping around the screen just like the player so now we have basic asteroids the next thing to do is to implement the smaller asteroids this is pretty easy though all i need to do is detect collisions destroy the big asteroids and instantiate two smaller asteroids that are tagged as level two asteroids a level two asteroid will not split up and instead just die and there we have it that is asteroids some final touches with some sound effects and here's the finished game this video took me so long to make so i'm sorry it's been so long i do have plans to work on something more dev-like though for my next video maybe it's gatling maybe it's not i'll announce it in my discord later tonight so make sure you join that in the description and thanks for watching
Info
Channel: Barji
Views: 324,625
Rating: 4.9395652 out of 5
Keywords: gamedev, game dev, Game Development, gamedevelopment, asteroids, arcade games, arcade, game dev challenge, c++, sfml game, sfml, c++ game, c++ game development, barji, gatling, game, video game, poggers, Making a C++ Game with No Experience!, Making a C++ Game, making a game, no experience, making a game with no experience, opengl game, making a game with sfml, how to make a game with sfml, how do you make a game with sfml, making asteroids, asteroids in c++, make asteroids in c++
Id: 4-sX-TtRR98
Channel Id: undefined
Length: 5min 50sec (350 seconds)
Published: Sun Nov 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.