c++ noob making a game [Archive] - C Board

PDA

View Full Version : c++ noob making a game


Supernova
10-25-2003, 11:47 PM
I decided to teach myself c++ yesterday (being sick tends to give you some free time). After reading through a lot of tutorials I decided to apply my knowledge to somthing lol.

My plan is to make a nice console rpg, even perhaps make it multiplayer once i learn how...
The first step i decided to take was to create a combat system, its 326 lines long (a lot longer then i expected...) and written in about 4 hours.

The whole point of this demo is to er kill a monster standing in front of you.

The zip file has the source code and the exe for whoever cares, what i'm looking for is perhaps pointers and tips as well as any suggestions for the final game.

The source is a bit messy in places, and it doesn't have too many comments, so good luck :D

Thanks for anyone who care to have a look

...
10-26-2003, 01:15 AM
if you want to add some rudimentary (IE, ASCII) graphics to it, you can check out this:

Dark Nemesis
10-26-2003, 01:45 AM
Wow, thats actually pretty good considering.
I sugest displaying the maximum HP for both people during the battle, make make it look cleaner (remove linebreaks, or add linbreaks) and maybe give more choices of things to do, like use a healing potion, cast a spell, etc...
Also, it shouldn't be much harder to have a 1v5 battle, or even a 3v5 (you and CPUs vs CPUs or you vs CPUs). Good luck, really.

Supernova
10-26-2003, 09:32 AM
Hey thanks, I don't want any graphics yet, if this works out I'm going to try and make a top down windows version, but thats going to be far in the future.

Spells and potions should be quite easy to add in, I'll probably just add that now lol. Next things i want to add is a save feature for the room your in etc etc, i just need to learn the best way how.

1 way I've thought about doing this is to save a .txt file and have arrays in that text file for items, health, room layout etc. Though i have no idea how to actually implement this, I know how to save a .txt file, but i don't know how i would save an array to it, nor how i would load this information out of the array once it loaded again.

If I get anything done today I'll post an update.
Thanks for replies!

KneeGrow
10-26-2003, 09:48 AM
for saving it is easy, just use teh fstream library

declare
ofstream myout;

myout.open("c:\...\yourtxt.txt");

and lets say you have a map of rooms and you are in map[4][5]

just myout<<mapx<<endl;
then myout<<mapy<<endl;

Supernova
10-26-2003, 09:51 AM
would i need a seperate output for say monster in the room, what the room is like, what items you currently have etc etc? or can that be combined into one txt file? lol i would experiment but i'm adding spells :D

Sang-drax
10-26-2003, 10:11 AM
You should use
#include <iostream> //Correct header
using namespace std;
instead of
#include <iostream.h> //Deprecated header

Supernova
10-26-2003, 10:13 AM
when i do that the program won't compile...

[edit] huh well it did for once...

jr2007
10-27-2003, 05:48 AM
That is amazing. Im trying to learn c++ since this morning and the best i can do is write code for the classic hello world by heart! How did u do it???

Also, can i use sum of ur code to create a similar game but with a different genre???

Supernova
10-27-2003, 03:35 PM
Originally posted by jr2007
That is amazing. Im trying to learn c++ since this morning and the best i can do is write code for the classic hello world by heart! How did u do it???

Also, can i use sum of ur code to create a similar game but with a different genre???

er, sure i guess you can use some of the code, but a little comment about where it came from would be nice :)

I'd have an update, however i'm having problems problems linking two er (noob alert lol) "source" file together, I have the other .cpp file all in place with the header and everything but when i compile, it gets to the new .cpp file (the one i'm trying to get the function from) and says function so and so undefined, probably a simple error, mis-spelled word somewhere.

frenchfry164
10-27-2003, 05:10 PM
I've been getting away from even using "using namespace std" because that sorta kills the purpose of it being in a namespace.

Pretty good work. Just keep taking it step by step, from simple to complex, and you'll be using OpenGL or (I dare say) DirectX and making full 3D games, or maybe even 2D games with 3D effects applied, or full 2D games, or whatever.

Oh, and just say no to mode 13h!

axon
10-28-2003, 11:36 PM
Some good work there...sorry for bing pessimistic but I don't believe you've done it just after a few hours of learning c++. If you did...my hats off to you friend.

Supernova
10-31-2003, 01:10 PM
Originally posted by axon
Some good work there...sorry for bing pessimistic but I don't believe you've done it just after a few hours of learning c++. If you did...my hats off to you friend.

thanks though

int fewhours=8;

or so hours :D

I finally have a little free time and i'm starting to make some more progress on my game, I do have a few questions though:

#1

How do you get the program to read varibles from a file and then put them in the right spots in the program?

#2

How do you create a new file type (ie somthing that can't be edited in notepad)?

#3

Whats better for storing item/spell data, structs or arrays?

Thanks for all the comments and any/all help!

Dark Nemesis
10-31-2003, 08:29 PM
1. read about file I/O
3. Structs IMO


ifstream read("he.ini");
read >> player.race;
read >> player.hp;
...
read.close();

This way it reads the file one word at a time, loading it into a variable.

he.ini:
RaceName
HP

Edit: error in code, read ofstream, should be ifstream, fixed now.

Supernova
10-31-2003, 09:18 PM
Thank you very much, I've started writing the rest of the game, it starting to come along and now that I know how to get the game to read saved data I can really start making some progress, thanks again!

Supernova
10-31-2003, 09:41 PM
hmm few more questions, if u have many save files how do you get your program to say look in a directory and then make a list of all the files in that directory and then allow you to load them?

Dark Nemesis
10-31-2003, 09:55 PM
There is a way to read a directory, but you'll have too look for the tutorial yourself, but I personally open two files on save time (one if the save already exists) one has a list of all the saves, the other is the actual save file. Lame way of doing this, but it works.

Supernova
10-31-2003, 10:44 PM
Originally posted by Dark Nemesis
There is a way to read a directory, but you'll have too look for the tutorial yourself, but I personally open two files on save time (one if the save already exists) one has a list of all the saves, the other is the actual save file. Lame way of doing this, but it works.

Well if I can't find a tutorial I'll keep that in mind, thanks again.

Newbie Magic
11-22-2003, 03:26 PM
Why do you have multiple save files? Why dont you just save all the data onto one save file? It would look like this:


#include <iostream.h>
#include <fstream.h>

int main()
{
int hp=100, exp=2000, lvl=10;

ofstream save("save.ini");
save << hp << "\n" << exp << "\n" >> lvl;
save.close();

hp=0;exp=0;lvl=0;

ifstream read("save.ini");
read>>hp;
read>>exp;
read>>lvl;
read.close();
cout<<hp<<" "<<exp<<" "<<lvl<<endl;
system("PAUSE");
return 0;
}


Should look like this once compiled:


100 2000 10
Press any key to continue...



Hope I helped ;)

Newbie Magic
11-22-2003, 03:33 PM
Here is a program that I made a little while ago using that save method (it is saved in hex so it may look different):
LevelUp.zip (http://www.angelfire.com/gundam/testsite1/other/LevelUp.zip)

Mokkan
11-25-2003, 12:22 PM
That's a cool program :D. Good job on the lvl up. :)

SirCrono6
11-27-2003, 12:15 PM
You shouldn't use system("CLS") to clear the screen, go to the C++ board and look at Clearing Text if you want.

Also, instead of:


using namepsace std;


Use:


using std::cin;
using std::cout;
using std::endl;
...


Probably other using std's but that's all I've had to use in my simple programs...

Oh, yeah. Instead of:


#include <iostream.h> //Deprecated header.


Use:


#include <iostream> //Correct header.


Edit: Oh! Oops! Someone already said about the deprecated/correct headers! :D

KneeGrow
11-27-2003, 05:13 PM
what s the diff between using namespace std and the deprecated header i dont get it

SirCrono6
11-27-2003, 11:09 PM
It's all part of programming better, and to the standard...

SirCrono6
12-01-2003, 11:05 PM
If you did this just a little after learning C++ then what did you use to learn? Books? Online tutorials? If so, which one did you use? I can do a little C++ but don't understand it that much. It looks like you got it fine and I want to make stuff like that too. So what did you use, or what would you reccomend for me to learn C++ better?