// game.cpp : 定义控制台应用程序的入口点。//#define _CRT_SECURE_NO_WARNINGS#include "EasyxEx.h//// 全局变量////游戏当前场景状态GAME_STATE state;//图片对象IMAGE background; //背景图片//鼠标按下消息void mouse_push(int x, int y, int button);//鼠标弹起消息void mouse_pop(int x, int y, int button);//鼠标移动消息void mouse_move(int x, int y);//按键处理函数void key_event(int key);//游戏逻辑更新void update(int t);//显示函数void display();//// main()//int main(int argc, char* argv[]) { //鼠标消息 MOUSEMSG msg; //初始化图形环境 //WINX = 1024 //WINY = 720 initgraph(WINX, WINY); //字体背景透明 setbkmode(TRANSPARENT); //加载图片 loadimage(&background, TEXT("bgm.png"), WINX, WINY); //帧时间 int t = clock(); while (running){ if (MouseHit()) { //如果有鼠标消息,处理鼠标操作 msg = GetMouseMsg(); switch (msg.uMsg){ case WM_LBUTTONDOWN: //记录按钮状态 mouse_button = MK_LBUTTON; mouse_push(msg.x, msg.y, MK_LBUTTON); break; case WM_RBUTTONDOWN: mouse_push(msg.x, msg.y, MK_RBUTTON); break; case WM_LBUTTONUP: //记录按钮状态 mouse_button = 0; mouse_pop(msg.x, msg.y, MK_LBUTTON); break; case WM_RBUTTONUP: mouse_pop(msg.x, msg.y, MK_RBUTTON); break; case WM_MOUSEMOVE: //记录鼠标位置 mouse.x = msg.x; mouse.y = msg.y; mouse_move(msg.x, msg.y); break; } } else if (_kbhit()) { //如果有键盘消息,处理按键操作 key_event(_getch()); } else { //更新游戏 update(clock() - t); t = clock(); //批量绘图,防止闪烁 BeginBatchDraw(); //显示画面 display(); //结束批量绘图 EndBatchDraw(); //延时 Sleep(20); } } //关闭图形坏境 closegraph(); return 0; }//鼠标按下消息//button MK_LBUTTON 左键// MK_RBUTTON 右键void mouse_push(int x, int y, int button) { }//鼠标弹起消息//button MK_LBUTTON 左键// MK_RBUTTON 右键void mouse_pop(int x, int y, int button) { }//鼠标移动消息void mouse_move(int x, int y) { }//按键处理函数void key_event(int key) { switch (key) { case KEY_ESC: //设置运行标记为 false,退出程序。 running = false; break; } }//游戏逻辑更新void update(int t) { switch (state) { case GAME_MENU: break; case GAME_PLAY: //处理游戏执行逻辑 break; case GAME_END: break; default: break; } }//显示函数void display() { //绘制背景图片 putimage(0, 0, &background); switch (state) { case GAME_MENU: //绘制游戏菜单 break; case GAME_PLAY: //绘制游戏场景 break; case GAME_END: //绘制游戏结束画面 break; default: break; } }