I'll check it out, and see what I can come up with to help you out. I'll try debugging it, as well. Please note that my knowledge in C++ is limited, but I'm starting college on March 3rd for video game programming. I'll let you know if I come up with anything.
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5
Here's something that I already found after reading just a few lines.
line #254
player.health = player.str * 10;
You already have that declared on line 158, so you're not going to have that declared again.
lines #247 - #267
if(playerexp >= 50)
{
player.lvl++;
player.str++;
player.acc = player.acc + 0;
player.intell++;
player.adrenaline = player.intell * 10;
player.health = player.str * 10;
cout << "Congratulations, you gained a level! You have gained\n";
cout << "1 Strength\n";
cout << "0 Accuracy\n";
cout << "1 Intelligence\n" << endl;
cout << "Your new stats are: " << endl;
cout << "Level: " << player.lvl << endl;
cout << "Strength: " << player.str << endl;
cout << "Accuracy: " << player.acc << endl;
cout << "Intelligence: " << player.intell << endl;
cout << "Health: " << player.health << endl;
cout << "Adrenaline: " << player.adrenaline << endl << endl;
system("PAUSE");
}
I'd just have that be in a module that you'd call at the beginning of the file. It could be in something like functions.cpp. Once you have the module created, you'd replace that code with the following
if neededexp = 0
{
levelup();
}
else
{
neededexp = neededexp - expgained;
}
The repeated battle animations can be cut from this file, and put into a function that would be in functions.cpp
lines #319 - #795
Cut them out of this file entirely, and make them a part of functions.cpp and include them at the beginning of this file. It'll save you a lot of time that way.
With your comments, just have them be like this:
// whatever
and the at the end of the code that is commented
// end whatever
This will make it so that the computer has to read less code, which will optimize loading times.
That's just what I've found just by skimming over your file quickly. #include ;
should make it so that your load times will be smaller, and it'll also make it so that you don't have to keep repeating the same code over and over.
I hope that I helped you out.
Good luck, man (^_^)
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5
Hey, no problem. I'm just glad that I was able to help.
I don't know if you're old enough to go to college (or even in USA), but if you are, you might want to think about going to DeVry for their online game and simulation programming courses. I'm doing that starting in March.
Thanks for letting me help you out.
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5
You should change the "< >" to quotes ( " " ):
#include "bfunction.cpp" This means that the file is in de project-folder
If you want to use multiple files I would recommend that you use .h files. For example:
You have a function void foo(int number) { }
You put de declaration in the header file (foo.h): int foo (int);
Next you put the implementation in the foo.cpp file:
int foo (int number)
{
return number*2;
}
Now you put #include "foo.h" in your main.cpp and your done!
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
I'm assuming that this is going to be on a web page.
I know that in PHP you can do things like this
<?php
$phpbb_root_path = './../';
include($phpbb_root_path . 'includes/functions.php');
?>
Or you can also do it like phpBB does it:
<?php
$phpbb_root_path = './../';
include($phpbb_root_path . 'includes/functions.' .$phpEx);
?>
You will have to declare the root directory before you're able to do any including in PHP.
Since PHP is based off of C++, you might be able to do it something like this:
#include "functions/bfunction.cpp";
Like I said, I have limited knowledge of C++ right now, so I'm not guarenteeing that anything will work exactly how you want it to, or at all for that matter.
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5
@Suetan, since the original poster's code is C++, I sincerly doubt that the means for performing a PHP include will be much help... PHP isn't a subset/superset of C++ : PHP is parsed by and interpretted by a C++ runtime engine; if that's what you mean by 'based off of C++'.
@kidprogrammer, it looks good to me. Perhaps some of the stuff in main could be moved out into other functions; but only if it looks like you'll gain any benefit, and not have many costs ( i.e. having to pass more than about 8 parameters to a 10 line function, or a function that's only called from one place is too many costs ).
Also, a minor; you use the windows.h header only for the 'Sleep' function.. That means your program will only compile on Windows machines, even though most of the code is platform-neutral. If you're only targeting Windows, that's fine. There are other ways to do a sleep( n ) though [ i.e, you should be able to use a call to system( "sleep n" ) and thus cut out the dependancy on windows.h ].
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
@MattEvans
What I was doing was using my knowledge with PHP to be able to hopefully implement it into C++. You're right about PHP's parsing by and interpretation on a C++ runtime engine.
I was merely trying to show how things are done in PHP and then work that into C++. I showed an example in a language that I know, and tried to work it into C++. That's all I was doing.
I'll keep it in mind not to refrence other languages in the future though.
Suetan
Junior Poster in Training
76 posts since Feb 2008
Reputation Points: 11
Solved Threads: 5