1

Help! Coding C++

Civeberg's Avatar Civeberg6/10/16 11:59 am
1 emeralds 451 9
6/12/2016 3:58 pm
Civeberg's Avatar Civeberg
I've recently wanted to get into learning C++. I have no idea how to do that though

I know Java fully, and decided it was time to move on to something a little more practical. Most games are made using C++ or C and C++ is much faster.

But I don't know how to learn it, since I know java all the tutorials I see are either too simple or too complex.

I want a video that's aimed for complete beginners, but instead of just randomly going over topics, it teaches you how to make a 2D C++ game from scratch.

If anyone knows of one, that would be a big help (I've spent about an hour googling, most of them either stop before they finish the game, or the people/quality of the videos are just way too bad that it wouldn't help anyone learn)

Anyway, just a video that would teach you how to make a simple game or something, that would be great. I've found some for java but I'm learning C++ now so they won't be a big help
Posted by Civeberg's Avatar
Civeberg
Level 29 : Expert Lumberjack
34

Create an account or sign in to comment.

9

1
06/12/2016 3:58 pm
Level 29 : Expert Lumberjack
Civeberg
Civeberg's Avatar
Again, thank you all. I watched a bunch of tutorials and ended up making a very simple game (VERY SIMPLE) based off Papers, Please xD

Click to reveal
#include <iostream>
#include <string>
#include <random>
#include <ctime>

using namespace std;

bool randomBool() {
return rand() % 2 == 1;
}

int main() {
bool inBattle = false;
int civilians, raiders;

const float civilian_accuracy = 50;
const int civilian_health = 40;
const int civilian_damage = 3;

const float raider_accuracy = 85;
const int raider_health = 60;
const int raider_damage = 7;

system("color 0b");

cout << " *** Mission Log *** \n";
cout << " | You are commander of the Kolechian army. You've recieved" << endl;
cout << " | orders that you are to send a group of raiders into an Arstotzkan" << endl;
cout << " | town to help aid the war. Decide carefully, the fate " << endl;
cout << " | of Kolechia could depend on you." << endl;
cout << endl;
cout << "Enter number of civilians living in the city: \n";
cin >> civilians;
cout << "How many raiders will you send?: \n";
cin >> raiders;

const int raidersStart = raiders;
const int civiliansStart = civilians;

mt19937 attack_random(time(0));
uniform_real_distribution<float> attack_distribution(0.0, 100.0);

int cCurrentHealth = civilian_health;
int rCurrentHealth = raider_health;


cout << endl;
cout << endl;
cout << " *** Mission Log *** \n";
cout << " | The attack is planned for tomorrow." << endl;
cout << " | You chose a village containing " << civiliansStart << " people." << endl;
cout << " | " << raidersStart << " of your best troops will be sent" << endl;
cout << endl;
cout << endl;

system("PAUSE");

inBattle = true;

while (inBattle) {
bool civFirst = randomBool();
float attack = attack_distribution(attack_random);

if (civFirst) {
if(attack <= civilian_accuracy) {
rCurrentHealth = rCurrentHealth - civilian_damage;
}
else if(attack <= raider_accuracy) {
cCurrentHealth = cCurrentHealth - raider_damage;
}
}

if(!civFirst) {
if (attack <= raider_accuracy) {
cCurrentHealth = cCurrentHealth - raider_damage;
}
else if (attack <= civilian_accuracy) {
rCurrentHealth = rCurrentHealth - civilian_damage;
}
}

// If a civilian dies, kill him and have him fight a new one
if (cCurrentHealth <= 0) {
civilians = civilians - 1;
cCurrentHealth = civilian_health;
}

// Same for raiders
if (rCurrentHealth <= 0) {
raiders = raiders - 1;
rCurrentHealth = raider_health;
}

if (raiders <= 0) {
inBattle = false;

system("cls");
system("color 0c");
cout << endl;
cout << " *** Mission Log *** \n";
cout << " | The battle was a failure" << endl;
cout << " | " << raidersStart << " raiders died" << endl;
cout << " | " << civiliansStart << " civilians remain" << endl;
cout << " | You have been suspected for treason due to" << endl;
cout << " | losing the battle. You are to be executed tonight" << endl;
cout << endl;
}

if (civilians <= 0) {
inBattle = false;

system("cls");
system("color 0a");
cout << endl;
cout << " *** Mission Log *** \n";
cout << " | The battle was a great success" << endl;
cout << " | " << civiliansStart << " civilains died" << endl;
cout << " | " << raiders << " raiders still remain" << endl;
cout << " | The attack hindered the Arstotzkan's progress" << endl;
cout << " | Kolechia won the war within the week" << endl;
cout << " | Good job general" << endl;
cout << endl;
}

}

system("PAUSE");
return 0;
}
1
06/11/2016 10:23 am
Level 49 : Master Wizard
Sammo346
Sammo346's Avatar
I'm currently third year studying for a degree in computer games programming, the first year was focused on C#

Go through the Bucky C++ tutorials, a whole lot of it will be transferable. Once you learn the basic differences and how to use headers and whatnot, then start the Unreal tutorials
1
06/11/2016 9:50 am
Level 29 : Expert Lumberjack
Civeberg
Civeberg's Avatar
Thanks everyone for your help, i'll look into all of these!

Sammo346
Either way, I wouldn't recommend using either to learn a language, you'll do far better learning how to use it properly before attempting Unreal Engine, such as the C# on Unity being very similar to Java.


What should I do then? I don't want to use unity because I'm not really interested in C#, but i feel like if I get into Unreal 4 there won't be many c++ tutorials aimed for semi-beginners
1
06/10/2016 4:42 pm
Level 49 : Master Wizard
Sammo346
Sammo346's Avatar
Bucky has amazing tutorials for this.
https://www.youtube.com/watch?v=tvC1WCd ... 8440AA6B83

Go through from the start skipping anything you're certain you already understand. You can skip the CodeBlocks stuff if you'd like

- For game making tutorials don't search the language, search for Unity or Unreal Engine tutorials instead. You can download Unity for free and do their official tutorial projects, however you'll have to keep in-mind that some tutorials will be for previous versions and may require slight alterations from the comments.
1
06/10/2016 8:22 pm
Level 77 : Legendary Robot
PrototypeTheta
PrototypeTheta's Avatar
To add to this, go for Unreal (pretty sure it's free now), it works in C++ wheras Unity uses C# (and if you know Java you know C# already).

If you want to try making a game in C++ from scratch, that's cool (pretty commendable if you pull it off), but messing around in something like Unreal could be a useful starting point.

The only other thing I might be able to offer is if you ever need to work out 3D collision detection (why you'd want to do this for a 2D game I don't know, but it's interesting stuff) I recently found a brilliant little paper that explains it perfectly.
1
06/11/2016 8:02 am
Level 49 : Master Wizard
Sammo346
Sammo346's Avatar
I'll take that paper link if you're offering.

Due to Unity being free for longer I would assume there are more varied tutorials around for it, however that might be wrong.

Either way, I wouldn't recommend using either to learn a language, you'll do far better learning how to use it properly before attempting Unreal Engine, such as the C# on Unity being very similar to Java.
1
06/11/2016 9:09 pm
Level 77 : Legendary Robot
PrototypeTheta
PrototypeTheta's Avatar
http://www.peroxide.dk/papers/collision/collision.pdf

Go nuts, pretty interesting read.


As for using a game engine to learn a language... Well, I did that for C#, and it did kind of work (admittedly I have every bad habit going) but it does provide an interesting environment to mess around in early on. But if you do ever get Unity hook Visual Studio into it as fast as you can, MonoDevelop is literally Satan.
1
06/10/2016 1:14 pm
Level 1 : New Miner
BobbyG2101
BobbyG2101's Avatar
If you are new to C++ try W3schools, http://www.w3schools.in/cplusplus/intro/ , it will teach everything about it, which you should know first before you make a game.

Hope this helps
1
06/10/2016 4:14 pm
Level 29 : Expert Lumberjack
Civeberg
Civeberg's Avatar
Thanks, but I already know the basics. I was looking for a tutorial on how to make a game itself because experience doing stuff is really how I learn compared to just writing random code
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome