Пример #1
0
void weather_effect::snowstorm(game *g)
{
	snow(g);
}
int main()
try {

    Point tl(300,50);
    Simple_window win(tl,1000,800,"My window");
    win.wait_for_button();
    win.set_label("My window");

    // add grid on leftmost 800-by-800 part
    Lines grid;
    int x_size = 800;
    int y_size = 800;
    for (int i = 100; i<=x_size; i+=100) {
        grid.add(Point(i,0),Point(i,y_size));
        grid.add(Point(0,i),Point(x_size,i));
    }
    win.attach(grid);
    //win.resize(1000,800);
    win.wait_for_button();

    // make squares on the diagonal red
    Vector_ref<Graph_lib::Rectangle> vr;
    for (int i = 0; i<8; ++i) {
        vr.push_back(new Graph_lib::Rectangle(Point(i*100,i*100),101,101));
        vr[vr.size()-1].set_fill_color(Color::red);
        win.attach(vr[vr.size()-1]);
    }
    //win.resize(1000,800);
    win.wait_for_button();

    // place 3 copies of a 200-by-200 image, don't cover the red squares
    Image plane1(Point(200,0),"pics_and_txt/image.jpg");
    plane1.set_mask(Point(200,0),200,200);
    win.attach(plane1);
    Image plane2(Point(500,200),"pics_and_txt/image.jpg");
    plane2.set_mask(Point(200,0),200,200);
    win.attach(plane2);
    Image plane3(Point(100,500),"pics_and_txt/image.jpg");
    plane3.set_mask(Point(200,0),200,200);
    win.attach(plane3);
    //win.resize(1000,800);
    win.wait_for_button();

    // add a 100-by-100 image, have it move around
    Image snow(Point(0,0),"pics_and_txt/snow_cpp.gif");
    snow.set_mask(Point(110,70),100,100);
    win.attach(snow);
    //win.resize(1000,800);
    win.wait_for_button();

    int x = 0;
    int y = 0;
    int dx = 0;
    int dy = 0;
    while (true) {
        x = randint(8);
        y = randint(8);
        dx = 100*x - snow.point(0).x;
        dy = 100*y - snow.point(0).y;
        snow.move(dx,dy);
        //win.resize(1000,800);
        win.wait_for_button();
    }
}
catch (exception& e) {
    cerr << "exception: " << e.what() << endl;
    keep_window_open();
}
catch (...) {
    cerr << "exception\n";
    keep_window_open();
}
Пример #3
0
int qml_interface::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            itFogz();
            break;
        case 1:
            destroyAll();
            break;
        case 2:
            fair();
            break;
        case 3:
            pCloudy();
            break;
        case 4:
            cloudy();
            break;
        case 5:
            rain();
            break;
        case 6:
            thunder();
            break;
        case 7:
            snow();
            break;
        case 8:
            updateSlot();
            break;
        case 9:
            replyFinished((*reinterpret_cast< QNetworkReply*(*)>(_a[1])));
            break;
        case 10: {
            QString _r = getWindSpeed();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 11: {
            QString _r = getWindDirection();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 12: {
            QString _r = getTemperature();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 13: {
            QString _r = getTime();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 14: {
            QString _r = depsurx();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 15: {
            QString _r = arvsurx();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 16: {
            QString _r = depsury();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 17: {
            QString _r = arvsury();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 18: {
            QString _r = depsurz();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 19: {
            QString _r = arvsurz();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 20: {
            QString _r = getNextUpdate();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 21: {
            QString _r = getFrequence();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 22: {
            QString _r = getSymbol();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        case 23:
            ItFogs();
            break;
        case 24: {
            int _r = getPositionCiel();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r;
        }
        break;
        case 25:
            setSymbol();
            break;
        case 26: {
            QString _r = getRandomInteger();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r;
        }
        break;
        default:
            ;
        }
        _id -= 27;
    }
#ifndef QT_NO_PROPERTIES
    else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0:
            *reinterpret_cast< Forecast*>(_v) = getCurrentForecast();
            break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::WriteProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 1;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #4
0
int main(int argc, char *argv[])
{
    (void) argc;
    (void) argv;

    //SDL is used for inputs and time
    SDL_Init(SDL_INIT_VIDEO);
    atexit(SDL_Quit);
    SDL_EnableKeyRepeat(10, 10);


    Graph *graph=new Graph_SDL();
    graph->init();
    //create vox obj
    std::vector<VoxImg*> walk_anim;
    walk_anim.push_back(new VoxImg("data/perso_stand.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_walk1.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_walk2.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_walk1.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_stand.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_walk3.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_walk4.vox",VOX_FILE));
    walk_anim.push_back(new VoxImg("data/perso_walk3.vox",VOX_FILE));
    float anim_index=0;

    VoxImg img_palet("data/palet2.vox",VOX_FILE);
    Vox_Scene scene(160,120,70,img_palet);
    Vox_Scene ground(160,120,70,img_palet);
    VoxSpr perso(walk_anim.at(anim_index));
    VoxSpr palet(&img_palet);
    ground.init();

    Draw_Vox_Ortho *draw=new Draw_Vox_Ortho(graph,&scene);//maybe create a generic class for otho or perspective
    new Particle_Manager(&scene,&ground);

    //----- events -----
    SDL_Event event;

    //----- timing -----
    Uint32 last_time = SDL_GetTicks();
    Uint32 current_time,ellapsed_time,start_time;
    Uint32 previous_fps_time=SDL_GetTicks()/1000;
    int fps=0;


    double angleZ = 0;
    double angleY = 0;
    double angleX = 0;

    Pt3d pos(10,10,10);

    Pt3d ball(10,10,1);
    double ball_r=4;

    Pt3d ball_v(1,1,1);


    bool run=true;
    double t=0.0;
    while (run)
    {
        fps++;

        start_time = SDL_GetTicks();
        while (SDL_PollEvent(&event))
        {

            switch(event.type)
            {
            case SDL_QUIT:
                exit(0);
                break;

            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                case SDLK_ESCAPE:
                    run=false;
                    break;
                case SDLK_UP:
                    pos.x-=pseudo_normalize(draw->vect_vox_x_c.z,graph->ORTHO_ZOOM);
                    pos.y-=pseudo_normalize(draw->vect_vox_y_c.z,graph->ORTHO_ZOOM);
                    anim_index+=0.5;
                    break;
                case SDLK_DOWN:
                    pos.x+=pseudo_normalize(draw->vect_vox_x_c.z,graph->ORTHO_ZOOM);
                    pos.y+=pseudo_normalize(draw->vect_vox_y_c.z,graph->ORTHO_ZOOM);
                    anim_index+=0.5;
                    break;
                case SDLK_RIGHT:
                    pos.x+=pseudo_normalize(draw->vect_vox_x_c.x,graph->ORTHO_ZOOM);
                    pos.y+=pseudo_normalize(draw->vect_vox_y_c.x,graph->ORTHO_ZOOM);
                    anim_index+=0.5;
                    break;
                case SDLK_LEFT:
                    pos.x-=pseudo_normalize(draw->vect_vox_x_c.x,graph->ORTHO_ZOOM);
                    pos.y-=pseudo_normalize(draw->vect_vox_y_c.x,graph->ORTHO_ZOOM);
                    anim_index+=0.5;
                    break;
                case SDLK_q:
                    pos.x-=pseudo_normalize(draw->vect_vox_x_c.y,graph->ORTHO_ZOOM);
                    pos.y-=pseudo_normalize(draw->vect_vox_y_c.y,graph->ORTHO_ZOOM);
                    anim_index+=0.5;
                    break;
                case SDLK_w:
                    pos.x+=pseudo_normalize(draw->vect_vox_x_c.y,graph->ORTHO_ZOOM);
                    pos.y+=pseudo_normalize(draw->vect_vox_y_c.y,graph->ORTHO_ZOOM);
                    anim_index+=0.5;
                    break;
                default:
                    break;
                }
                break;

            case SDL_MOUSEMOTION:
                angleZ -= event.motion.xrel*0.01;
                angleX += event.motion.yrel*0.01;
                break;

            case SDL_MOUSEBUTTONDOWN:
                if ((event.button.button == SDL_BUTTON_WHEELUP)&&(event.button.type == SDL_MOUSEBUTTONDOWN))
                {
                }
                if ((event.button.button == SDL_BUTTON_WHEELDOWN)&&(event.button.type == SDL_MOUSEBUTTONDOWN))
                {
                }
                break;

            }
        }

        for (int i=0; i<10; i++)
        {
            Pt3d snow(rand()%scene.xsiz,rand()%scene.ysiz,0);
            Pt3d snow_speed(0,0,1);
            /*if (int(t*20)%10==0)*/ Particle_Manager::the_one->add_particle(31,snow,snow_speed,0);
        }
        Particle_Manager::the_one->update();
        ground.sub(palet);
        if (anim_index>=walk_anim.size()) anim_index=0;
        if (anim_index<0) anim_index=walk_anim.size()-0.01;
        perso.set_img(walk_anim.at((int)anim_index));
        perso.set_pos(pos);
        palet.set_pos(ball);
        scene.reinit(ground);//have to reinit scene AFTER modifications (add, sub, particle update), and JUST before blit!
        Particle_Manager::the_one->blit_all();
        scene.blit(perso);
        scene.blit(palet);

        //angleZ += 0.00020 * ellapsed_time;
        //angleY += 0.00023 * ellapsed_time;
        //angleX += 0.00027 * ellapsed_time;
        t+=0.05;

        ball.add(ball_v,&ball);
        if (ball.x>=scene.xsiz-ball_r-1) ball_v.x*=-1;
        if (ball.y>=scene.ysiz-ball_r-1) ball_v.y*=-1;
        if (ball.z>=scene.zsiz-1) ball_v.z*=-1;
        if (ball.x<=ball_r) ball_v.x*=-1;
        if (ball.y<=ball_r) ball_v.y*=-1;
        if (ball.z<=0) ball_v.z*=-1;
        if (ground.collide(palet) && (ball_v.z>0)) ball_v.z*=-1;

        if (!ground.touch_bottom(perso)) pos.z+=1;
        else if (ground.collide(perso)) pos.z-=1;
        /*else
        {
            //if (obj1.pos.z<scene.zsiz)
            {
                obj1.pos.z+=1;
                if (!ground.collide(perso)) pos.z+=1;
                obj1.pos.z-=1;
            }
        }*/

        //drawing
        draw->update_camera(100,100,0,angleX,angleY,angleZ);
        draw->render();


        //----- timing -----
        if (previous_fps_time!=current_time/1000)
        {
            std::cout<<"FPS: "<<fps<<std::endl;
            previous_fps_time=current_time/1000;
            fps=0;
        }
        current_time = SDL_GetTicks();
        ellapsed_time = current_time - last_time;
        last_time = current_time;
        ellapsed_time = SDL_GetTicks() - start_time;
        //if (ellapsed_time < 20)
        //    SDL_Delay(20 - ellapsed_time);
        //----- end timing -----
    }


    return 0;
}