这个游戏名叫军事演习 用这个来运行!

double A = 3.2,  //加速度
       Vi=65; //炮弹初始速度
int x0=-300,y0=-250;  // 炮弹初始位置
double  Vx,Vy; // 炮弹初始水平速度,垂直速度
int  x,y; //炮弹的坐标
int ang ;  //炮的角度
int score;  //得分
int objx  ; //目标位置
int t0,tt; //时间
int hard=2; //难度=1为300s,难度=2为150s,难度=3为100s,难度=4为73s, ..
void calcV(double ang){ //炮的角度
    Vx = Vi * cos( ang );
    Vy = Vi * sin( ang );
}
void calcXY(double t){ //时间t计算炮弹位置坐标
    x = x0 + Vx*t;
    y = y0 + Vy*t - A*t*t;
}

void lunch(double ang){
    calcV( ang );
    double t=0; 
    calcXY(t);
    p.size(1);
    for (; y>y0-2 ; t+=0.1 )
    {
        calcXY(t);
        p.moveTo(x,y);
        p.o(1,13);
        wait(0.01);
    }
}
void getAng(){//获得炮的角度
    p.cav(0).clsRec();
    if ( ang<90 && buttonMP(2) )   
       ang++;
    if ( ang>15 && buttonMP(3) )   
       ang--;
    p.moveTo(x0+3,y0-100).text(ang,0,35);
    p.moveTo(x0,y0);   
    
    p.picU(0).setAngle(90-ang).fd(20).rr(4,50,10).picU(1);    
}
void showScore(){
    string tt=""+d2s(score*20);
    p.cav(1).moveTo(230,204).clsRec(150,150).c(15).text(tt);
}
void init (){  
    p.up().speed(10).hide();
    ang=15;
    score=0;   
    showScore();
    p.picL(1,"1/20057/迷彩939tank.png").picL(2,"1/20057/yanxi01.png").picL(3,"1/20057/yanxi02.png");
    p.picL(4,"1/20057/baning001.png").soundL(100,"1/20057/炮弹.wav").soundVol(100,0.3);
    p.soundL(101,"1/20057/不成功炮弹.wav").soundVol(101,0.3);
    p.soundL(102,"1/20057/战斗背景急促.wav").soundVol(102,0.2).soundLoop(102);
    p.soundL(103,"1/20057/炮弹失败.wav").soundVol(103,0.2);
    p.picL(8,11,"3205/碉堡.png",1);
    
    p.cav(-1);
    p.rgb(15,7,128).c(16);
    p.button(1,"发  射",4,20,0,0,y0-95,16,16);//pen.button(id,string,col,size, dir,x,y,bgcol,edgecol);
    p.button(2,"+",15,22,0,x0-50,y0-100,1);
    p.button(3,"-",15,22,0,x0+50,y0-100,1);
 
    p.moveTo(0,0).pic(1);
    
}
void showObj(){    
    p.cav(1);
    p.moveTo(objx,y0).clsRec(100,100);
    int xx;
    for(;;){
        xx=rand(-10,18)*20;
        if (abs(xx-objx)>100)
            break;
    }
    objx=xx;
    p.moveTo(objx,y0).pic(rand(8,11)); //目标           
}
void showTime(){
    tt = 300-(getTime()-t0)*hard;
    p.cav(1);
    p.setAngle(0).moveTo(-360,0).rr(20,300,15).moveTo(-360,-150).fd(tt/2).rr(20,tt,1);    
}

int main(){
    
    init();  //初始化
    p.moveTo(-350,330).pic(2).moveTo(-216,340).text("军事演习",3,40); 
    p.moveTo(-210,300).text("本次演习任务:",15,23); 
    p.moveTo(-40,265).text("规定的时间里,调节炮筒角度,发射炮弹,消灭敌军碉堡。",3,23); 
    objx=rand(10,15)*20;
    
    p.cav(1).moveTo(objx,y0).pic(8);//初始目标       
    t0=getTime();
    for (;;)
    {     
        showTime();
        if (tt<hard)
        {
            //时间到,失败                   
            break;
        }
        getAng();       
        if ( buttonMP(1) ){  //按发射按钮
            lunch(ang);
            p.soundStop(100).sound(100).pic(4);
            if (abs(x-objx)<18 ){ //击中目标               
                score++;                        
                showScore();                
                wait(1.5);
                if (score==5) { //5=几个目标                   
                   //胜利
                   break;   
                }

                showObj();                
            }
            else
                 p.sound(103);

        }
                 wait(0.1);
    }
//结束    
            for( int j=0; j<score; j++){
                      p.soundStop(100).sound(100);
                      p.moveTo(60+j*65,100).pic(11-j%3);
                      wait(0.2);p.pic(4);wait(0.5);                
                }  
                string sx="仅";
                if (score==5)
                    sx="成功";
                p.font(3).text("我方"+sx+"炸毁敌军碉堡"+d2s(score)+"座!",15,25,0,200,35).font(2);
                wait(2);                  
    return 0;
}

0 条评论

目前还没有评论...