zengjunjian666 2020-04-19 00:14 采纳率: 0%
浏览 972

求组easyx图形库问题和kbhit键盘输入后窗口闪烁的问题

本人想设计一个坦克大战的游戏,刚用了kbhit函数键盘操作这个坦克移动时,我的窗口一直在闪烁!求哪位大帮我 试着运行这个程序,萌新刚学easyx图形库想做个游戏。

代码如下:

#include <iostream>
#include  <graphics.h> 
#include<conio.h>
#include<windows.h>
using namespace std;

//全局变量
int x ;
int y ;
void Update()
{
    x = 100;
    y = 180;
}
//   坦克图形
void  show() 
{
    initgraph(1200, 640);
    BeginBatchDraw();

    setbkcolor(WHITE);
    cleardevice();
    setfillcolor(GREEN);
    setlinecolor(GREEN);

    fillrectangle(x, y, x+250, y+120);
    setlinecolor(BLACK);
    fillrectangle(x+80, y-30, x+170, y);
    setfillcolor(BLACK);
    FlushBatchDraw();
    fillroundrect(x-30, y+120, x+280, y+170, 40, 40);
    setfillcolor(BROWN);
    fillrectangle(x+250, y+40, x+380, y+70);

    Sleep(50);
    EndBatchDraw();
    _getch();
    closegraph();
}

void Updatewithinput()
{
    char input;
    if (_kbhit())
    {
        input = _getch();
        if(input=='a')
          x=x-50;
        if(input=='d')
            x=x+50;
    }

}


int main()
{
        Update();

        while (1)
        {
            show();
            Updatewithinput();
        }

    return 0;

}

  • 写回答

1条回答 默认 最新

  • 程序鸡 2020-04-19 12:10
    关注
    #include <iostream> 
    #include <graphics.h> 
    #include<conio.h> 
    #include<windows.h> 
    using namespace std;
    //全局变量 
    int x; int y;
    void Update()
    
    {
        initgraph(1200, 640);
        x = 100;
        y = 180;
        setbkcolor(WHITE);
    
    } // 坦克图形 
    void show() {
    
        BeginBatchDraw();
        cleardevice();
        setfillcolor(GREEN);
        setlinecolor(GREEN);
        fillrectangle(x, y, x + 250, y + 120);
        setlinecolor(BLACK);
        fillrectangle(x + 80, y - 30, x + 170, y);
        setfillcolor(BLACK);
    
        fillroundrect(x - 30, y + 120, x + 280, y + 170, 40, 40);
        setfillcolor(BROWN);
        fillrectangle(x + 250, y + 40, x + 380, y + 70);
        FlushBatchDraw();
        Sleep(50);
        EndBatchDraw();
    
    }
    void Updatewithinput()
    {
        char input;
        input = _getch();
        if (input == 'a')
            x = x - 50;
        if (input == 'd')
            x = x + 50;
    }
    int main() {
        Update();
        while (1)
        {
            show();
            Updatewithinput();
        }
    
        closegraph();
        return 0;
    }
    
    评论

报告相同问题?

问题事件

  • 请选择合适的标签 5月5日

悬赏问题

  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画