1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| IMAGE* imgZhiWu[ZHI_WU_COUNT][20];
int curX, curY; int curZhiWu;
bool fileExist(const char* name) { FILE* fp = fopen(name, "r"); if (fp == NULL) { return false; } else { fclose(fp); return true; } }
void gameInit() { memset(imgZhiWu, 0, sizeof(imgZhiWu));
char name[64]; for (int i = 0; i < ZHI_WU_COUNT; i++) { for (int j = 0; j < 20; j++) { sprintf_s(name, sizeof(name), "res/zhiwu/%d/%d.png", i, j + 1); if (fileExist(name)) { imgZhiWu[i][j] = new IMAGE; loadimage(imgZhiWu[i][j], name); } else { break; } } }
curZhiWu = 0; initgraph(WIN_WIDTH, WIN_HEIGHT, 1); }
void updateWindow() { BeginBatchDraw();
if (curZhiWu > 0) { IMAGE* img = imgZhiWu[curZhiWu - 1][0]; putimagePNG(curX - img->getwidth() / 2, curY - img->getheight() / 2, img); }
EndBatchDraw(); } void userClick() { ExMessage msg; static int status = 0; if (peekmessage(&msg)) { if (msg.message == WM_LBUTTONDOWN) { if (msg.x > 338 && msg.x < 338 + 65 * ZHI_WU_COUNT && msg.y < 96) { int index = (msg.x - 338) / 65; printf("%d\n", index); status = 1; curZhiWu = index + 1; } } else if (msg.message == WM_MOUSEMOVE && status == 1) { curX = msg.x; curY = msg.y;
} else if (msg.message == WM_LBUTTONUP) {
} }
} int main(void) { gameInit();
while (1) { userClick();
updateWindow(); }
system("pause"); return 0; }
|