26 Jun 2008 fzort   » (Journeyer)

ncm : I realize that my last post looks like flame bait. Sorry for that. I should have hastened to add that the problem is with me, not C++. Years of "design patterns" indoctrination while working as a Java code monkey in the "enterprise" have done that to me. I'm in dire need of detox.

I'm using a sort of "class hierarchy" in the game, though. For instance, different types of enemies behave and are drawn in different ways, but share common traits, so "virtual functions" become useful there. In those situations, I'm using run-of-the-mill "object-oriented C":

typedef union foe foe;
 
/* the "abstract superclass" */
struct foe_common {
    vector2 position;
    void (*update)(foe *);
    void (*draw)(const foe *);
    /* ... */
};
 
/* a "concrete subclass" */
struct foe_sitting_duck {
    struct foe_common common;
    vector2 direction;
    /* ... */
};
 
union foe {
    struct foe_common common;
    struct foe_sitting_duck sitting_duck;
    struct foe_ninja ninja;
    /* ... and so on */
};

Latest blog entries     Older blog entries

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!