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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| #include <stdio.h> #include <Windows.h> #include "tools.h"
#include <mmsystem.h> #pragma comment(lib, "winmm.lib")
int getDelay() { static unsigned long long lastTime = 0; unsigned long long currentTime = GetTickCount(); if (lastTime == 0) { lastTime = currentTime; return 0; } else { int ret = currentTime - lastTime; lastTime = currentTime; return ret; } }
void putimagePNG(int picture_x, int picture_y, IMAGE* picture) { DWORD* dst = GetImageBuffer(); DWORD* draw = GetImageBuffer(); DWORD* src = GetImageBuffer(picture); int picture_width = picture->getwidth(); int picture_height = picture->getheight(); int graphWidth = getwidth(); int graphHeight = getheight(); int dstX = 0;
for (int iy = 0; iy < picture_height; iy++) { for (int ix = 0; ix < picture_width; ix++) { int srcX = ix + iy * picture_width; int sa = ((src[srcX] & 0xff000000) >> 24); int sr = ((src[srcX] & 0xff0000) >> 16); int sg = ((src[srcX] & 0xff00) >> 8); int sb = src[srcX] & 0xff; if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight) { dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; int dr = ((dst[dstX] & 0xff0000) >> 16); int dg = ((dst[dstX] & 0xff00) >> 8); int db = dst[dstX] & 0xff; draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16) | ((sg * sa / 255 + dg * (255 - sa) / 255) << 8) | (sb * sa / 255 + db * (255 - sa) / 255); } } } }
void putimagePNG2(int x, int y, IMAGE* picture) { IMAGE imgTmp; if (y < 0) { SetWorkingImage(picture); getimage(&imgTmp, 0, -y, picture->getwidth(), picture->getheight() + y); SetWorkingImage(); y = 0; picture = &imgTmp; }
if (x < 0) { SetWorkingImage(picture); getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight()); SetWorkingImage(); x = 0; picture = &imgTmp; }
putimagePNG(x, y, picture); }
void putimagePNG2(int x, int y, int winWidth, IMAGE* picture) { IMAGE imgTmp; if (y < 0) { SetWorkingImage(picture); getimage(&imgTmp, 0, -y, picture->getwidth(), picture->getheight() + y); SetWorkingImage(); y = 0; picture = &imgTmp; }
if (x < 0) { SetWorkingImage(picture); getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight()); SetWorkingImage(); x = 0; picture = &imgTmp; } else if (x >= winWidth) { return; } else if (x > winWidth-picture->getwidth()) { SetWorkingImage(picture); getimage(&imgTmp, 0, 0, winWidth - x, picture->getheight()); SetWorkingImage(); picture = &imgTmp; }
putimagePNG(x, y, picture); }
bool rectIntersect(int x01, int y01, int x02, int y02, int x11, int y11, int x12, int y12) { int zx = abs(x01 + x02 - x11 - x12); int x = abs(x01 - x02) + abs(x11 - x12); int zy = abs(y01 + y02 - y11 - y12); int y = abs(y01 - y02) + abs(y11 - y12); return (zx <= x && zy <= y); }
void preLoadSound(const char* name) { char cmd[512]; sprintf_s(cmd, sizeof(cmd), "open %s alias %s-1", name, name); mciSendString(cmd, 0, 0, 0); sprintf_s(cmd, sizeof(cmd), "open %s alias %s-2", name, name); mciSendString(cmd, 0, 0, 0); }
void playSound(const char* name) { static int index = 1; char cmd[512];
if (index == 1) { sprintf_s(cmd, sizeof(cmd), "play %s-1", name); mciSendString(cmd, 0, 0, 0); sprintf_s(cmd, sizeof(cmd), "close %s-2", name); mciSendString(cmd, 0, 0, 0); sprintf_s(cmd, sizeof(cmd), "open %s alias %s-2", name, name); mciSendString(cmd, 0, 0, 0); index++; } else if (index == 2) { sprintf_s(cmd, sizeof(cmd), "play %s-2", name); mciSendString(cmd, 0, 0, 0); sprintf_s(cmd, sizeof(cmd), "close %s-1", name); mciSendString(cmd, 0, 0, 0); sprintf_s(cmd, sizeof(cmd), "open %s alias %s-1", name, name); mciSendString(cmd, 0, 0, 0); index = 1; } }
void drawBloodBar(int x, int y, int width, int height, int lineWidth, int boardColor, int emptyColor, int fillColor, float percent) { LINESTYLE lineStyle; getlinestyle(&lineStyle); int lineColor = getlinecolor(); int fileColor = getfillcolor();
if (percent < 0) { percent = 0; }
setlinecolor(BLUE); setlinestyle(PS_SOLID | PS_ENDCAP_ROUND, lineWidth); setfillcolor(emptyColor); fillrectangle(x, y, x + width, y + height); setlinestyle(PS_SOLID | PS_ENDCAP_FLAT, 0); setfillcolor(fillColor); setlinecolor(fillColor); if (percent > 0) { fillrectangle(x + 0.5 * lineWidth, y + lineWidth * 0.5, x + width * percent, y + height - 0.5 * lineWidth); } setlinecolor(lineColor); setfillcolor(fillColor); setlinestyle(&lineStyle); }
|