版本比较
游戏
正文
增加 12 行删除 12 行
107 行未改动全部展开108109110111112112113114115116157 行未改动全部展开2742752762772782782792802812825 行未改动28828929029129229229329429529629729829930030130130230330430578 行未改动384385386387388388389390391392288 行未改动全部展开6816826836846856856866876876886896906915 行未改动6976986997007017017027037047057067077087097107117117127137147157167177187187197207217227237247257267277287287297307317323 行未改动736737738739740740741742743744214 行未改动全部展开107 行未改动全部展开 HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0)); // 红色激光 SelectObject(hdc, brush); RECT rect; GetClientRect(hwnd, &rect);
// 绘制激光线 - 使用Rectangle绘制一个细长的矩形 FillRect(hdc, &rect, brush);
DeleteObject(brush);157 行未改动全部展开// 创建激光void CreateLaser(bool isHorizontal, int position, int direction = 1) { int laserWidth, laserHeight; int x, y;
if (isHorizontal) { // 横向激光 laserWidth = maxx; // 横跨整个屏幕宽度 laserHeight = 5; // 高度为5像素5 行未改动 laserHeight = maxy; // 高度为整个屏幕高度 x = position; y = 0; }
Laser newLaser; newLaser.hwnd = CreateLaserWindow(x, y, laserWidth, laserHeight); newLaser.x = x; newLaser.y = y; newLaser.length = isHorizontal ? maxx : maxy; newLaser.isHorizontal = isHorizontal; newLaser.active = true; newLaser.direction = direction;
lasers.push_back(newLaser);}
// 显示激光预警78 行未改动// 检测玩家与激光的碰撞bool CheckLaserCollision(double px, double py) { for(size_t i = 0; i < lasers.size(); i++) { if (!lasers[i].active) continue;
if (lasers[i].isHorizontal) { // 横向激光 if (py >= lasers[i].y && py <= lasers[i].y + 5) { // 激光高度为5像素 if (px >= lasers[i].x && px <= lasers[i].x + maxx) {288 行未改动全部展开 static DWORD lastLaserTime = GetTickCount(); static bool warningShown = false; static DWORD warningStartTime = 0; static DWORD laserActivationTime = 0;
DWORD currentTime = GetTickCount();
// 检查是否到了生成新激光的时间 if (currentTime - lastLaserTime > (rand() % 5000 + 10000)) { // 10-15秒 if (!warningShown) { // 显示预警5 行未改动 } warningShown = true; warningStartTime = currentTime; }
// 等待1.5秒后激活激光 if (warningShown && currentTime - warningStartTime > 1500) { bool horizontal = rand() % 2 == 0; // 随机选择方向 int position; if (horizontal) { position = rand() % maxy; // 在屏幕高度内随机选择y坐标 } else { position = rand() % maxx; // 在屏幕宽度内随机选择x坐标 }
CreateLaser(horizontal, position); laserActivationTime = currentTime; lastLaserTime = currentTime; // 重置计时器 warningShown = false; } }
// 检查激光是否应该消失(持续5秒) for(size_t i = 0; i < lasers.size(); i++) { if (currentTime - laserActivationTime > 5000) { // 5秒后消失 if (lasers[i].active) { DestroyWindow(lasers[i].hwnd); lasers[i].active = false; } } }
// 清理已失效的激光 for(int i = lasers.size() - 1; i >= 0; i--) { if (!lasers[i].active && GetTickCount() - laserActivationTime > 5500) { lasers.erase(lasers.begin() + i);3 行未改动
int main(){ // 初始化COM(某些对话框可能需要) CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
// 初始化随机数种子 srand(time(NULL));
HWND conso=GetConsoleWindow();214 行未改动全部展开