Making a Game With C++ and SDL2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one year ago i made this game in 48 hours for the gmtk game jam an annual game making competition but i participated with an extra challenge i couldn't use a game engine just c plus plus and a graphics library called sdl2 and the game kinda sucked so one year later i'm back to try this challenge again for the gmtk gamejam 2021 [Music] the jam starts in 30 minutes so while we wait let's set everything up with that taken care of let's take a look at the theme the theme is no joined together oh my god i want to see games now why one thing you might be able to gather from this footage is that i wasn't entirely fond of the gmtk game jam theme it's not bad just not very original i've already made two games under similar themes so it was going to be hard to come up with something different so i was already behind a few hours from setting everything up but i have a trick up my sleeve you see this year i don't have to follow coder gopher's 10 part tutorial series don't get me wrong i'm still going to steal his code but now since i know how it works i can use and modify it without needing to spend hours recreating it step by step hey you can't just steal my code polymart so what this code does is just let you create entities set their positions and draw them to the screen and i can modify it as i need to to add things like rotating and scaling sprites displaying fonts and whatever so let's draw an entity to the screen um i said let's draw an entity to the screen this is going to be a long weekend five hours into the jam and i can't even display a sprite hmm there we go now can i please start working on the actual game so i kind of want to try making a top-down mini golf game since i think trying to recreate golf ball physics from scratch would be a lot of fun so to tie it in with the theme i'm thinking of having multiple golf courses make up each level and your stroke affects all of the balls at once they are joined together i think this idea is different enough from my past games right so i put together a little prototype with a circle but don't be fooled this isn't any ordinary circle this is a golf ball [Music] i think this is how golf balls are supposed to work when you click the left mouse button i store the cursor's coordinates in a vector called initial position and while the mouse is being held down i set a velocity variable to the distance between the current cursor position and the initial position vector using a theorem created by my good friend pythagoras then it's just a basic friction simulation while the mouse button isn't being pressed down i convert the 1d velocity into x and y components using some ratios and add this to the ball's position every frame and each frame i decrease the 1d velocity by a tiny constant until it reaches zero but just one golf ball is pretty boring so what if we had two golf balls still pretty boring so let's get to work on some art i made sprites and for the ball and the background that's good enough for now i'm going to sleep the biggest things i need to focus on today are tile maps with collision and level progression so i made tile objects that the ball can bounce off of and they can pretty much be any size i just check where the ball will be the next frame but for each axis individually if i move the ball's x position and it's inside a tile i invert the x velocity and if i move the ball's y position and it's inside a tile i invert the y velocity and the collision detection itself is just basic rectangular box collision so i made some simple art for 64 by 64 and 32 by 32 tiles and then i made a little arrow that points in the direction of your shot using the inverse tangent of the x and y velocity components so now that we have the building blocks for levels we need a way to store and progress between levels so i made a method called load level load level clears the list of tiles and resets the ball's parameters then based on an integer that represents the current level adds new tiles at certain positions and sets new starting positions for each ball so by tediously filling in positions for each object i can create and load as many levels as i want then for level progression i made a whole sprite in and a whole object that when collided with sets the ball to be in a win state where its size shrinks towards zero and its position moves toward the center of the hole and once both ball sizes reach zero i increase the current level integer by one and call load level this is nice and all but here's the problem i have no levels and all my games up until this point have been endless with procedural generation so i don't really know how to design them the deadline is getting pretty close so let's hope i can pull this off but there's one thing i want to take care of first ui right now it's hard to gauge the power of your strokes so i want to make a power meter along with a stroke counter to track your score throughout the game so we're gonna need a font rendering library and a font so here's the new ui in action there is a display of the current hole along with your total strokes and a power meter i made by just scaling a sprite based on your velocity the jam ends in less than four hours so let's try to design as many levels as possible in an hour then i can spend the last three hours setting up menus sound effects and a build [Music] so i went a little bit over time but now i have five levels and two and a half hours to submit let's add some sound effects [Music] very cool i finished things up by adding a splash screen title screen and end screen after the final level that displays your total strokes surprisingly i actually had a completed game and submitted 30 minutes before the deadline i wanted to compile to javascript for a web build but i knew it was too late to mess with that since i've learned from the past that it is pretty unreliable a few hours after submitting i woke up from my game jam induced coma and it turns out that c plus actually added a secret feature to my game it's basically a speed run timer every second my code leaks around 200 megabytes of memory so you have to play the game really quickly if you want to get through it before it crashes yeah i i messed up a lot of people couldn't even get into the game so basically i wasted 48 hours making a game that nobody can play and i'm a lot worse at coding in c plus than i thought but i guess it was like a learning experience or something and i think the end result turned out pretty cool regardless if you can ignore the fact that it doesn't work i'll leave a link to the game's itch.io page in the description which will be updated soon to fix the memory leaks and hopefully include a web version the project's also on github but you probably shouldn't look at that anyway that's all so thanks so much for watching and i'll see you in the next video you
Info
Channel: PolyMars
Views: 323,164
Rating: 4.9569979 out of 5
Keywords: polymars, twini-golf, sdl2, game jam sdl, simple directmedia layer, cpp, C++, C++ game, C++ game dev, gmtk, gmtk game jam 2021, gmtk game jam, game jam, game dev, 48 hours, making of, cursor custodian, learning sdl2 in 48 hours, learn sdl2 c++, sdl2 game, making a game in 48 hours, making a game in 24 hours, behind the scenes, indie gamedev, indie game devlog, discord, discord bot
Id: iEn0ozP-jxc
Channel Id: undefined
Length: 8min 13sec (493 seconds)
Published: Mon Aug 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.