Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

Game From Scratch C++ Edition The Introduction

 

I have decided to take a quick detour from my primary game development, to illustrate how to create a more simplistic 2D game using C++. I am going to cover it over a number of posts, each building on the last and if you follow along, hopefully at the end you will be well on the road to creating your own games.

 

 

Why in C++, I thought you hated C++?

 

 

That is a good question with a bad answer. I am writing it in C++ because regardless to all the people say “DON’T DO THAT IN C++!” the vast majority of people still do. The problem is so many of these people follow outdated or just downright bad examples and establish a horrific coding style right from day one.

 

 

So often questions come up like “how do I split my code up into multiple files” or people state things like “I hate OOP, I’ll just use functions”. Both of these statements illustrate the failing of many tutorials. Using C++ without objects is like using a hammer only as a nail extraction tool; while functional you are entirely missing the point of the tool. One last thing that many new developers get hung up on… we are writing a game, not a game engine! Don’t overwhelm yourself with unneeded complexity when you are just starting out.

 

 

This tutorial is going to span a number of posts so that I can go into the detail necessary. I am going to make some decisions for the sake of readability, but for the most part this should be code that you can take away and develop a success game upon. Along the way I will try to explain things to the best of my ability. With each post I will include a download link with the project, source code, etc. I have this nack for going off topic or into detail and frankly that is part of what I enjoy about writing.  That said, it can be confusing or distracting for people that just want the facts.  In this case I will box such comments into “Optional Information” sections that you can freely skip and still keep up. 

 

 

One last thing, this post will not teach you to program. I am going to make certain assumptions about my audience, the biggest of which is that you have a few weeks of learning under your belt. I assume you know the very basics in one language like how to declare a variable or how to use an if statement. If you have absolutely no exposure to programming I suggest you head over here for some getting started advice.

 

 

 

What game are we going to create?

 

We are going to create a downright amazing game about two intrepid paddles in space, called PANG!

 

 

Yeah yeah, we are going to create a Pong clone. Frankly every first game should be something simple and fairly easy to complete. That said, if things in this post go according to plan, Pang should provide us a few interesting opportunities, as with each additional post we can add a few more features like 2 player hot-seat, AI, nuclear missiles, networking, etc.

 

 

Doing most of the heavy lifting will be the excellent SFML libraries. They are well designed and do a very good job of keeping you away from a lot of the harmful aspects of C++.

 

 

 

Stuff you need to follow along

 

 

Before we begin, there are a few things you need to download and install.

 

 

This tutorial is going to work entirely with Microsoft C++ Express 2010. If you have another version or different IDE, you can still follow along, but directions will be explicitly for Visual C++ Express. So if you haven’t already head over here and click the Install Now button.

 

*** One word of warning, if you already have a Visual Studio 2010 product installed and patched to SP1, you will have to reapply the SP1 after you install Visual C++ Express. It takes a long time, and yes, it’s very annoying ***

 

 

 

Next head on over to SFML and download the SFML Windows - Visual C++ 2008 headers / libraries / external libraries package. This link is a zip file, just save it somewhere on your computer, we will address it again shortly.

 

 

One last catch ( explained here ) is that the SFML Visual C++ DLLs simply do not work with Visual Studio 2010. I have compiled them for you and you can download them here. Again, simply save that zip file somewhere and we will use it shortly.

 

 

Finally you are going to need a paint program of some form. MSPaint will work in a pinch, but I would recommend Paint.NET or the GIMP instead. Download links for both can be found here.

 

 

Ok, now that we have everything we need lets move on to Part 1.

 

 

  Forward to Part 1




blog comments powered by Disqus


Month List

Popular Comments

About the Mec…. er Giant Piloted Robots
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon


Home > >

1. May 2011

 

Hmmmm, really need to settle on a name for the bipedal robotic characters that isn't Mech/Mecha soon just to ease these conversations! Not my most creative day so I’ll just go with GPR now.

 

Anyways, the GPR is very much fundamental to the game.  One of my favorite things about Autoduel and Mechwarrior Mercs was the sense of acquisition.  Start with a lowly machine and work your way up the ranks.  One of my favorite factors of Chromehounds was the customization aspect.  I intend to incorporate both into our game.

 

The very first Mech, er GPR the character starts with is power_loadervery primitive, like the Powerloader from Aliens that Ripley used.  Very simple bipedal machine with a single weapon forward firing weapon mount.  As the player wins matches, they will have the option of swapping that weapon out for better weapons and eventually with be able to buy better GPR frames.  In the end though, it will entirely be about trade offs.

 

Each frame will have a certain number of slots available, of different sizes to accommodate different sized weapons.  Additionally frames will be able to have different power plants, that will be a factor in speed, battery life, weapon power and charges.  So you could mount a big heavy laser, that really sucks the juice or mount smaller engine which would be lighter and faster but couldn’t power the weapons as well.

 

It is all about trade offs, so you could create a fast lightly armed frame, or a heavily armed slow machine or simply an average all around machine.  You could also use munitions based weapons like rocket launchers or machine guns that don’t use energy from the engine, but once they run out of ammunition are as good as useless. 

 

cci_40All frames start with a certain amount of energy, tied to the type of power plant installed.  Things like the weight of the frame ( from weapons and armor ), firing of energy weapons, running at high speeds, taking damage from certain types of weapons, etc.  If energy goes to zero, you stop dead and can’t fire.  Engines will recharge slowly on their own, so you need to balance speed and weapon use to keep your power levels healthy.  Or, go with a power plant that has a rapid recharge rating.  In my head now, statistically a power plant is rated by:  size ( amount of space needed by frame to install ), weight, power available, recharge rate and frame class(es) ( what size of frames the engine can be install into ) and finally cost.

 

Frames work on a very similar manner, with various weight classes, like featherweight, light, medium, etc…  In addition they have variant number of weapon mounts of different types ( forward facing, 360, back facing, 360 degrees auto tracking, pod based, etc ), maximum weight for all add-ons ( engines, weapons, armour, etc ), maximum internal space for engines.

 

So, in the beginning, machines would be only a few meters tall, with a single weapon and underpowered engines and minimal armor.  By the end though, the player could be piloting a literal titan, several meters tall and bristling with weapons and armor.  Of course then, so will their enemies. 

 

From a developers perspective, this means I need to figure out how to make weapons44784_md-Guard, Imperial, Sentinel, Tank, Walker, Warhammer 40,000 modular.  In the end I imagine this comes down to dynamic parenting of bones, but it is something I need to look into from a technical point of view before continuing too far ahead.  I had been tempted to make frames even more customizable, so different legs, torsos, cockpits, arms and weapons, but truth is I think the level of work is too high to handle right now, especially when it comes to creating the animations.  If the modular weapons end up being not too difficult, I may revisit this concept.

 

You know, the name Frames is starting to grow on me.  BattleFrames?  Battle Frame Formats?  Yeah, that’s the perfect name, BFF!  Oh, wait….  *groan*  Back to the drawing board.

 

For those looking at the various inspirational images in this post, they are from the top Ripley in a Power Loader in Aliens, the Walker from Avatar and finally the Imperial Guard Walker, which is probably the closest in my minds eye to the kind of vehicle the player will start in.  Think of it like the go-cart of Frames.

blog comments powered by Disqus

Month List

Popular Comments