How do I make a pointer point to the current running level if each level is its own class?

Adam
  • How do I make a pointer point to the current running level if each level is its own class? Adam

    I'm hard-coding my levels and coding each level in its own class...The problem is that I need to have a pointer that points to the class of the current level. I don't know how I would go about doing this. I ideally want to have a vector that stores the levels, and I'm working on a level managing class to load, update, draw, and unload the levels in.

  • If your level classes have a common Base class you can just create a pointers to it:

    class Level {
        virtual void func1()
        //...
        virtual void funcN()
    }
    
    class Level1: public Level {
        virtual void func1()
        //...
        virtual void funcN()
    }
    
    class Level2: public Level {
        virtual void func1()
        //...
        virtual void funcN()
    }
    
    Vector<*Level> levels;
    levels.append(new Level1())
    //...
    levels.append(new LevelN())
    

  • It would be a bad design to have separate classes for each of the level and will also duplicate your code. Why can't you change the level specific values before starting a new level (have them stored in as some constant or in text file).

Tags
c++ levels objects
Related questions and answers
  • . For example, if I have 40 levels, and 1,000,000 XP for the last level, the first level up requirement is then 625. But if I change the levels to 80, the first level up becomes 156. In both cases...I'm trying to create a formula that can be modified simply by changing two values: number_of_levels, and last_level_experience. This is to enable people modding the game to change the levelling...; if (levels < 2) levels = 2; int experience_for_last_level = 1e6; float fraction = 1.0 / levels; { int i = 0; float fraction_counter = fraction; int counter

  • : How the Entity and its sprite interact in my current setup. class Entity { public: void handleEvent(const Event& event); void render(Surface* surf, unsigned long currentTime); // void...This is the first time I'm trying to make a 2D game, so I'm having quite a few difficulties in getting things right. Right now I'm trying to figure out exactly how the entity state machine should work. 1. I noticed entity states are... well, stateless. Basically, they just act on the data in the entity accordingly, they hold no data of their own. When an entity forwards events to its states

  • class. For example, I have a Actor class in C++, and I want to be able to create the same class in Lua and gain access to members with LuaPlus, but I can't figure how I can achieve that. Is this actually LuaPlus built-in functionality, or do I have to write my own interface that exchanges data tables between C++ and Lua? My current approach would be to fire an event in Lua that creates an new actor class in C++ code, and transfer its ID and the data I need to back to Lua. When I modify the data I send the modifications back to C++ code again, but I actually thought there's something

  • with different types of objects in the same scene. I was also thinking about making a MeshNode class and then make a Mesh object that contains them, but then I have some conflict on where to store some data... don't want to find out in the end that I have to rewrite everything again, as a lot of other objects will be working with these data. Sorry if it's a too subjective matter, but I need some insight. I'm... I was thinking about making smaller structures with the fTime variable each so I can have attribute keyframes, light keyframes and buffer keyframes, then make the node structure look like

  • is that glEdgeFlagv takes (quoting from documentation): a pointer to an array that contains a single Boolean element, which replaces the current edge flag value. What's the point of having a special version that takes a pointer to an array of length one? I can't imagine its to let you toggle the pointed-to bool to change the value later because the documentation would have to mention that to avoid inadvertent frees. I don't know of any platform where a pointer is smaller than a bool. When would one use glEdgeFlagv instead of glEdgeFlag?

  • I'm trying to write my level classes by having a base class that each level class inherits from...The base class uses pure virtual functions. My base class is only going to be used as a vector that'll have the inherited level classes pushed onto it...This is what my code looks like at the moment, I've tried various things and get the same result (segmentation fault). //level.h class Level... supposed to include in the inherited class structure, but this is what I have at the moment... //level1.h class Level1: public Level { public: Level1(); ~Level1(); void load(); void

  • the world for a few seconds ahead. It looks like I can make a parallel world the "long way" - for each body in the world, copy the body data back into a def and re-create it, then copy the fixtures... (and if so, was it actually a workable design or not?), or if Box2D has some affordance for doing this within its API which I am missing. ...I'm working on a platformer where I'd like to be able to move or copy bodies between multiple Box2D b2Worlds. The desire has cropped up three times now - moving objects between documents in my editor

  • In my code, I just have a Level class right now in the main game loop that just blits a background and spawns some enemies for testing purposes...But I can't figure out how to go about implementing multiple levels and level progression. What is the best way to manage multiple levels and level progression in a game? I'm thinking that I would make the Level class just read level data from a file, and create a Level vector...But I'm not sure if that's the best way to do it.

  • I want to make a simple game where I have some characters fighting on a plane (level). I find the trickiest part as figuring out who should do what here. I want my terrain to have friction (so you... on that, but I do not think this offers enough flexibility. I was thinking more along the lines of each player / character does have some logic. The Input from the game gives it the command... by its coefficient of friction. Because I don't think the player needs to know about the level (and preferably the level does not know about characters) It's in these little design aspects that I get

Data information