| | |
Multiple Questions
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 33
Reputation:
Solved Threads: 0
Okay, I have many questions, mainly about subjects that haven't been discussed well in my school class, although I also have a few questions pertaining to a RPG I've been working on.
1. Threads. I've tried to search for a good tutorial on their basics, but I can't seem to find anything, can anyone explain them more fully to me. The main reason I want to use them is for monsters in my RPG, currently I am having to constantly add to a timer while doing other things to make sure the monsters do not pause while the player swings a sword. I just want to be able to assign each monster their own thread, allowing them to move independently of the rest of the game.
2. I'm having trouble making this RPG very flexible, one reason I know is because I used global variables rather than passing by reference, because of that I will most likely have to remake the majority of the program, but my main problem is, when the player swings their weapon, the 3 coordinates on the 2D array of the 3 spaces in front of the character are checked for enemies, this is where I run into some problems, as I have to brute-force each monster individually in order to check them. This makes it impossible for me to have a variable amount of monsters, as adding more requires me to brute-force even more into the program, which I want to avoid.
I've thought about using classes, and giving each monster their own class, but this is a bit of a waste of memory, and I was wondering if there was any other way I could do this.
3. Probably the main reason I want to avoid using classes is because I'm still a little shaky with them, if anyone can provide a good basic tutorial of classes and when to use them, it would be greatly appreciated.
4. Global Variables, I want to know when to use them, vs. when to pass variables around, I assume there are some basic guidelines on when to use either.
Thanks ahead of time for any answers, if you want to see the RPG so far, here's the sourcecode:
RPG
Space to Talk, ASWD to move, space to swing sword.
1. Threads. I've tried to search for a good tutorial on their basics, but I can't seem to find anything, can anyone explain them more fully to me. The main reason I want to use them is for monsters in my RPG, currently I am having to constantly add to a timer while doing other things to make sure the monsters do not pause while the player swings a sword. I just want to be able to assign each monster their own thread, allowing them to move independently of the rest of the game.
2. I'm having trouble making this RPG very flexible, one reason I know is because I used global variables rather than passing by reference, because of that I will most likely have to remake the majority of the program, but my main problem is, when the player swings their weapon, the 3 coordinates on the 2D array of the 3 spaces in front of the character are checked for enemies, this is where I run into some problems, as I have to brute-force each monster individually in order to check them. This makes it impossible for me to have a variable amount of monsters, as adding more requires me to brute-force even more into the program, which I want to avoid.
I've thought about using classes, and giving each monster their own class, but this is a bit of a waste of memory, and I was wondering if there was any other way I could do this.
3. Probably the main reason I want to avoid using classes is because I'm still a little shaky with them, if anyone can provide a good basic tutorial of classes and when to use them, it would be greatly appreciated.
4. Global Variables, I want to know when to use them, vs. when to pass variables around, I assume there are some basic guidelines on when to use either.
Thanks ahead of time for any answers, if you want to see the RPG so far, here's the sourcecode:
RPG
Space to Talk, ASWD to move, space to swing sword.
You're coding in C++. Forget about global variables, try and make a class that has all those variables. If you can't fit it in a class or function you're quite possibly doing something wrong. Globals are considered dangerous when you tend to use them as much as you do. It also cleans up your code a lot, 2000 lines is a lot, especially when I think you could make it a lot more readable by splitting all the code up in classes. Having the functions that need the member variables of a class in that same class or friends of that class also eliminates the need to pass every variable and allows you to simply make private "safe" data members.
2, 3, 4 should be solved by learning and using classes. 1 is very advanced and will make your eyes bleed and your program deadlock. ;-) Assigning each monster its own thread would do you little good since you'd have to lock every variable/array it'll access and unlock it... It will probably slow down the program quite a lot.
Well, really try to encapsulate most of the functions and variables into classes. That should be your focus. I like the idea and your work on the RPG though! Very cool.
The monster hit algorithm could be something like this right:?
2, 3, 4 should be solved by learning and using classes. 1 is very advanced and will make your eyes bleed and your program deadlock. ;-) Assigning each monster its own thread would do you little good since you'd have to lock every variable/array it'll access and unlock it... It will probably slow down the program quite a lot.
Well, really try to encapsulate most of the functions and variables into classes. That should be your focus. I like the idea and your work on the RPG though! Very cool.

The monster hit algorithm could be something like this right:?
C++ Syntax (Toggle Plain Text)
For each monster for each hit coordinate check if the monster.location == hitcoordinate[n] if so do damagerollorsomething
Last edited by Clockowl; Aug 26th, 2008 at 8:36 pm.
•
•
Join Date: Apr 2008
Posts: 33
Reputation:
Solved Threads: 0
•
•
•
•
You're coding in C++. Forget about global variables, try and make a class that has all those variables. If you can't fit it in a class or function you're quite possibly doing something wrong. Globals are considered dangerous when you tend to use them as much as you do. It also cleans up your code a lot, 2000 lines is a lot, especially when I think you could make it a lot more readable by splitting all the code up in classes. Having the functions that need the member variables of a class in that same class or friends of that class also eliminates the need to pass every variable and allows you to simply make private "safe" data members.
2, 3, 4 should be solved by learning and using classes. 1 is very advanced and will make your eyes bleed and your program deadlock. ;-) Assigning each monster its own thread would do you little good since you'd have to lock every variable/array it'll access and unlock it... It will probably slow down the program quite a lot.
Well, really try to encapsulate most of the functions and variables into classes. That should be your focus. I like the idea and your work on the RPG though! Very cool.
The monster hit algorithm could be something like this right:?
C++ Syntax (Toggle Plain Text)
For each monster for each hit coordinate check if the monster.location == hitcoordinate[n] if so do damagerollorsomething
I think that what I could do is assign each monster a class, and that should allow me to be at least slightly more variable. I began to try and get rid of my global variables by passing them all by reference and such, but after about 15 minutes, I realized that my program was way too messy and not flexible enough, so I'll probably have to go and redo a lot of it.
As for hitting the monsters, the biggest problem is that the look of the monsters can vary, so I can't have a fixed look, meaning I have to check to see if the coordinates of the monster match with the coordinates of the sword swing, so I have to brute-force it, although using classes should reduce that at least a bit more, not to mention when you hit the monsters, they are knocked back and damage is done based on which monster you hit, so I need to know exactly which one it was.
Last edited by Nishinoran; Aug 26th, 2008 at 9:15 pm.
You can have a monster class with a function isHit(const unsigned int x, const unsigned int y); that returns whether the monster is hit. This makes the hit function belonging to the player really short, since it only needs to feed 3 coordinates, the monster does the rest. Like this, you can hide big pieces of code, make sure they work and never look at them again until you want to change them.
Best of luck with it, I might also take a look at it myself if you like? I'm kinda out of projects now, and this seems a nice project with a dedicated developer. Besides, I have some OpenGL skills if you'd like it to be more visual...
Let me know,
Best of luck with it, I might also take a look at it myself if you like? I'm kinda out of projects now, and this seems a nice project with a dedicated developer. Besides, I have some OpenGL skills if you'd like it to be more visual...
Let me know,
•
•
Join Date: Apr 2008
Posts: 33
Reputation:
Solved Threads: 0
•
•
•
•
You can have a monster class with a function isHit(const unsigned int x, const unsigned int y); that returns whether the monster is hit. This makes the hit function belonging to the player really short, since it only needs to feed 3 coordinates, the monster does the rest. Like this, you can hide big pieces of code, make sure they work and never look at them again until you want to change them.
Best of luck with it, I might also take a look at it myself if you like? I'm kinda out of projects now, and this seems a nice project with a dedicated developer. Besides, I have some OpenGL skills if you'd like it to be more visual...
Let me know,
I kinda want to work on this alone, as this is my first large-scale project, I'm pretty much just doing it for practice, thanks for the offer, and the help so far.
Also, I can't seem to remember off the top of my head the command to create a variable type, I want to have a variable with two possible values, 1 or 0, basically, a binary variable, it's not typecast...
Last edited by Nishinoran; Aug 27th, 2008 at 12:20 pm.
It's called a in C++ 
You can create types with typedef.
typedef <newtype> <oldtype>
IIRC
cpp Syntax (Toggle Plain Text)
bool

You can create types with typedef.
typedef <newtype> <oldtype>
IIRC
![]() |
Similar Threads
- Multiple webcams (USB Devices and other Peripherals)
- *Random System Restarts* (Win XP) (Windows NT / 2000 / XP)
- get rid of boxes on XP (Viruses, Spyware and other Nasties)
- System 32 Folder (Windows 95 / 98 / Me)
- JoeOneEye- prosearching.com problem (Viruses, Spyware and other Nasties)
- Preparing for an interview and need some questions answered (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- dual boot winxp and redhat 9 on laptop. help (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Windows Messages - Where to start?
- Next Thread: Segmentation Fault
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





