版本比较
game-雷霆战机
正文
增加 80 行删除 80 行
66 行未改动6768697071717273747576767778798081828384858686878889907 行未改动98991001011021021031041051067 行未改动11411511611711811811912012112212312412512612712812812913013113213313413513613613713813914026 行未改动1671681691701711711721731731741751761771781791801801811821831841851861871871881891901911921931931941951961971971981992002012022032042042052062062072082082092102112122132142152162172182182192202212222232242252262272282282292302312322332342342352362372382392382392402412412422432432442452462472482492502502512522532542552562562572582592602612622622632642652662672682672682692702712722722732742742752762772782792782792802812812822832842853 行未改动28929029129229329329429529629711 行未改动3093103113123133133143153163178 行未改动32632732832933033033133233333422 行未改动3573583593603613613623633643653 行未改动36937037137237337337437537637716 行未改动3943953963973983983994004004014024034044054064074084084094104114124134144144154164164174184194194204214224234244254264274284294294304314324334344354364364374384394394404414424434444454454464474484494504514524534544544554564574574584594604614614624634644656 行未改动4724734744754764764774784794803 行未改动4844854864874884884894904914924934944954954964974984993 行未改动50350450550650750750850951051110 行未改动52252352452552652652752852953053153253253353453553616 行未改动5535545555565575575585595595605615625634 行未改动5685695705715725725735745755765775775785795805815825825835845855865875875885895905915925925935945955955965975985996006016016026036046056046056066076086096106116126136136146156156166176186192 行未改动62262362462562662662762862963063163163263363463563663763863964064064164264364264364464564664764864964965065165265265365465565665765865965966066166266366366466566666666766866967066 行未改动 show(0, ROWS * 2 + 4, " "); show(0, ROWS * 2 + 4, s);}
//初始化窗口 //初始化窗口void InitWindow() { SetConsoleTitle("雷霆战机3.0"); HideConsoleCursor(); SetSize(16, 2);
Sleep(200); keybd_event(VK_SHIFT, 0, 0, 0); Sleep(20); keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);}
//游戏教程void Tutorial() { while(KeyDown(VK_2));
SetSize(27, 14); system("cls"); gotoxy(0, 0); cout << "游戏操作:\n";7 行未改动 cout << "n:游戏存档 m:游戏读档\n"; cout << "q:战机升级 e:打开设置菜单\n"; cout << "ctrl+shift+x:老板键\n"; cout << "按(1).返回";
while(!KeyDown(VK_1)); while(KeyDown(VK_1));}
7 行未改动
//获取设置void LoadSetUp() { if(access("data/雷霆战机设置.dat", F_OK)) return ;
file.open("data/雷霆战机设置.dat", ios::in | ios::binary); file.read((char*)&music, sizeof(music)); file.read((char*)&difficult, sizeof(difficult)); file.close();}
//游戏设置菜单void SetUpMenu() { while(KeyDown(VK_3));
LoadSetUp(); while(!KeyDown(VK_3)) { SetSize(15, 3); color(0xf); cout << "按(1)." << (music ? "开启" : "关闭") << "音乐\n"; cout << "按(2)." << (difficult ? "困难" : "简单") << "模式\n"; cout << "按(3).返回";
while(!KeyDown(VK_1) && !KeyDown(VK_2) && !KeyDown(VK_3)); if(KeyDown(VK_1)) { while(KeyDown(VK_1)); music = !music;26 行未改动
//游戏存档void SaveGame() { file.open("data/雷霆战机存档.dat", ios::out | ios::binary);
file.write((char*)&Mine, sizeof(Mine));
for(int i = 0; i < ROWS; i++) { int n1 = PlaneList[i].size(); file.write((char*)&n1, sizeof(n1)); for(auto& tmp : PlaneList[i]) { file.write((char*)&tmp, sizeof(tmp)); }
int n2 = BulletList[i].size(); file.write((char*)&n2, sizeof(n2)); for(auto& tmp : BulletList[i]) { file.write((char*)&tmp, sizeof(tmp)); } }
file.write((char*)&GameTimeCount, sizeof(GameTimeCount)); for(int i = 0; i < 4; i++) { file.write((char*)&PlaneCreateCount[i], sizeof(PlaneCreateCount[i])); } file.write((char*)&BulletCreateCount, sizeof(BulletCreateCount));
for(int i = 0; i < 3; i++) { file.write((char*)&Skill[i], sizeof(Skill[i])); }
file.close();}
//游戏读档bool LoadGame() { if(access("data/雷霆战机存档.dat", F_OK)) return false;
file.open("data/雷霆战机存档.dat", ios::in | ios::binary);
file.read((char*)&Mine, sizeof(Mine));
for(int i = 0; i < ROWS; i++) { PlaneList[i].clear(); int n1; file.read((char*)&n1, sizeof(n1)); for(int j = 0; j < n1; j++) { Node2 tmp; file.read((char*)&tmp, sizeof(tmp)); PlaneList[i].push_back(tmp); }
BulletList[i].clear(); int n2; file.read((char*)&n2, sizeof(n2)); for(int j = 0; j < n2; j++) { Node2 tmp; file.read((char*)&tmp, sizeof(tmp)); BulletList[i].push_back(tmp); } }
file.read((char*)&GameTimeCount, sizeof(GameTimeCount)); for(int i = 0; i < 4; i++) { file.read((char*)&PlaneCreateCount[i], sizeof(PlaneCreateCount[i])); } file.read((char*)&BulletCreateCount, sizeof(BulletCreateCount));
for(int i = 0; i < 3; i++) { file.read((char*)&Skill[i], sizeof(Skill[i])); }
file.close();
last = now = clock();
return true;}
//初始化游戏void InitGame() { SetSize(COLS + 10, ROWS * 2 + 5 + coding);
Mine = (Node1) {(ROWS - 1) / 2, 1, 3, 0, 0, 0, 0.0}; for(int i = 0; i < ROWS; i++) { PlaneList[i].clear(); BulletList[i].clear(); }
GameTimeCount = 0.0; for(int i = 0; i < 4; i++) { PlaneCreateCount[i] = 0.0; } BulletCreateCount = 0.0;
//初始化技能 for(int i = 0; i < 3; i++) { Skill[i] = (Node4) {!coding * SkillCooling[i], 0.0, 0}; } //初始化BGM
//初始化BGM mciSendString(TEXT("open 雷霆战机.mp3 type mpegvideo alias bgm"), NULL, 0, 0); mciSendString(TEXT("play bgm repeat"), NULL, 0, 0); mciSendString(TEXT("stop bgm"), NULL, 0, 0);
if(coding) { cout << "请输入KILL:"; cout << "请输入KILL:"; cin >> Mine.kill; cout << "请输入TIME:"; cin >> GameTimeCount; } }
Boss.HP = 0;
last = clock();}
//人机互动3 行未改动 if(!Mine.cnt) t = 0.0; else if(Mine.cnt < 2) t = 0.2; else if(Mine.cnt < 3) t = 0.075; else t = 0.025;
if((Mine.timer += delta) >= t) { if(KeyDown(VK_W) || KeyDown(VK_UP)) { //上 Mine.cnt++, Mine.timer = 0.0;11 行未改动 Mine.cnt++, Mine.timer = 0.0; Mine.col = min(Mine.col + 1, COLS / 2); }else Mine.cnt = 0; }
//技能 if(KeyDown(VK_J) && !Skill[0].cooling && Mine.kill >= Skill[0].cnt * 20) { Skill[0].cooling = SkillCooling[0]; Skill[0].timer = SkillTime[0];8 行未改动 Skill[2].cooling = SkillCooling[2]; Skill[2].timer = SkillTime[2]; Mine.kill -= Skill[2].cnt++ * 20; }
//升级 if(KeyDown(VK_Q) && Mine.level < 4 && Mine.kill >= LevelUpgrade[Mine.level + 1]) { if(!Sentences.count("恭喜升级!")) { Mine.kill -= LevelUpgrade[Mine.level + 1];22 行未改动 }else { if(music) mciSendString("resume bgm", NULL, 0, NULL); } }
if(KeyDown(VK_E)) { while(KeyDown(VK_E)); bool tmp = pause; pause = true;3 行未改动 now = last = clock(); SetSize(COLS + 10, ROWS * 2 + 4 + coding); if(music) mciSendString("resume bgm", NULL, 0, NULL); }
//老板键 if(!(KeyDown(VK_CONTROL) && KeyDown(VK_X))) return ; Mine.timer = 0.0; while(KeyDown(VK_CONTROL) && KeyDown(VK_X));16 行未改动 if((it = next) == Sentences.begin()) break; it--; } }
if(pause) return true;
//更新尸潮 if(HordeTimeCount > 0.0) { HordeTimeCount -= delta; }else if(ceil(GameTimeCount) <= GameTimeCount + delta && rand() % 100 == 114) { HordeTimeCount = rand() % 5000 / 1000.0; Sentences[(string) "尸潮来袭!"] = 2.5; }
//更新技能 for(int i = 0; i < 3; i++) { Skill[i].cooling = max(Skill[i].cooling - !coding * delta, 0.0); Skill[i].timer = max(Skill[i].timer - delta, 0.0); }
GameTimeCount += delta;
for(int i = 0; i < ROWS; i++) { list<Node2>::iterator it1, it2;
//碰撞判断 for(it1 = PlaneList[i].begin(); it1 != PlaneList[i].end();) { bool flag = false; for(it2 = BulletList[i].begin(); it2 != BulletList[i].end();) { Node2& plane = *it1, bullet = *it2; if(plane.col - bullet.col >= 0 && plane.col - bullet.col <= 3) { list<Node2>::iterator next2 = ++it2; if(Skill[1].timer <= 0.0) BulletList[i].erase(--it2); it2 = next2;
if((plane.point -= bullet.point) <= 0) { flag = true; break; } }else it2++; }
if(flag) { Mine.kill++;
list<Node2>::iterator next1 = ++it1; PlaneList[i].erase(--it1); it1 = next1; }else it1++; }
//更新敌人 for(it1 = PlaneList[i].begin(); it1 != PlaneList[i].end();) { Node2 &plane = *it1; if((plane.timer += !(Skill[2].timer > 0.0) * delta) >= plane.speed) { plane.timer -= plane.speed; plane.col -= plane.speed2; if(plane.col < 0 || i == Mine.row && plane.col - Mine.col >= 0 && plane.col - Mine.col <= D) { Mine.HP--;
list<Node2>::iterator next1 = ++it1; PlaneList[i].erase(--it1); it1 = next1; it1 = next1; }else it1++; }else it1++; }
//更新子弹 for(it2 = BulletList[i].begin(); it2 != BulletList[i].end();) { Node2 &bullet = *it2; if((bullet.timer += delta) >= bullet.speed) {6 行未改动 }else it2++; }else it2++; } }
//刷新敌人 for(int i = 0; i < 4; i++) { if(GameTimeCount < PlaneCreateStart[i]) continue; double f = max(6.0 - (Mine.level - i), 3.5) + (!difficult - (HordeTimeCount > 0.0) * 1.5) * 2;3 行未改动 int row = rand() % ROWS; PlaneList[row].push_back((Node2) {i, COLS, PlaneHealthPoint[i], 1, 0.0, 0.2 * ((i == 3 && Mine.level < 4) + 1)}); } }
//刷新子弹 double t = BulletCreateTime[Mine.level] / 5 * (5 - (Skill[0].timer > 0.0) * 2); if((BulletCreateCount += delta) >= t) { BulletCreateCount -= t; BulletList[Mine.row].push_back((Node2) {Mine.level, Mine.col + D, BulletDamagePoint[Mine.level], 2, 0.0, fps}); }
return Mine.HP > 0;}
//显示游戏画面3 行未改动 gotoxy(0, 0); for(int i = 1; i <= (COLS - 3) / 2; i++) cout << "-"; cout << " 雷霆战机3.0 "; for(int i = 1; i <= (COLS - 2) / 2; i++) cout << "-";
for(int i = 0; i < ROWS; i++) { for(auto& plane : PlaneList[i]) { if(plane.type == 0) { color(Skill[2].timer > 0.0 ? 0x7 : 0x5);10 行未改动 show(plane.col, i * 2 + 2, "<{{{[][]"); show(plane.col + 1, i * 2 + 3, "\\\\\\-----"); } }
color(Skill[1].timer > 0.0 ? 0x6 : 0x8); for(auto& bullet : BulletList[i]) { show(bullet.col, i * 2 + 2, "·"); } }
if(Mine.level < 4) { color(0xb); show(Mine.col, Mine.row * 2 + 1, " \\"); show(Mine.col, Mine.row * 2 + 2, "*=");16 行未改动 show(Mine.col + 8, Mine.row * 2 + 2, ")》"); color(0xc); show(Mine.col, Mine.row * 2 + 3, " --"); color(0xb); show(Mine.col + 3, Mine.row * 2 + 3, "*O=++"); show(Mine.col + 3, Mine.row * 2 + 3, "*O=++"); }
if(Boss.HP) { color(0xc); show(COLS - 1, 2, "<----------"); show(COLS - 2, 4, "//--::::::::");4 行未改动 show(COLS - 5, 14, "-\\\\\\-:::\\------"); show(COLS - 2, 16, "\\\\--::::::::"); show(COLS - 1, 18, "<----------"); }
gotoxy(0, ROWS * 2 + 2); cout.setf(ios::fixed); color(0x1f); cout << "skill:";
color(0x1f); cout << "①"; color(!Skill[0].cooling && Mine.kill >= Skill[0].cnt * 20 ? 0x1e : 0x17); cout << setw(5) << setprecision(2) << Skill[0].cooling << " ";
color(0x1f); printf("②"); color(!Skill[1].cooling && Mine.kill >= Skill[1].cnt * 20 ? 0x1e : 0x17); cout << setw(5) << setprecision(2) << Skill[1].cooling << " ";
color(0x1f); printf("③"); color(!Skill[2].cooling && Mine.kill >= Skill[2].cnt * 20 ? 0x1e : 0x17); cout << setw(5) << setprecision(2) << Skill[2].cooling << " ";
color(0x1f); puts("upgrade");
color(0x17); cout << "cost: "; cout << setw(7) << Skill[0].cnt * 20 << " "; cout << setw(7) << Skill[1].cnt * 20 << " "; cout << setw(7) << Skill[2].cnt * 20 << " ";
color(Mine.level < 4 && Mine.kill >= LevelUpgrade[Mine.level + 1] && !Sentences.count("恭喜升级!") ? 0x1e : 0x17); if(Mine.level < 4) cout << setw(7) << max(LevelUpgrade[Mine.level + 1] - Mine.kill, 0) << "\n"; else puts("no"); else puts("no");
color(0x1f); for(int i = 1; i <= 40; i++) cout << " "; gotoxy(0, ROWS * 2 + 4); cout << "kill:" << Mine.kill << " "; cout << "HP:" << Mine.HP << " "; cout << "level:" << Mine.level << "/5 "; cout << "time:" << setprecision(2) << GameTimeCount;
cout.unsetf(ios::fixed);
for(auto& tmp : Sentences) { color(tmp.first == "尸潮来袭!" ? 0x4 : 0xe); show(COLS + 10 - tmp.first.size(), ROWS * 2 + 3, tmp.first.c_str()); }2 行未改动
//游戏结束bool GameOver() { mciSendString("close bgm", NULL, 0, NULL);
color(0x6); cout << "Game Over\n"; Sleep(2000); cout << "kry again? (y/n)\n";
while(!KeyDown(VK_Y) && !KeyDown(VK_N)); return KeyDown(VK_Y);}
//主函数int main() { InitWindow(); StartUI();
GAME: InitGame(); InitGame();
while(true) { now = clock(); if((now - last) * 1.0 / CLOCKS_PER_SEC < fps) { continue; }
UserClick((now - last) * 1.0 / CLOCKS_PER_SEC); system("cls");
if(coding) Debug("begin updata"); if(!UpdataGame((now - last) * 1.0 / CLOCKS_PER_SEC)) { if(GameOver()) goto GAME; break; } if(coding) Debug("end updata");
if(coding) Debug("begin draw"); DrawGame(); if(coding) Debug("end draw");
last = now; }
color(0xf); return 0;}```