⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 billard3d.c

📁 这是一个相当棒的Linux下的台球游戏
💻 C
📖 第 1 页 / 共 5 页
字号:
void shoot( int ani ){    int other_player;    other_player = (act_player==0) ? 1 : 0 ;    if ( player[other_player].is_net ){        DPRINTF("shoot: handling unresolved net request\n");        switch(g_net_state){        case NET_STATE_ACK:            while( !net_get_ack() );        case NET_STATE_DATA:            g_net_data.shoot=0;            net_send_data();        case NET_STATE_REQ: break;        }        fprintf(stderr,"shoot: sending new data with shot\n");        net_send_send_req();        while( !net_get_ack() );        g_net_data.shoot=1;        net_send_data();        g_net_data.shoot=0;        g_net_state=NET_STATE_REQ;    }    if( ani ){        DPRINTF("shoot: ani-shot\n");        queue_anim=30;    } else {        DPRINTF("shoot: direct shot\n");        queue_shot();    }}intin_cue_ball_region( VMvect pos ){    int in_region=1;    switch(gametype){    case GAME_8BALL:    case GAME_9BALL:        if( pos.x >  (TABLE_W-BALL_D)/2.0 )  in_region=0 ;        if( pos.x < -(TABLE_W-BALL_D)/2.0 )  in_region=0 ;        if( pos.y > -TABLE_L/4.0          )  in_region=0 ;        if( pos.y < -(TABLE_L-BALL_D)/2.0 )  in_region=0 ;        break;    case GAME_CARAMBOL:        break;    case GAME_SNOOKER:#define TABLE_SCALE (TABLE_L/(3.571042))        if( pos.y > -TABLE_L/2.0+TABLE_SCALE*0.737 ) in_region=0 ;        if( vec_abs(vec_diff(pos,vec_xyz(0,-TABLE_L/2.0+TABLE_SCALE*0.737,0))) > TABLE_SCALE*0.292 ) in_region=0 ;#undef TABLE_SCALE        break;    }    return(in_region);}intin_table_region( VMvect pos ){    int in_region=1;    if( pos.x >  (TABLE_W-BALL_D)/2.0 )  in_region=0 ;    if( pos.x < -(TABLE_W-BALL_D)/2.0 )  in_region=0 ;    if( pos.y >  (TABLE_L-BALL_D)/2.0 )  in_region=0 ;    if( pos.y < -(TABLE_L-BALL_D)/2.0 )  in_region=0 ;    return(in_region);}static void ball_free_place( int ind, BallsType * pballs ){        int i,exitloop;        double x,y, x0,y0, r,phi;        x=pballs->ball[ind].r.x; y=pballs->ball[ind].r.y;        x0=x; y0=y;        phi=0.0;        do{            exitloop=1;            r=floor(phi/2.0/M_PI)*0.01;            x=x0+r*cos(phi);            y=y0+r*sin(phi);            DPRINTF("phi=%f\n", phi);            DPRINTF("ind=%d, CUE_BALL_IND=%d\n", ind, CUE_BALL_IND);            if( ( ind==CUE_BALL_IND && in_cue_ball_region(vec_xyz(x,y,0)) && player[act_player].place_cue_ball ) ||                in_table_region(vec_xyz(x,y,0))              )            {            } else exitloop=0;            DPRINTF("1:exitloop=%d\n", exitloop);            for(i=0;i<pballs->nr;i++) if( i!=ind && pballs->ball[i].in_game ){                if ( vec_abs(vec_diff(vec_xyz(x,y,0),pballs->ball[i].r)) <                     (pballs->ball[ind].d+pballs->ball[i].d)/2.0 )                { exitloop=0; break; }            }            DPRINTF("2:exitloop=%d\n", exitloop);            phi+=0.01;        } while(!exitloop);        pballs->ball[ind].r.x=x;        pballs->ball[ind].r.y=y;}static void all_balls_free_place(BallsType * pballs){    int i;    for(i=0;i<pballs->nr;i++) if( pballs->ball[i].in_game ){        ball_free_place( i, pballs );    }}//static void Idle_timer( int value )static void Idle_timer( void ){    int i;//    static int balls_moving=0;    static int balls_were_moving=0;    static int first_time=1;    int t_act;    static int dt;    static int t_prev=-1;    static int frametime_rest=0;//    static int frametime_fromlast=0;//    static int framestep=0;    static int dt_rest=0;    static int count=0;    static double dt_s_rest=0.0;//    static int waiting_for_net_data=0;    int other_player;    double fact;    count++;    t_act   = time_us();    if (t_prev==-1)  t_prev=t_act;    dt     += t_act-t_prev;    dt_s_rest += (double)(t_act-t_prev)/1000000.0;    t_prev  = t_act;    if(count==1){        count=0;        frametime_ms=(int)((double)dt/1000.0);        if( frametime_ms<1 ) frametime_ms=1;//        if( frametime_ms<frametime_ms_min ) frametime_ms=frametime_ms_min;        if( frametime_ms>frametime_ms_max ) frametime_ms=frametime_ms_max;        dt=0;        dt_rest+=frametime_ms;//        frametime_ms=frametime_ms_min;    }//    glutTimerFunc( frametime_ms*0.8,       /* -5 for assuring framerate increase *///                   Idle_timer, value );  /* assure a framerate of max ... fps *///    glutTimerFunc( frametime_ms_min, Idle_timer, value );    sys_set_timer( frametime_ms_min, Idle_timer) ;#ifdef USE_SOUND#ifndef USE_SDL    mixaudio();#endif#endif//    fprintf(stderr,"dt=%d\n",dt);    fact=pow(0.85,(double)frametime_ms/50.0);//    fact=0.85;    Xrot_offs *= fact;    Zrot_offs *= fact;    fact=pow(0.94,(double)frametime_ms/50.0);//    fact=0.94;    cam_dist = (cam_dist*fact)+(cam_dist_aim+vec_abs(balls.ball[CUE_BALL_IND].v)*0.4)*(1.0-fact);    free_view_pos = vec_add( vec_scale( free_view_pos, fact ), vec_scale( free_view_pos_aim, 1.0-fact ) );    if (Animate) {//        int bhit=0;//        int whit=0;        double bhitstrength=0.0;        double whitstrength=0.0;        double toffs=0.0;//      Xrot += DXrot;//      Yrot += DYrot;#if 0        first_time=1; /* to get into loop when balls not moving */        for(i=0;            (balls_moving || first_time ) &&            (             i<(frametime_ms+frametime_rest)/(int)(10.0/g_motion_ratio) /* assure constant time flow */            );            i++)#else       while(dt_s_rest>0.0) /* assure constant time flow */#endif       {        first_time=0; /* to get into loop when balls not moving *///       for(i=0;i<(frametime_ms+frametime_rest)/3;i++){   /* assure constant time flow *///       for(i=0;i<(frametime_ms+5)/10;i++){   /* assure constant time flow *///           balls_moving = proceed_dt( &balls, &walls, 0.01 );#ifdef TIME_INTERPOLATE           copy_balls(&balls,&g_lastballs);#endif#define TIMESTEP 0.0075           dt_s_rest-=TIMESTEP/0.75/g_motion_ratio;//           printf("g_motion_ratio=%f\n",g_motion_ratio);           balls_moving = proceed_dt( &balls, &walls, TIMESTEP );           if(balls_moving) balls_were_moving = 1;           /* 0.0075 instead of 0.01 - finetuning *//*           bhitstrength+=BM_get_balls_hit_strength_last();           whitstrength+=BM_get_walls_hit_strength_last();*///           fprintf(stderr,"whitstrength=%f\n",whitstrength);//           fprintf(stderr,"bhitstrength=%f\n",bhitstrength);#ifdef USE_SOUND           {           int index;           index=0;           do{               BM_get_balls_hit_strength_last_index( index++ ,&bhitstrength, &toffs );               bhitstrength = 1.75 * (0.3 * bhitstrength / CUEBALL_MAXSPEED +                                      0.7 * bhitstrength*bhitstrength / CUEBALL_MAXSPEED / CUEBALL_MAXSPEED);               if(bhitstrength!=0.0){                   if( toffs>TIMESTEP || toffs<0.0 ){                       exit(0);                   }else{//                       printf("toffs/TIMESTEP=%f\n",toffs/TIMESTEP);                   }                   PlaySound_offs(&ball_ball_snd,options_snd_volume*((bhitstrength>1.0)?1.0:bhitstrength), SOUND_NULLOFFS-(TIMESTEP-toffs)*22050);               }           } while(bhitstrength!=0.0);           index=0;           do{               BM_get_walls_hit_strength_last_index( index++ ,&whitstrength, &toffs );               whitstrength = 0.4 * (0.3 * whitstrength / CUEBALL_MAXSPEED +                                     0.7 * whitstrength*whitstrength / CUEBALL_MAXSPEED / CUEBALL_MAXSPEED);               if(whitstrength!=0.0){                  PlaySound_offs(&ball_wall_snd,options_snd_volume*((whitstrength>1.0)?1.0:whitstrength), SOUND_NULLOFFS-(TIMESTEP-toffs)*22050);//                  PlaySound(&ball_wall_snd,(whitstrength*0.125>1.0)?1.0:whitstrength*0.125);               }           } while(whitstrength!=0.0);           }#endif        if (!balls_moving) break;       }       if (dt_s_rest>0.0) dt_s_rest=0.0; /* to move on if last move was completely in last simulation step */#ifdef TIME_INTERPOLATE       if((frametime_ms+frametime_rest)/10>0)           g_frametime_laststep = (frametime_ms+frametime_rest)/10*10;       g_frametime_fromlast = frametime_rest;#endif       frametime_rest = (frametime_ms+frametime_rest) % 10;       if(options_balltrace){           for(i=0;i<balls.nr;i++) if( balls.ball[i].in_game ){               BM_add2path( &balls.ball[i] );           }       }/*#ifdef USE_SDL       if(bhitstrength!=0.0){           PlaySound(&ball_ball_snd,(bhitstrength*0.25>1.0)?1.0:bhitstrength*0.25);       }       if(whitstrength!=0.0){           PlaySound(&ball_wall_snd,(whitstrength*0.125>1.0)?1.0:whitstrength*0.125);       }#endif*//*       for(;dt_rest>=10;dt_rest-=10){           balls_moving = proceed_dt( &balls, &walls, 0.0075 );       }*/       if( (!balls_moving) && balls_were_moving ){           int i;           int old_queue_view;           /* allways a shot to be due when balls just stopped moving */           g_shot_due=1;           balls_were_moving=0;           //           evaluate_last_move();           old_queue_view=queue_view;           if(options_gamemode!=options_gamemode_training){               evaluate_last_move( player, &act_player, &balls, &queue_view, &Xque );               if(!tournament_state.wait_for_next_match &&                  options_gamemode==options_gamemode_tournament &&                  (player[0].winner || player[1].winner) )               {                   tournament_evaluate_last_match( &tournament_state );                   tournament_state.wait_for_next_match=1;               }           } else {               int old_cueball_ind;               player[act_player].place_cue_ball=1;               /* find a ball still in game */               old_cueball_ind=CUE_BALL_IND;               while(!balls.ball[CUE_BALL_IND].in_game){                   CUE_BALL_IND++;                   if(CUE_BALL_IND==balls.nr) CUE_BALL_IND=0;                   if(CUE_BALL_IND==old_cueball_ind) break;               }           }           if( old_queue_view==1 && queue_view==0  ) /* this is sloppy and ugly */           { /* set free_view_pos to actual view */               double th=Xrot/180.0*M_PI;               double ph=Zrot/180.0*M_PI;               free_view_pos_aim = vec_scale(vec_xyz(sin(th)*sin(ph),sin(th)*cos(ph),cos(th)), cam_dist);               free_view_pos_aim = vec_add( free_view_pos_aim, CUE_BALL_XYPOS );               free_view_pos = free_view_pos_aim ;           }           /* no balls should overlap */           all_balls_free_place(&balls);           /* score text */           for(i=0;i<2;i++){               char str[256];               switch(gametype){               case GAME_8BALL: strcpy(str,"0"); break;               case GAME_9BALL:                   {                       int j;                       int minballnr=15;                       for(j=0;j<balls.nr;j++){                           if(balls.ball[j].nr<minballnr && balls.ball[j].nr!=0 && balls.ball[j].in_game)                               minballnr=balls.ball[j].nr;                       }                       player[i].next_9ball = minballnr;                       sprintf( str, "next:%d", minballnr );                   }                   break;               case GAME_CARAMBOL:                   sprintf( str, "%d", player[i].score );                   break;               case GAME_SNOOKER:                   sprintf( str, "%c%03d  %s", (player[i].score<0)?'-':'+', abs(player[i].score), player[i].snooker_on_red ? "red":"col" );                   break;               }               textObj_setText( player[i].score_text, str );           }       }       if(g_shot_due &&          !( options_gamemode==options_gamemode_tournament &&            (tournament_state.wait_for_next_match || tournament_state.tournament_over)           )/*          g_act_menu==0 &&          !helpscreen_on*/         )       {//           first_time=0;           g_shot_due=0;           if( player[act_player].is_AI && !(player[act_player].winner || player[(act_player+1)%2].winner) ){               do_computer_move(1);           }           if( (!player[act_player].is_AI) && player[act_player].is_net ){               fprintf(stderr,"waiting for net move----------------------------------------------\n");               //               do_net_move();           }       }       other_player = (act_player==0) ? 1 : 0 ;       if( !balls_moving && queue_anim==0.0 ){#if 1           if      ( player[act_player].is_net ){               switch(g_net_state){               case NET_S

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -