graphics弹弹球代码

作者: admin
标签:
更新: 8/8/2019, 5:36:24 PM
#include <graphics.h>
void compute(bool &r, bool& t, int& x, int& y, int rectx){
    if(r){
        x+=5;
        if(x==635) r=0;
    }else {
        x-=5;
        if(x==5) r=1;
    }
    if(t){
        y+=5;
        if(x>=rectx&&x<=rectx+200&&y==465){
            t=0;
            y-=5;
        }
    } else {
        y-=5;
        if(y<=0) t = 1;
    }
    if(y>465){
        outtextxy(100,100,"你输了,按任意键开始");
        if(kbhit())
            y = 0;
    }
}
void moverect(int& x){
    char ch; 
    if(kbhit()){//判断输入 
        ch = getch();//把字符读入 
        if(ch =='a') x-=10;
        if(ch =='d') x+=10;
    }
}
int main(){
    PIMAGE img;
    initgraph(640, 480);
    img = newimage();
    getimage(img,"test.jfif");//加载图片到img画板,请替换成自己的图片
    int x=100, y=100;
    bool r = 1;
    bool t = 1;
    int rectx = 400;        //板子的x轴 
    setfillcolor(WHITE);
    while(is_run()){
        xyprintf(100,100,"%f",getfps());
        compute(r, t, x, y, rectx);  //计算 
        fillellipse(x,y,10,10);
        moverect(rectx); 
        rectangle(rectx,470,rectx+200,478); //画板子 
        delay_fps(60);
        cleardevice();
    }
    delimage(img); //删除图像对象
    closegraph();
    return 0;
}
删除
修改
点击登陆评论