Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3

Author Topic: Faffing about with a roguelike  (Read 4600 times)

Jack_Bread

  • Bay Watcher
  • 100% FRESH ♥HIPPO♥
    • View Profile
Re: Faffing about with a roguelike
« Reply #15 on: March 02, 2012, 07:42:44 am »

I think the problem is what Levi said.
Try adding
Code: [Select]
rect *new_room;near the beginning and have
Code: [Select]
new_room = new rect(x,y,w,h);instead of "rect new_room(x,y,w,h);"
Unfortunately, that breaks the entire rest of the function. new_room suddenly isn't a class, so I can't call the Intersect function, get the centre_x or centre_y values or push it onto the rooms list.

-snip-
Oh, instead of using new_room.intersect(whatever), you use new_room->intersect(whatever) and it should still work.

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #16 on: March 02, 2012, 08:04:10 am »

Yeah, that's what I did to fix it.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: Faffing about with a roguelike
« Reply #17 on: March 02, 2012, 08:14:31 am »

Posting to watch, i'm quite proficient with c++

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #18 on: March 06, 2012, 03:29:01 pm »

Okay, slight problem. In my character class, I have a call to the IsBlocked function. The IsBlocked function requires me to pass a list of characters to it (so I can run through the list and check if any of them are in the space you're trying to move to). If I move the function prototype above the declaration for character class, I get 102 errors and if I move it below, I get 1. Either way, it won't compile.
Code: (character class) [Select]
class character{
public:
int x;
int y;
const char* symbol;
TCODColor colour;
const char* name;
bool blocks;

character(int a, int b, const char* c, TCODColor d, const char* e)
{
x = a;
y = b;
symbol = c;
colour = d;
name = e;
blocks = true;
}
void Move(int dx, int dy, TCODList<character*> objects)
{
if(IsBlocked(dx,dy,objects)==false){
x+=dx;
y+=dy;
}
}
void Draw(TCODConsole *console)
{
console->setForegroundColor(colour);
console->printLeft(x, y, TCOD_BKGND_NONE, symbol);
}
void Clear(TCODConsole *console)
{
console->printLeft(x, y, TCOD_BKGND_NONE, " ");
}
};
Code: (IsBlocked()) [Select]
bool IsBlocked(int x, int y, TCODList<character*> objects)
{
if(map[x][y].blocked==true)
return true;
for(character **it = objects.begin(); it!= objects.end(); it++){
if(((*it)->blocks == true) && ((*it)->x == x) && ((*it)->y == y))
return true;
}
return false;
}
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Faffing about with a roguelike
« Reply #19 on: March 06, 2012, 03:32:08 pm »

Okay, slight problem. In my character class, I have a call to the IsBlocked function. The IsBlocked function requires me to pass a list of characters to it (so I can run through the list and check if any of them are in the space you're trying to move to). If I move the function prototype above the declaration for character class, I get 102 errors and if I move it below, I get 1. Either way, it won't compile.

What happens if you put this above:

Code: [Select]
bool IsBlocked(int x, int y, TCODList<character*> objects); //don't forget this semicolon.

And the full IsBlocked() function below.

Edit:  And out of curiosity, what is the error if it still dies?
« Last Edit: March 06, 2012, 03:34:03 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #20 on: March 06, 2012, 03:34:15 pm »

The aforementioned 102 errors. The functions are all below the main, the classes above. I know how function prototypes work.
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Faffing about with a roguelike
« Reply #21 on: March 06, 2012, 05:29:50 pm »

Since the IsBlocked function has a parameter with a type depending on the character class, you need to declare the character class first. I think it goes something like:
Code: [Select]
class character;and so you can put that line of code above the definition of IsBlocked
Logged

JoshuaFH

  • Bay Watcher
    • View Profile
Re: Faffing about with a roguelike
« Reply #22 on: March 06, 2012, 07:40:45 pm »

posting to watch.
Logged

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #23 on: March 07, 2012, 04:08:51 am »

As I noted to myself last night while trying to get to sleep, herp derp I can just put IsBlocked into the character class.
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Faffing about with a roguelike
« Reply #24 on: March 08, 2012, 12:59:47 am »

-codesnip-
Since when can I read that?  :o
Awesome.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #25 on: March 08, 2012, 09:19:29 am »

Since it's not that difficult code? Even the libtcod stuff's fairly easy to work out, although I really should comment more.
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Faffing about with a roguelike
« Reply #26 on: March 08, 2012, 11:51:19 am »

Yeah, but you have to remember something: I'm dumb. Or at least, it feels that way a lot. Also, I'm nowhere near a competent programmer, and I'm just marveling at my newfound understanding. In other words, don't mind me, I'm just over here contemplating my navel.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #27 on: March 08, 2012, 02:46:00 pm »

Anyone know if C++ can do component classes or if that's just something unique to Python?
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: Faffing about with a roguelike
« Reply #28 on: March 09, 2012, 02:24:21 am »

Don't know about python really, but just about anything can be emulated with c++ through inheritance, encapsulation and polymorphism, or templates, which are !!fun!!

e.g. in c++ you can emulate run-time polymorphism in this manner :-

say you have a "class character"

and have a pointer to an abstract base class within it, e.g. :-

class character
{
    profession *myprofession;
}

"profession" is abstract, but the pointer can point to any possible child class of the abstract profession. By having a number of these abstract pointers instead of using multiple inheritance, you can have modular run-time polymorphism.

Maybe describing what you want to do and i can show how that could be structured in c++?
« Last Edit: March 09, 2012, 02:28:44 am by Reelya »
Logged

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: Faffing about with a roguelike
« Reply #29 on: March 09, 2012, 07:50:37 am »

It's explained here.
Logged
Pages: 1 [2] 3