Re: Newbie making a roguelike



On Jul 16, 2:42 am, Mingos <dominikmarc...@xxxxxxxxx> wrote:
On 15 Lip, 20:35, Daimones <pcl3...@xxxxxxxxx> wrote:

Also I must be mis-understanding something, because I have a Move()
function in my roguelike.cpp, which references my hard-coded dungeon
array which is in the same file. I'm trying to move these functions to
another file and not exactly sure how to go about that, do they have
to be in a class? Because I just put the functions into another .cpp
file and they can't reference the global dungeon array.

Always declare classes and structs and such in your .h/.hpp files.
The .cpp files should only contain the actual code, ie, the
implementation of what you declared. If you need a global variable/
object/whatever, do this:

Newb Question: What's the difference between .h and .hpp files?
I'm assuming .hpp is where you would store a class? Since it has
source, and also declarations?

in the map.hpp:

extern int myMap[80][60];

and in the map.cpp:

#include "map.hpp"
int myMap[80][60] = {/*your hardcoded map goes here*/};


Ahh okay, that's what has to be done, I was unaware of using the
extern command to implement a global variable.


Remember that if you want to reference myMap from another .cpp file,
it has to bear the preprocessor command #include "map.hpp". This way
you should be OK.

When there are quite a few .hpp files to keep track of, make an
includes.hpp file and put all the #include commands there in the order
you need. Then, each .cpp file will only need this: #include
"includes.hpp". Easy.

Yea, I sort of started that already, I have define.h with all my
#defines in them which is included in my headers.h file.

One more thing. I may be misunderstanding you, but did you say that
Move() is a function? A global function? That's C, not C++. You can do
it this way, sure, but it's much more handy to make it a method within
a class. Declare the class and all its methods in the .hpp and then
write the implementation in the .cpp file. Trust me, it's the way to
go :).

It was my own function named Move(), not a global C function. Sorry
for the confusion.

Best of luck with your roguelike!
Mingos

Thanks!
.



Relevant Pages

  • Re: Newbie making a roguelike
    ... which references my hard-coded dungeon ... file and they can't reference the global dungeon array. ... Remember that if you want to reference myMap from another .cpp file, ...
    (rec.games.roguelike.development)
  • Re: Newbie making a roguelike
    ... which references my hard-coded dungeon ... file and they can't reference the global dungeon array. ... What's the difference between .h and .hpp files? ... write the implementation in the .cpp file. ...
    (rec.games.roguelike.development)
  • Re: arrays of objects
    ... class CChannel ... Later in the .cpp file I have: ... Later on I do stuff with each array and the regarray but that is ... on where I declare the arrays in my CChannel class header file. ...
    (comp.lang.cpp)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: vb.net class
    ... about fixed array lenghts or using ReDim statements. ... code ensures everything in the array is a String because you declare it ... Count can be generated from the time list, not need to store ...
    (microsoft.public.dotnet.languages.vb)

Loading