Exemplo n.º 1
0
osg::ref_ptr< osg::Group > LevelManager::loadLevel( const std::string& levelFile )
{
    log_info << "LevelManager: start loading level: " << levelFile << std::endl;

    // store the level file name, we will use it for physics serialization
    _levelFile = levelFile;

    // clear the entity list used for loading process
    _setupQueue.clear();

    // send loading notification
    {
        EntityNotification ennotify( YAF3D_NOTIFY_LOADING_LEVEL );
        EntityManager::get()->sendNotification( ennotify );
        // flush the notification queue so perior and new entities get the notification
        EntityManager::get()->flushNotificationQueue();
    }

    std::vector< BaseEntity* > entities; // list of all entities which are created during loading
    if ( !loadEntities( levelFile, &entities ) )
    {
        log_error << "LevelManager: error loading entities" << std::endl;
        return NULL;
    }

    return _topGroup;
}
Exemplo n.º 2
0
void BattleController::viewDidLoad()
{
    loadBattleGround();
    
    //create battle layer
    loadBattleWorld();
    
    loadEntities();
    
//    showCoordinate();
    
    //create test button
    
    CCMenuItemLabel *skipBtn=CCMenuItemLabel::create(CCLabelTTF::create("skip", "Arial", 34),
                                                   this,
                                                   menu_selector(BattleController::onSkip));
    
    CCMenuItemLabel *startBtn=CCMenuItemLabel::create(CCLabelTTF::create("start", "Arial", 34),
                                                     this,
                                                     menu_selector(BattleController::onStart));

    CCMenu* menu=CCMenu::create(skipBtn,startBtn,NULL);
    menu->alignItemsHorizontally();
    
    m_view->addChild(menu);
    
}
Exemplo n.º 3
0
int main(int argc, char** argv) {
    (void) argc;
    (void) argv;
    /*srand(time(NULL));*/
#ifdef WIN32
    {
        LARGE_INTEGER divisor;
        QueryPerformanceFrequency(&divisor);
        clockDivisor = divisor.QuadPart;
    }
#else
    clockDivisor = CLOCKS_PER_SEC;
#endif
    printf("Starting\nClock divisor: %lu\n", clockDivisor);

    struct graphics g = {
#ifdef SHOWKEYS
        .width = 100, .height = 100,
#else
        .width = 1200,
        .height = 900,
#endif
    };
    initiateGraphics(&g, "Test window");

    if(!g.window) goto CLEANUP;
    /*thread t;*/
    /*newThread(test, NULL, &t);*/

    clockType frameStart, frameEnd, gameStart;
    getClockTime(&frameStart);

    initLogic();
    loadEntities();
    loadTileTextures();
    initializeWorld();
    initializeBullets();
    initializeItems();
    initializeItemFunctions();
    luaStart();

    getClockTime(&gameStart);

    while(1){
        cameraTick();
        renderGraphics(&g);

        oldMouseState = mouseState;
        mouseState = SDL_GetMouseState(&mouseX, &mouseY);
        if(oldMouseState != mouseState){
            mouseEvent();
        }
        for(SDL_Event event; SDL_PollEvent(&event);){
            switch(event.type){
            case SDL_QUIT:
                goto CLEANUP;
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                if(event.key.keysym.scancode == 0x14) goto CLEANUP; //TODO
                keyEvent(event.key);
            break;
            }
        }

        getClockTime(&frameEnd);
        frameTime = getDiffClock(frameStart, frameEnd);
        appTime = getDiffClock(gameStart, frameEnd);
        frameStart = frameEnd;
        gameUpdate();
    }
CLEANUP:

    luaEnd();
    uninitializeItems();
    uninitializeItemFunctions();
    uninitializeBullets();
    uninitializeWorld();
    unloadTileTextures();
    unloadEntities();
    destroyGraphics(&g);

    return 0;
}

float normalRandomFloat(){
    return ((float) rand()) / ((float) RAND_MAX);
}

float randomFloat(float a, float b){
    float diff = b - a;
    return a + normalRandomFloat() * diff;
}