|
|
#1 (permalink) |
|
Crumbly, but Good
|
Step-by-Step Guide to Creating a Text-Based RPG
Part 1 This is a guide about how to create a text-based RPG using C++ (an actual programming language. no rpg-maker required!). All you need to start is Windows and the free IDE Dev-C++. If you don't have Dev-C++ installed, check out this post, it explains how to install it, step-by-step. http://www.onrpg.com/boards/1215.html This is a very good place to start if you want to eventually program in 3D using DirectX or OpenGL, but don't really know a whole lot about programming. I know it sounds less than glamorous to make a text-based game, but to be honest, the difference between a text-based game and a 3D game is just a whole bunch of math; most of the programming fundamentals are the same. So! Let's get started. What you're going to be doing is learning how to write a small program, compile it, and run it in a dos window. First we're going to make a small program called “Hello World”. Hello World Hello world is the traditional name for the first program a programmer writes in a new language they're trying to learn. Don't ask me why; it's probably some inside joke from like the 70's at IBM .So, let's fire up Dev-C++, and create a new project. Creating a New Project To make a new project, do this: (these steps might not look exactly the same on your computer, I'm not actually using windows in these screenshots )Click this button. ![]() Select console project. ![]() Name your project, it can be whatever you want,it doesn't matter. ![]() Create a new folder for your project. Again, it doens't matter where the folder is, for the sake of convenience, I'm creating it in the Dev-C++ folder here. ![]() ![]() Now save the .dev file in the new folder. ![]() You should get a nice new window with some code in it, essentially the code I'm about to post to you below, but a bit different. Just delete the code they put in there, and paste in the code I'm about to post. Oh, just a note about the semi-colons (the ; ). At the end of every statement in C or C++, there needs to be a semi-colon to tell the computer that it's the end of a “command”. It doesn't matter how the code is spaced, or even if it's on another line, as long as it's in order and has a semi-colon telling the computer where the end is. The Actual Code! Code:
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout << “Hello World!” << endl;
cin.get();
return 0;
}
Explanation Code:
#include <iostream> I know that sounds complicated, and it is at first, but all you really need to know for now is that you really need to put that up there for your code to work. You can ignore it for now ![]() Code:
using namespace std; Code:
int main(int argc, char* argv[]) Confused yet? Don't worry. All this stuff you won't have to deal with at first when you want to write code. What's important is that you know that basically everything in your program starts off with your first line inside int main's curly-braces, which in this case is:Code:
cout << “Hello World” << endl; ![]() Cout is an instance of the standard output stream class. This should mean nothing to you, so don't worry if you don't understand. All you need to know is that cout is your ticket to putting text on the user's screen. Basically what cout will do is take any amount of things you throw at it, and put them on the screen. When we say; Code:
cout << “Hello World!”; Code:
cout << “Hello World” << endl; So whereas cout << “Hello World” << “Hi”; will print: Code:
Hello WorldHi Code:
Hello World Hi Code:
cin.get() If this line wasn't here, when you executed the program, a dos window would pop up for about a tenth of a second, and then disappear, we wouldn't be able to see what we've written. This way, the program waits until the user presses enter before continuing along on it's merry way. The last line here is pretty much the last of the overhead. Code:
return 0; Running the Code So now. How do we actually go about running this code? Well, we do this. Go to File->Save. ![]() Just save it anywhere; keep it as main.cpp. This is your file that contains all your code. Once your file is saved, click this button. This should compile and run your code. ![]() You should see a dos window, with the words “Hello World” in it, and the cursor waiting on the line below. Hit enter, and the window should disappear. We're Done! And that it! I know. A lot of trouble just to put one line in a dos window. But it gets better! Soon you'll be able to put two, maybe three lines on a window :o. Seriously though, this is a good start. Everything builds on this. Anyway, that's this week's tutorial. I'm hoping to release these on a weekly basis, or maybe on a bi-monthly basis. This should get whoever's interested started out. Questions? Comments? Feedback? It's good? It sucks? Too boring? Too fast? Too long? Post anything! I'll try and clarify and fix any problems you guys might have.
__________________
Last edited by Eriond; 11-10-2008 at 08:45 AM. |
|
|
|
|
|
#2 (permalink) |
|
42
Join Date: Feb 2008
Location: In your basement >:)
Posts: 912
Reputation: 26
|
Seems decent for a beginning tutorial. Might I recommend creating a guide like this on Wikipedia, they did the same thing with blender (which is how I'm learning to model) so I think it would work well for your tutorial too.
__________________
|
|
|
|
|
|
#8 (permalink) |
|
Marios's Mustache Wax
Join Date: Jun 2009
Posts: 2
Reputation: 10
|
I've been using PGCC (Pocket GCC) on my T-mobile Dash and I have been able to modify the files to get it to run from a command prompt through Task Manager. As silly as it may sound, I didn't even think about using arguments or cin.get() to make the program stop and wait for a user response. So, with just those couple of tips I have been able to run the files in a console window without having to use batch files to do so. Like I said, I'd really really like to see a continuation of the text-based RPG project that isn't Wrath Lands...
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|