[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The Unknown Game



> Interesting, think I could have a look at your code?

I'd rather not give out the code at this time.  However, I will provide
the highlights to the system I was talking about.

Basically all game objects inherit from the TrollThing class.  This
includes the player, monsters, and items.  There are additional classes
such as TrollMonster and TrollItem which have aditional member functions
and include some default behavior.  For example monsters turn invicible
after being hit and need to blink in and out to alert the player.

class TrollThing
{
 public:
  virtual ~TrollThing();
  virtual void die();
  virtual void draw(IScreen drawscreen);
  IUShort getDirection();
  bool isDead();
  virtual void react() = 0;
  virtual void takeHit(TrollThing *hitby) = 0;

  static bool checkCollision(const TrollThing *a, const TrollThing *b);

 protected:
  TrollThing(TrollScreen *scr, IUShort secrt = 0);

  TrollScreen *screen;
  IUShort sprite;
  IUShort direction;
  IUShort facing, frame;
  IUByte shift; // color shift
  IUShort x, y;
  IUByte dead;
  IUShort secret;
};

So when the game initiallizes it loads the library and runs the
TrollDllInit() function.  It passes the game object as the only
argument.  The dll then registers the monsters.  Since constructors
can't be passed directly, the class all have static create functions.
The game keeps an array of create functions.  When the map file says
a monster type 1 exists in the room it calls the first create
function.

// This function must be extern "C" so that C++ doesn't rename the function.
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *\
  TrollDllInit - Sends information about monsters and items to the main
    program.

    Parameters:
      game         (In)  Game being played

    Returns: 0 on success, any other value indicates failure
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
extern "C" int TrollDllInit(TrollGame *game)
{
 // add monster types
 game->addMonsterType(0, TrollFlyer::createTrollFlyerSlow);
 game->addMonsterType(1, TrollFlyer::createTrollFlyerFast);
 // add items
 game->addItemType(0, TrollActivatibleItem::createTrollSwordItem);
 return 0;
}

> Yup, it was grabbing the wrong function.  I changed the name to killf(),
> and did an nm on the lib to pluck EXACTLY what C++ was turning the name
> into.  I now know that function is being run, but I still get coredumps
> when I try to access the data...  Welp, 'tis progress nonetheless.

Doh!  I can believe I didn't notice this before.  (Watch your going to
hate yourself to.)

Player * kill(Player * tokill, Player * me)
{
  // Do really stupid hacking...  null health,
  // intell and strength of killed dude, give to killer
  fprintf(stderr, "\nFOOBAR!\n");
  me->health+=tokill->health;
  fprintf(stderr, "\nFOO!\n");

}

There is no return.

Dennis Payne
payned@rpi.edu