#include <stdio.h>
#include <Windows.h>
#include <easyx.h>
#include <conio.h>
#include <time.h>
#include <graphics.h>
#include <stdlib.h>
#include <iostream>
#include<mmsystem.h>
#include<math.h>
IMAGE img_player;
IMAGE img_player1;
IMAGE img_monster1;
IMAGE img_monster2;
IMAGE img_food1;
IMAGE img_food2;
IMAGE img_food3;
IMAGE img_food4;
IMAGE img_food5;
IMAGE img_map;
struct Player {
int x;
int y; //位置
int dirx;
int diry; //移动方向
unsigned long t1, t2, dt; //控制速度
};
struct Player player, player1;
//定义敌人
struct Enemy {
int x;
int y;
int dirx;
int diry;
unsigned long t1, t2, dt;
};
struct Enemy monster1, monster2;
//定义豆子
struct Food {
int x;
int y;
bool isexist;
//用于判断豆子是否被吃
};
struct Food food1, food2, food3, food4, food5;
void wanjia()
{
BeginBatchDraw();
loadimage(&img_player, _T("D:\\wanjia1.png"), 50, 50); //关键
putimage(player.x, player.y, &img_player);
loadimage(&img_player1, _T("D:\\wanjia1.png"), 50, 50); //关键
putimage(player1.x, player1.y, &img_player1);
EndBatchDraw();
}
void diren()
{
BeginBatchDraw();
loadimage(&img_monster1, _T("D:\\5.png"), 50, 50); //关键
putimage(monster1.x, monster1.y, &img_monster1);
loadimage(&img_monster2, _T("D:\\5.png"), 50, 50); //关键
putimage(monster2.x, monster2.y, &img_monster2);
EndBatchDraw();
}
void douzi1()
{
BeginBatchDraw();
loadimage(&img_food1, _T("D:\\food.png"), 30, 30); //关键
putimage(800, 50, &img_food1);
EndBatchDraw();
}
void douzi2() {
BeginBatchDraw();
loadimage(&img_food2, _T("D:\\food.png"), 30, 30); //关键
putimage(270, 250, &img_food2);
EndBatchDraw();
}
void douzi3() {
BeginBatchDraw();
loadimage(&img_food3, _T("D:\\food.png"), 30, 30); //关键
putimage(285, 400, &img_food3);
EndBatchDraw();
}
void douzi4() {
BeginBatchDraw();
loadimage(&img_food4, _T("D:\\food.png"), 30, 30); //关键
putimage(750, 550, &img_food4);
EndBatchDraw();
}
void douzi5() {
BeginBatchDraw();
loadimage(&img_food5, _T("D:\\food.png"), 30, 30); //关键
putimage(700, 400, &img_food5);
EndBatchDraw();
}
//3.显示程序
void GameDraw()
{
//开始绘制
BeginBatchDraw();
wanjia();
//绘制敌人
diren();
//绘制豆子
douzi1();
douzi2();
douzi3();
douzi4();
douzi5();
//结束绘制
EndBatchDraw();
}
int main() { //显示菜单,并且获取用户输入的命令选项
initgraph(900, 600);
void GameInit();
cleardevice();
while (1) { //游戏的每一个画面都在不断绘制,用循环
BeginBatchDraw();
loadimage(&img_map, _T("D:\\map2.jpg"), 900, 600); //关键
putimage(0, 0, &img_map);
GameDraw();
FlushBatchDraw();
EndBatchDraw();
}
closegraph();
}
使用vs C语言绘制图片,并加入了
BeginBatchDraw();
FlushBatchDraw();
EndBatchDraw();但仍然无法解决图像不断闪烁的问题。请问怎么办?(除了采用双缓冲的技术)