Esempio n. 1
0
int main(int argc, char* argv[]){

    // Reset keyboard
    for(unsigned char i = 0; i < 0xff; i ++){
        keys[i] = 0;
    }

    // Exit function
    atexit(cleanup);

    // OpenGL
    glutInit(&argc, argv);
    initRendering();

    // OpenGL / glut callback functions
    glutDisplayFunc(drawScene);
    glutKeyboardFunc(handleKeyboard);
    glutKeyboardUpFunc(handleKeyboardUp);
    glutSpecialFunc(handleKeyboardSpecial);
    glutReshapeFunc(handleResize);
    glutIdleFunc(NULL);
    glutTimerFunc(ms_delay, handleTimer, 0); //TODO: what should the numbers be?

    /// Team and Player Stuff

    // Camera Stuff
    camera.set_centre_x(350.0d);
    camera.set_centre_y(250.0d);
    camera.set_width(4*200.0d);
    camera.set_w2h_ratio(1.0d);
    camera.set_cam_vel(4*200.0d / fps);

    // Create Teams
    global.addTeams(2);

    // Setup the Battlefield
    global.addArenaSection(0.0d, 0.0d, 700.0d, 500.0d);
    global.setArenaSectionState(0, AREA_TYPE_NEUTRAL);
    global.addArenaSection(battlefield(50.0d, 50.0d, 100.0d, 400.0d));
    global.setArenaSectionState(1, AREA_TYPE_BASE);
    global.addArenaSection(battlefield(600.0d, 50.0d, 100.0d, 400.0d));
    global.setArenaSectionState(2, AREA_TYPE_BASE);


    // Setup spawnpoints
    global.addSpawnPoint(spawnpoint())

    global.addSoldier(soldier());
//    // TODO: Random Soldiers
//    nextsoldier.color_red = 0.5d; nextsoldier.color_green = 0.8d; nextsoldier.color_blue = 0.0d;
//    nextsoldier.m_ab_viewrange = 10.0;
//    nextsoldier.giveObjective(0.0d, 0.0d, nextsoldier.TRANSIT_TYPE_GUNRUN, nextsoldier.OBJECTIVE_TYPE_JUSTMOVE);


    for(unsigned int addsol = 0; addsol < 1; addsol ++){
        //team0.soldiers.at(addsol).spos(-320.0d, -50.0d + 20.0d * addsol);
        //team1.soldiers.at(addsol).spos(+320.0d, -60.0d + 20.0d * addsol);
    }



    /// Team and Player Stuff

    // Main loop
    glutMainLoop();

    return EXIT_SUCCESS;
}
Esempio n. 2
0
int main(int argc, char* argv[]) {
    init_random_gen();
    //SDL init;
    std::cout<<"init sdl"<<std::endl;
    if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_OPENGL|SDL_INIT_TIMER)==-1) {
        std::cerr<<"sdl init failed..."<<SDL_GetError()<<std::endl;
        return 1;
    }

    IMG_Init(IMG_INIT_PNG);

    std::cout<<"init video"<<std::endl;
    screen=SDL_SetVideoMode(SCREEN_W,SCREEN_H,SCREEN_DEPTH,SDL_OPENGL|SDL_DOUBLEBUF);
    if (!screen) {
        std::cerr<<"video init failed..."<<std::endl;
        return 1;
    }
    SDL_WM_SetCaption("FrEEsIegE FiGHt",NULL);
    TextureIds texture_ids=init_opengl(screen->w,screen->h,N_TEXTURE);

    //object init
    std::string base_dir=get_base_dir();
    SpriteCollection spr_coll(base_dir+"sprites.cfg",base_dir+"anims.cfg",base_dir,texture_ids);
    std::cout<<spr_coll<<std::endl;

    Background background(&spr_coll);
    Foreground foreground(&spr_coll);
    LifeBar life_bar1(&spr_coll,PLAYER_1);
    LifeBar life_bar2(&spr_coll,PLAYER_2);
    BattleField battlefield(&spr_coll,&life_bar1,&life_bar2,&foreground);

    //mutex timer init
    counter_reset_mutex=SDL_CreateMutex();
    SDL_TimerID counter_reset_id=SDL_AddTimer(1000,counter_reset_callback,NULL);

    bool quit=false;
    SDL_Event event;
    Uint32 ticks=SDL_GetTicks();
    while (!quit) {
        //draw
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        background.draw();
        life_bar1.draw();
        life_bar2.draw();
        battlefield.refresh();
        battlefield.draw();
        foreground.draw();
        SDL_GL_SwapBuffers();
        SDL_Flip(screen);
        //logic

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                if (event.key.keysym.sym!=SDLK_ESCAPE) {
                    switch (event.key.keysym.sym) {
                    //unit spawn keys
                    case SDLK_a:
                        battlefield.spawn(SOLDIER,PLAYER_1);
                        break;
                    case SDLK_q:
                        battlefield.spawn(SOLDIER,PLAYER_2);
                        break;
                    case SDLK_z:
                        battlefield.spawn(DRUID,PLAYER_1);
                        break;
                    case SDLK_s:
                        battlefield.spawn(DRUID,PLAYER_2);
                        break;
                    case SDLK_e:
                        battlefield.spawn(KNIGHT,PLAYER_1);
                        break;
                    case SDLK_d:
                        battlefield.spawn(KNIGHT,PLAYER_2);
                        break;
                    case SDLK_r:
                        battlefield.spawn(GOLEM,PLAYER_1);
                        break;
                    case SDLK_f:
                        battlefield.spawn(GOLEM,PLAYER_2);
                        break;
                    case SDLK_t:
                        battlefield.spawn(PLANT,PLAYER_1);
                        break;
                    case SDLK_g:
                        battlefield.spawn(PLANT,PLAYER_2);
                        break;
                    case SDLK_y:
                        battlefield.spawn(DRAGON,PLAYER_1);
                        break;
                    case SDLK_h:
                        battlefield.spawn(DRAGON,PLAYER_2);
                        break;
                    case SDLK_u:
                        battlefield.spawn(FLOWER,PLAYER_2);
                        break;
                    case SDLK_j:
                        battlefield.spawn(FLOWER,PLAYER_1);
                        break;
                    case SDLK_o:
                        battlefield.spawn(VETERAN,PLAYER_2);
                        break;
                    case SDLK_l:
                        battlefield.spawn(VETERAN,PLAYER_1);
                        break;
                    default:
                        break;
                    }
                    break;
                }
            case SDL_QUIT:
                quit=true;
                break;
            default:
                break;
            }
        }

        while (ticks>(SDL_GetTicks()-1000/FPS)) SDL_Delay(3);
        ticks=SDL_GetTicks();

        current_fps++;
    }

    SDL_RemoveTimer(counter_reset_id);
    SDL_DestroyMutex(counter_reset_mutex);

    IMG_Quit();

    SDL_Quit();
    return 0;
}