I've made this Supaplex-like game, but I have a problem.
I want to have more levels, so I've made that when moving to the next level, it clears the vectors with all the objects, and putting new objects into.

this is my code for moving to level 2:

void start_level(HWND m_hwnd){
    grasses.clear();
    persons.clear();
    bombs.clear();
    cinfos.clear();
    level++;
    switch(level){
        case 1:
            persons.push_back(man(1,2,m_hwnd,"person",true));
            grasses.push_back(grass(0,1,false));
            grasses.push_back(grass(1,0,false));
            grasses.push_back(grass(1,1,false));
            grasses.push_back(grass(2,0,false));
            grasses.push_back(grass(4,1,false));
            grasses.push_back(grass(4,2,false));
            grasses.push_back(grass(2,3,false));
            grasses.push_back(grass(1,4,false));
            grasses.push_back(grass(2,4,false));
            for(int i = 0; i <= 4; i++){
                grasses.push_back(grass(3,i,false));
            }
            bombs.push_back(bomb(0,2));
            bombs.push_back(bomb(0,4));
            bombs.push_back(bomb(1,3));
            bombs.push_back(bomb(2,2));
            bombs.push_back(bomb(2,1));
            bombs.push_back(bomb(4,3));
            bombs.push_back(bomb(4,0));
            cinfos.push_back(cinfo(0,0));
            cinfos.push_back(cinfo(0,3));
            cinfos.push_back(cinfo(4,4));
            break;
    }
    InvalidateRect(m_hwnd,NULL,TRUE);
}

It's working fine, except that it creates objects at places i haven't told to. For example:

cinfos.push_back(cinfo(0,0));
cinfos.push_back(cinfo(0,3));
cinfos.push_back(cinfo(4,4));

this part creates 3 cinfos (an object in the game :P), it's working fine when i'm only creating 2, but when creating 3, it's also creaing one at (4,3) and i really don't know why :/

And sometimes it's creating a bomb object at (0,0)

I hope that anybody can help me!

I don't know the answer to your question but there's got to be a much simplier way to code that switch statement. What are you going to do if someone wants to be a level 255? Lets see -- 20 lines of code for level 2 I guess will mean over 5,000 lines of code for level 255. Not a very efficient program.

that's no problem because there's only 3 levels :P
it's my first C++ game ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.