版本比较
琪露诺可爱
正文
增加 2065 行删除 1342 行
123456783104567891310111213141516171617181920211920212223242522232425262727282930312930313233343536373839404142434432333435464748495051525354555657583637383940414243444546474849505152536054555662636457585960616263646566676869707172737475767778796667808182697083848586878889727374909192939495967677787980979899100101102103848586878810410510610710810991921101111121131141151161171181191201211221231241251269495961271281291301311011021031041321331341351361371071081091101111121131141151161381391401191201211221231241251261271281291301411421431441451461471481491501511521531541551561571581591341351361371601611621631641651401411421431441661671681691701711721731741471481491501751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512521521531541551561571581591601612532542552562572582592601651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043052042052062073063073083093103113122112123133143153163173183192183203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503512272282292302312322332342352362372382392402412422432442452463523533543553563573583593603613623633643653663672492502512522532542552562572582592602612622632642652662672683683693703713723733743753763773783793803813822712722732742752762772782792803833843853863873883893903913923933943953963972842852862872882892902912922932942952962972982993003013023033983994004014024034044054064074084094104114123063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573584134144154164174184194204213613623633643653663673683693703713723733743753763773783793803813823834224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524533863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525534594604614624634644654664674684695545555565575585595605615625635645655665675685695704734745715725735744774784794804814824834844854864874884894904914924934944954964974985755765775785795805815825835845855865005015025035045055065075085095105115875885895905915135145155165175185195205215225235245255265275285295305315925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916925355365376936946956966975405415425435445455465475485495505515525535545555565575585595605615625635645656986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307315695705715725735745755765775785795805815825835845855865875885895905915925937327337345955965975985996006016026036046056066076086096106116126137357367377387397407417427437447457467477487497507517526156166176186196206216226236246256266276286296306316326336346356366377537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218226406416426436446456466476486496508238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748756546556566576586596606616626636646656666676686696706716726738768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112126776786796806816826836846856866876886896906916926936946956966976986997007017027031213121412157057067077087097107117127137147157167177187197207217227237247257267271216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212937317327337347357361294129512967387397407417427437447457467477487491297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133775375475575675775875976076176276376476576676776876977077177277377477577677777813381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141578178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480828829830831832833834835836837838839840841148114821483148484384484584684784884985085185285385485585685785885986086114851486148786386486586686786886987087187287387487587687787814881489149014911492149314941495880881882883884885886887888889890891892893894895896897898899149614971498149915009019029039049059069079089099109119129139149159169179189191501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617079239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589591708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175496396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187810531054105510561057105818791880106010611881188218831884188518861887188818891890189118921893189418951896189718981899190010631064106510661067106810691070107110721073107410751076107710781079190119021903108110821904190519061907190810841085108610871088108910901909191019111092191219131914191519161094109510961097109810991100110111021103110411051106110711081109191719181111111211131114111511161117111811191120112111221123112411251126191919201921192219231924192519261927192811281129113011311132113311341929193019311136113711381139114011411142193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173196819691970197111751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201972197319741975197619771978197919801981122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591982198312611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911984198519861987198819891990199119921993199412931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336199519961997199819992000200120022003200420052006200720082009201020112012201313381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378201420152016201720181380138113821383138413851386138713881389139013911392139313941395139613972019202020211399140014011402140314041405140614071408140914101411141214132022202320242025202620272028202920301415141614171418141914201421142214231424142514261427142820312032203320342035203620372038143014311432143314341435143614371438143914401441144214432039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206414451446144714481449145014511452145314541455145614571458145914602065206620672068206920702071207214621463146414651466146714681469147014711472147314741475207320742075207620771477147814791480148114821483148414851486148714881489149020782079208020812082208320842085208620872088208920902091209220932094209520962097209820991492149314941495210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219```cpp#define _USE_MATH_DEFINES#include <iostream>#include <vector>#include <fstream>#include <sstream>#include <string>#include <cmath>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <conio.h>#include <cstdlib>#include <cstring>#include <ctime>#include <cctype>#include <fstream>#include <iomanip>#include <iostream>#include <sstream>#include <string>#include <vector>#include <windows.h>
const int W = 64;const int H = 32;// ===== 游戏画布尺寸(字符格)=====const int W = 64; // 画面宽度(列数),含左右边框各 1 格const int H = 32; // 画面高度(行数),含上下边框各 1 格
const float PLAYER_VIS_R = 1.2f;const float PLAYER_HIT_R = 0.4f;const float GRAZE_R = 1.4f;const float BULLET_R = 0.7f;const float PLAYER_SPEED = 13.f;const float PLAYER_SPEED_SLOW = PLAYER_SPEED * 0.35f;const int FRAME_DELAY = 1;// ===== 玩家碰撞/视觉参数(单位:格)=====const float PLAYER_VIS_R = 1.2f; // 玩家视觉半径(仅用于渲染/调试,当前碰撞未用)const float PLAYER_HIT_R = 0.4f; // 玩家实际受击判定半径(真正的 hitbox,越小越友好)const float GRAZE_R = 1.4f; // 擦弹判定半径:子弹进入此圈内算擦弹,加分+续连击const float BULLET_R = 0.7f; // 子弹碰撞半径(和 PLAYER_HIT_R 相加作为命中距离)
const float FIXED_DT = 1.0f / 60.0f;// ===== 玩家移动(单位:格/秒)=====const float PLAYER_SPEED = 13.f; // 正常移动速度const float PLAYER_SPEED_SLOW = PLAYER_SPEED * 0.35f; // 按住 Shift 低速移动速度(约 4.55 格/秒)
const int C_BLACK = 0;const int C_BLUE = 1;const int C_GREEN = 2;const int C_CYAN = 3;const int C_RED = 4;const int C_MAGENTA = 5;const int C_YELLOW = 6;const int C_WHITE = 7;const int C_GRAY = 8;const int C_LBLUE = 9;const int C_LGREEN = 10;const int C_LCYAN = 11;const int C_LRED = 12;const int C_LMAGENTA = 13;const int C_LYELLOW = 14;const int C_BRIGHT = 15;// ===== 主循环时序 =====const int FRAME_DELAY = 1; // 每帧 Sleep 毫秒数(1ms,配合累加器做固定步长)const float FIXED_DT = 1.0f / 60.0f; // 固定物理步长:60Hz,约 0.01667s
const int COLOR_LINE = C_LRED;const int COLOR_AIM = C_RED;const int COLOR_CIRCLE = C_LYELLOW;const int COLOR_FAN = C_LGREEN;const int COLOR_SPIRAL = C_LMAGENTA;const int COLOR_BOUNCE = C_LCYAN;const int COLOR_ACCEL = C_MAGENTA;const int COLOR_DELAY = C_YELLOW;const int COLOR_PLAYER = C_LGREEN;const int COLOR_UI = C_LBLUE;const int COLOR_WARN = C_LRED;const int COLOR_INFO = C_LCYAN;const int COLOR_TITLE = C_LYELLOW;// ===== Windows 控制台 16 色调色板(SetConsoleTextAttribute 用)=====const int C_BLACK = 0; // 黑const int C_BLUE = 1; // 深蓝const int C_GREEN = 2; // 深绿const int C_CYAN = 3; // 深青const int C_RED = 4; // 深红const int C_MAGENTA = 5; // 深洋红/紫const int C_YELLOW = 6; // 棕黄(深黄)const int C_WHITE = 7; // 灰白(默认前景色)const int C_GRAY = 8; // 深灰(亮黑)const int C_LBLUE = 9; // 亮蓝const int C_LGREEN = 10; // 亮绿const int C_LCYAN = 11; // 亮青const int C_LRED = 12; // 亮红const int C_LMAGENTA = 13; // 亮洋红const int C_LYELLOW = 14; // 亮黄const int C_BRIGHT = 15; // 亮白(最亮)
const float BULLET_BASE_SPEED = 20.f;// ===== 谱面参数占位符 =====const float RAND_ANGLE = -99999.f; // 谱面里写 rand/r 时的哨兵值,运行时替换为随机角度(度)
const float ENDLESS_SPAWN_BASE = 0.14f;const float ENDLESS_SPAWN_MIN = 0.04f;const float ENDLESS_SPAWN_MAX = 0.45f;// ===== 各类子弹主题色 =====const int COLOR_LINE = C_LRED; // 直线弹 '#'const int COLOR_AIM = C_RED; // 自机狙 '@'const int COLOR_CIRCLE = C_LYELLOW; // 环形弹 'O'const int COLOR_FAN = C_CYAN; // 扇形弹 '%'const int COLOR_SPIRAL = C_LMAGENTA; // 螺旋弹 '&'const int COLOR_BOUNCE = C_LCYAN; // 反弹弹 '?'const int COLOR_ACCEL = C_MAGENTA; // 加速弹 '!'const int COLOR_DELAY = C_YELLOW; // 滞留弹 '+'const int COLOR_PLAYER = C_LGREEN; // 玩家 '*'const int COLOR_UI = C_LBLUE; // 顶栏 HUD 文字const int COLOR_WARN = C_LRED; // 警告/Game Over 文字const int COLOR_INFO = C_LCYAN; // 剧情/提示文字const int COLOR_TITLE = C_LYELLOW; // 菜单标题const int COLOR_BLASTER = C_LYELLOW; // 龙骨炮炮台/激光(蓄力完成态)const int COLOR_LASER = C_BRIGHT; // 激光高亮色(当前渲染处直写 C_BRIGHT,保留备用)const int COLOR_BLASTER_W = C_LRED; // 炮台蓄力警告色(暗红)
// ===== 弹幕运动与生成(单位:格/秒、秒、度、个)=====const float BULLET_BASE_SPEED = 20.f; // 子弹基准速度(各关卡再乘 base_speed×diff_mult×diff_rate)const float ENDLESS_SPAWN_BASE = 0.14f; // 无尽模式基础生成间隔(秒),实际会再按难度/弹量缩放const float ENDLESS_SPAWN_MIN = 0.04f; // 无尽生成间隔下限(秒),防止过密const float ENDLESS_SPAWN_MAX = 0.45f; // 无尽生成间隔上限(秒),防止过疏const float SPIRAL_ROT_SPEED = 2.4f;const float SPIRAL_EXPAND_RATE = 0.38f;const float SPIRAL_ROT_SPEED = 2.4f; // 螺旋弹角速度(弧度/秒)const float SPIRAL_EXPAND_RATE = 0.38f; // 螺旋弹径向扩张系数(半径 = speed×rate×寿命)
const int CIRCLE_MIN_CNT = 12;const int CIRCLE_RAND_ADD = 10;// ===== 弹幕数量/形状默认值 =====const int CIRCLE_MIN_CNT = 12; // 无尽模式环形弹最低颗数const int CIRCLE_RAND_ADD = 10; // 无尽模式环形弹在此基础上随机再加 0~9 颗const int FAN_CNT = 10; // 无尽模式扇形弹默认颗数const float FAN_MIN_DEG = 30.f; // 无尽模式扇形最小张角(度)const float FAN_MAX_DEG = 80.f; // 无尽模式扇形最大张角(度)
const int FAN_CNT = 10;const float FAN_MIN_DEG = 30.f;const float FAN_MAX_DEG = 80.f;// ===== 计分与连击 =====const float MAX_MULT = 3.0f; // 连击倍率上限const float COMBO_DECAY = 4.0f; // 连击维持时间(秒):超过此时长未擦弹/续连则断连const float COMBO_GAIN_RATE = 0.08f; // 每存活 1 秒连击加成的倍率增量(mult = 1 + combo×rate)const float SCORE_BASE = 10.0f; // 每存活 1 秒的基础分(再乘 mult×diff_mult)const float GRAZE_SCORE = 25.0f; // 单次擦弹得分(再乘当前 mult)
const float MAX_MULT = 3.0f;const float COMBO_DECAY = 4.0f;const float COMBO_GAIN_RATE = 0.08f;const float SCORE_BASE = 10.0f;const float GRAZE_SCORE = 25.0f;// ===== 剧情打字机 =====const float TYPEWRITER_SPEED = 0.04f; // 每个字符推进所需秒数(越小越快)
const int REVIVE_MAX = 3;
bool god_mode = false;
template<typename T>T clamp(T v, T lo, T hi) { if(v < lo) return lo; if(v > hi) return hi; return v;template <typename T> T clamp(T v, T lo, T hi) { if (v < lo) return lo; if (v > hi) return hi; return v;}
void set_color(int c) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);void set_color(int c) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); }void reset_color() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), C_WHITE); }
// 用 API 清屏替代 clear_screen():无进程开销、无缓冲竞态、不闪烁void clear_screen() { std::cout.flush(); // 先冲掉 cout 缓冲,杜绝竞态 HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD written = 0; COORD home = {0, 0}; if (GetConsoleScreenBufferInfo(h, &csbi)) { DWORD cells = (DWORD)csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacterA(h, ' ', cells, home, &written); FillConsoleOutputAttribute(h, C_WHITE, cells, home, &written); SetConsoleCursorPosition(h, home); }}void reset_color() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), C_WHITE);}
bool key[256] = {false};bool last_key[256] = {false};
void update_key() { for(int i = 0; i < 256; i++) last_key[i] = key[i]; for(int i = 0; i < 256; i++) { key[i] = (GetAsyncKeyState(i) & 0x8000) != 0; } for (int i = 0; i < 256; i++) last_key[i] = key[i]; for (int i = 0; i < 256; i++) key[i] = (GetAsyncKeyState(i) & 0x8000) != 0;}
enum BulletType { B_LINE, B_AIM, B_CIRCLE, B_FAN, B_SPIRAL, B_BOUNCE, B_ACCEL, B_DELAY};enum BulletType { B_LINE, B_AIM, B_CIRCLE, B_FAN, B_SPIRAL, B_BOUNCE, B_ACCEL, B_DELAY, B_BLASTER, B_BLASTER_AIM };
struct Bullet { BulletType type; float x, y; float vx, vy; float speed; float acc; float delay_timer; float spiral_ang; float birth; int bounce_left; char ch; int col; bool active; BulletType type{}; float x{}; float y{}; float vx{}; float vy{}; float speed{}; float acc = 0.f; // M8:全部字段默认初始化消除UB float delay_timer = 0.f; float spiral_ang = 0.f; float spiral_x0 = 0.f; // S1修复螺旋:保存螺旋发射原点X float spiral_y0 = 0.f; // S1修复螺旋:保存螺旋发射原点Y float birth = 0.f; int bounce_left = 0; char ch = '*'; int col = C_WHITE; bool active = false;};
struct NoteEvent { float time; float x, y; BulletType type; std::vector<float> args; float time; float x, y; BulletType type; std::vector<float> args;};
struct Stage { std::string name; std::string story; float base_speed; std::vector<NoteEvent> notes;// 【新增】单关卡结构(DIY/内置关卡统一)struct DanStage { std::string name; std::vector<std::string> pages; // 多页剧情,每页打字机 float diff_mult; float base_speed; std::vector<NoteEvent> notes;};
enum GameMode { MODE_CHALLENGE, MODE_ENDLESS, MODE_DIYstruct DialogueState { bool active = false; bool finished = true; int page_idx = 0; int char_idx = 0; float timer = 0.f; std::vector<std::string> *pages = nullptr;
void start(std::vector<std::string> &p) { pages = &p; page_idx = 0; char_idx = 0; timer = 0.f; active = !p.empty(); finished = p.empty(); }
void stop() { active = false; finished = true; pages = nullptr; }
int cur_len() const { if (!pages || page_idx < 0 || page_idx >= (int)pages->size()) return 0; return (int)(*pages)[page_idx].size(); }
bool page_done() const { return char_idx >= cur_len(); }
void update(float dt) { if (!active) return; if (page_done()) { // 本页打完,停止累加 timer = 0.f; return; } timer += dt; while (timer >= TYPEWRITER_SPEED && !page_done()) { timer -= TYPEWRITER_SPEED; char_idx++; } }
void fast_forward() { if (active) char_idx = cur_len(); // 上限就是本页长度 }
bool next_page() { if (!active) return false; page_idx++; char_idx = 0; timer = 0.f; if (page_idx >= (int)pages->size()) { active = false; finished = true; return false; } return true; }
std::string get_display() const { if (!active || !pages || page_idx < 0 || page_idx >= (int)pages->size()) return ""; const std::string &s = (*pages)[page_idx]; int n = char_idx; if (n < 0) n = 0; if (n > (int)s.size()) n = (int)s.size(); return s.substr(0, n); }
int page_count() const { return pages ? (int)pages->size() : 0; }};enum OverlayState { OVERLAY_NONE, OVERLAY_HELP, OVERLAY_STORY};enum Difficulty { D_EASY, D_NORMAL, D_HARD};
enum GameMode { MODE_CHALLENGE, MODE_ENDLESS, MODE_DIY };enum OverlayState { OVERLAY_NONE, OVERLAY_HELP, OVERLAY_STORY, OVERLAY_CLEARWAIT, OVERLAY_PAUSE, OVERLAY_DEAD, OVERLAY_GAMEOVER };enum Difficulty { D_EASY, D_NORMAL, D_HARD };
float diff_rate;
struct ScoreMgr { unsigned long long score; float combo; float combo_timer; float mult; void reset() { score = 0; combo = 0; mult = 1.0f; combo_timer = 0; } void hurt() { combo = 0; mult = 1.0f; combo_timer = 0; } void add(float val) { score += (unsigned long long)llround(val); //【评审修复】计分取整消除丢分 } void add_tick(float dt, float diff_mult) { float add = SCORE_BASE * dt * mult * diff_mult; score += (unsigned long long)llround(add); //【评审修复】计分取整消除丢分 if(combo > 0) { combo += dt; mult = clamp(1.0f + combo * COMBO_GAIN_RATE, 1.0f, MAX_MULT); } } void tick(float dt) { if(combo_timer > 0) { combo_timer -= dt; if(combo_timer <= 0) hurt(); } } void refresh_combo() { combo_timer = COMBO_DECAY; if(combo <= 0) combo = 0.01f; } unsigned long long score; float combo; float combo_timer; float mult;
void reset() { score = 0; combo = 0; mult = 1.0f; combo_timer = 0; }
void hurt() { combo = 0; mult = 1.0f; combo_timer = 0; }
void add(float val) { score += (unsigned long long)llround(val); }
void add_tick(float dt, float diff_mult) { float add = SCORE_BASE * dt * mult * diff_mult; score += (unsigned long long)llround(add); if (combo > 0) { combo += dt; mult = clamp(1.0f + combo * COMBO_GAIN_RATE, 1.0f, MAX_MULT); } }
void tick(float dt) { if (combo_timer > 0) { combo_timer -= dt; if (combo_timer <= 0) hurt(); } }
void refresh_combo() { combo_timer = COMBO_DECAY; if (combo <= 0) combo = 0.01f; }};
struct Player { float x, y; int hp; int max_hp; float invincible; float x, y; int hp; int max_hp; float invincible;};
std::vector<Bullet> bullets;std::vector<NoteEvent> note_list;std::vector<Stage> stage_list;std::vector<DanStage> dan_stage_list; // 内置挑战关卡列表std::vector<DanStage> diy_stage_list; // DIY加载的多关卡ScoreMgr sc;Player pl;GameMode gmode;OverlayState overlay = OVERLAY_NONE;float overlay_timer = 0.f;int cur_stage = 0;int cur_stage_idx = 0;int note_ptr = 0;float game_timer;bool running;bool gameover;bool win;float spawn_t;DialogueState dlg;int revive_count = 0;std::string cur_user = ""; // 空 = 游客const std::string USERS_FILE = "users.txt";bool g_logout_request = false;
std::string save_path() { if (cur_user.empty()) return "save_guest.txt"; return "save_" + cur_user + ".txt";}
unsigned long long best_endless[3] = {0, 0, 0};unsigned long long best_challenge = 0;int saved_god = 0;int saved_diff = 1;
int diff_index() { return diff_rate <= 0.65f ? 0 : (diff_rate <= 1.0f ? 1 : 2); }
unsigned long long get_revive_cost() { unsigned long long base = (diff_rate <= 0.65f) ? 2000ULL : (diff_rate <= 1.0f ? 3000ULL : 4000ULL); return base + 8000ULL * revive_count;}
char get_bullet_ch(BulletType t) { switch(t) { case B_LINE: return '#'; case B_AIM: return '@'; case B_CIRCLE: return 'O'; case B_FAN: return '%'; case B_SPIRAL: return '&'; case B_BOUNCE: return '?'; case B_ACCEL: return '!'; case B_DELAY: return '+'; default: return '*'; } switch (t) { case B_LINE: return '#'; case B_AIM: return '@'; case B_CIRCLE: return 'O'; case B_FAN: return '%'; case B_SPIRAL: return '&'; case B_BOUNCE: return '?'; case B_ACCEL: return '!'; case B_DELAY: return '+'; case B_BLASTER: case B_BLASTER_AIM: return 'D'; default: return '*'; }}
int get_bullet_color(BulletType t) { switch(t) { case B_LINE: return COLOR_LINE; case B_AIM: return COLOR_AIM; case B_CIRCLE: return COLOR_CIRCLE; case B_FAN: return COLOR_FAN; case B_SPIRAL: return COLOR_SPIRAL; case B_BOUNCE: return COLOR_BOUNCE; case B_ACCEL: return COLOR_ACCEL; case B_DELAY: return COLOR_DELAY; default: return C_WHITE; } switch (t) { case B_LINE: return COLOR_LINE; case B_AIM: return COLOR_AIM; case B_CIRCLE: return COLOR_CIRCLE; case B_FAN: return COLOR_FAN; case B_SPIRAL: return COLOR_SPIRAL; case B_BOUNCE: return COLOR_BOUNCE; case B_ACCEL: return COLOR_ACCEL; case B_DELAY: return COLOR_DELAY; case B_BLASTER: case B_BLASTER_AIM: return COLOR_BLASTER; default: return C_WHITE; }}
BulletType str2type(const std::string& s) { if(s=="line") return B_LINE; if(s=="aim") return B_AIM; if(s=="circle") return B_CIRCLE; if(s=="fan") return B_FAN; if(s=="spiral") return B_SPIRAL; if(s=="bounce") return B_BOUNCE; if(s=="accel") return B_ACCEL; if(s=="delay") return B_DELAY; return B_LINE;BulletType str2type(const std::string &s) { if (s == "line") return B_LINE; if (s == "aim") return B_AIM; if (s == "circle") return B_CIRCLE; if (s == "fan") return B_FAN; if (s == "spiral") return B_SPIRAL; if (s == "bounce") return B_BOUNCE; if (s == "accel") return B_ACCEL; if (s == "delay") return B_DELAY; if (s == "blaster") return B_BLASTER; if (s == "blaster_aim") return B_BLASTER_AIM; return B_LINE;}
std::string type2str(BulletType t) { switch(t) { case B_LINE: return "line"; case B_AIM: return "aim"; case B_CIRCLE: return "circle"; case B_FAN: return "fan"; case B_SPIRAL: return "spiral"; case B_BOUNCE: return "bounce"; case B_ACCEL: return "accel"; case B_DELAY: return "delay"; default: return "line"; } switch (t) { case B_LINE: return "line"; case B_AIM: return "aim"; case B_CIRCLE: return "circle"; case B_FAN: return "fan"; case B_SPIRAL: return "spiral"; case B_BOUNCE: return "bounce"; case B_ACCEL: return "accel"; case B_DELAY: return "delay"; case B_BLASTER: return "blaster"; case B_BLASTER_AIM: return "blaster_aim"; default: return "line"; }}
void build_stages() { Stage tuto; tuto.name = "教学关 · 基础躲避"; tuto.story = "欢迎来到弹幕世界\nWASD移动,Shift低速,H打开帮助\n按空格跳过此提示"; tuto.base_speed = 0.8f; tuto.notes = { {1.0f,32,8, B_CIRCLE, {10}}, {2.5f,16,8, B_AIM, {}}, {2.5f,48,8, B_AIM, {}}, {4.0f,32,8, B_FAN, {7,60,180}}, }; stage_list.push_back(tuto);
Stage s1; s1.name = "符卡一 · 环舞"; s1.story = "环形弹幕会向四周散开,寻找空隙"; s1.base_speed = 1.1f; s1.notes = { {0.5f,32,7, B_CIRCLE, {14}}, {2.0f,32,7, B_CIRCLE, {16}}, {3.2f,12,8, B_AIM, {}}, {3.2f,52,8, B_AIM, {}}, {4.5f,32,7, B_FAN, {10,70,180}}, {6.5f,32,7, B_CIRCLE, {18}}, }; stage_list.push_back(s1);
Stage s2; s2.name = "符卡二 · 回旋"; s2.story = "螺旋弹幕缓缓扩张,不要被逼到角落"; s2.base_speed = 1.25f; s2.notes = { {0.5f,32,6, B_SPIRAL, {2}}, {2.5f,10,8, B_BOUNCE, {30,2}}, {2.5f,54,8, B_BOUNCE, {150,2}}, {4.8f,32,6, B_FAN, {10,75,180}}, {6.8f,32,6, B_SPIRAL, {2, 180.0f}}, }; stage_list.push_back(s2);
Stage s3; s3.name = "符卡三 · 疾行"; s3.story = "加速弹越飞越快,反弹弹可以在墙上来回弹"; s3.base_speed = 1.4f; s3.notes = { {0.5f,32,6, B_ACCEL, {90,80}}, {1.8f,16,6, B_BOUNCE, {45,2}}, {1.8f,48,6, B_BOUNCE, {135,2}}, {3.5f,32,6, B_DELAY, {90,1.0}}, {5.2f,32,6, B_CIRCLE, {20}}, {5.8f,32,6, B_SPIRAL, {2}}, }; stage_list.push_back(s3);// 难度弹量系数:简单 65%,普通 85%,困难 100%float get_bullet_count_mult() { if (diff_rate <= 0.65f) return 0.65f; if (diff_rate <= 1.00f) return 0.85f; return 1.0f;}
void spawn_bullet(BulletType type, float sx, float sy, float vx, float vy, float sp, std::vector<float> args, float now_t) { //【评审修复】删掉死参数phase Bullet b; b.type = type; b.x = sx; b.y = sy; b.vx = vx; b.vy = vy; b.speed = sp; b.acc = 0; b.delay_timer = 0; b.spiral_ang = 0.0f; b.birth = now_t; b.bounce_left = 3; b.ch = get_bullet_ch(type); b.col = get_bullet_color(type); b.active = true; if(type == B_ACCEL) { b.acc = args.size()>=1 ? args[0] : 60.f; } if(type == B_DELAY) { b.delay_timer = args.size()>=1 ? args[0] : 1.2f; } bullets.push_back(b);void spawn_bullet(BulletType type, float sx, float sy, float vx, float vy, float sp, std::vector<float> args, float now_t) { Bullet b; b.type = type; b.x = sx; b.y = sy; b.vx = vx; b.vy = vy; b.speed = sp; b.birth = now_t; b.bounce_left = 3; b.ch = get_bullet_ch(type); b.col = get_bullet_color(type); b.active = true; if (type == B_ACCEL) { b.acc = args.size() >= 1 ? args[0] : 60.f; } if (type == B_DELAY) { b.delay_timer = args.size() >= 1 ? args[0] : 1.2f; } // S1螺旋弹:记录发射原点 if (type == B_SPIRAL) { b.spiral_x0 = sx; b.spiral_y0 = sy; if (args.size() >= 2) b.spiral_ang = args[1] * (float)M_PI / 180.0f; else b.spiral_ang = 2.0f * (float)M_PI * (rand() / (RAND_MAX + 1.0)); } bullets.push_back(b);}
//【评审修复】base_speed接线:增加spd_scale默认参数void spawn_event(const NoteEvent& e, float px, float py, float now_t, float spd_scale = 1.0f) { float base_sp = BULLET_BASE_SPEED * spd_scale; if(e.type == B_LINE) { float ang = e.args[0] * M_PI / 180.0; spawn_bullet(B_LINE, e.x, e.y, cos(ang)*base_sp, sin(ang)*base_sp, base_sp, {}, now_t); } else if(e.type == B_AIM) { float dx = px - e.x; float dy = py - e.y; float len = hypot(dx, dy); if(len < 1e-3) return; spawn_bullet(B_AIM, e.x, e.y, dx/len*base_sp, dy/len*base_sp, base_sp, {}, now_t); } else if(e.type == B_CIRCLE) { int cnt = (int)e.args[0]; cnt = clamp(cnt, 1, 64); for(int i=0; i<cnt; i++) { float ang = 2*M_PI * i / cnt; spawn_bullet(B_CIRCLE, e.x, e.y, cos(ang)*base_sp, sin(ang)*base_sp, base_sp, {}, now_t); } } else if(e.type == B_FAN) { int cnt = (int)e.args[0]; cnt = clamp(cnt, 2, 64); float total_deg = clamp(e.args[1], 5.0f, 120.0f); //【评审修复】fan张角值域夹取 float start_ang = e.args[2] * M_PI / 180.0; float d_ang = total_deg * M_PI / 180.0 / (cnt-1); for(int i=0; i<cnt; i++) { float ang = start_ang + i*d_ang; spawn_bullet(B_FAN, e.x, e.y, cos(ang)*base_sp, sin(ang)*base_sp, base_sp, {}, now_t); } } else if(e.type == B_SPIRAL) { Bullet b; b.type = B_SPIRAL; b.x = e.x; b.y = e.y; b.vx = 0; b.vy = 0; b.speed = base_sp; if(e.args.size() >= 2) b.spiral_ang = e.args[1] * M_PI / 180.0f; else b.spiral_ang = 2.0f * M_PI * (rand() / (RAND_MAX + 1.0)); b.birth = now_t; b.ch = get_bullet_ch(B_SPIRAL); b.col = get_bullet_color(B_SPIRAL); b.active = true; bullets.push_back(b); } else if(e.type == B_BOUNCE) { float ang = e.args[0] * M_PI / 180.0; Bullet b; b.type = B_BOUNCE; b.x = e.x; b.y = e.y; b.vx = cos(ang)*base_sp; b.vy = sin(ang)*base_sp; b.speed = base_sp; b.birth = now_t; b.bounce_left = (int)e.args[1]; b.ch = get_bullet_ch(B_BOUNCE); b.col = get_bullet_color(B_BOUNCE); b.active = true; bullets.push_back(b); } else if(e.type == B_ACCEL) { float ang = e.args[0] * M_PI / 180.0; float a = e.args[1]; spawn_bullet(B_ACCEL, e.x, e.y, cos(ang)*base_sp*0.4f, sin(ang)*base_sp*0.4f, base_sp*0.4f, {a}, now_t); } else if(e.type == B_DELAY) { float ang = e.args[0] * M_PI / 180.0; float dt = e.args[1]; spawn_bullet(B_DELAY, e.x, e.y, cos(ang)*base_sp, sin(ang)*base_sp, base_sp, {dt}, now_t); }void spawn_event(const NoteEvent &e, float px, float py, float now_t, float spd_scale = 1.0f) { auto A = [](const std::vector<float> &v, size_t i, float def = 0.f) -> float { if (i >= v.size()) return def; return (v[i] == RAND_ANGLE) ? (float)(rand() % 360) : v[i]; }; float base_sp = BULLET_BASE_SPEED * spd_scale; if (e.type == B_LINE) { float ang = A(e.args, 0) * M_PI / 180; spawn_bullet(B_LINE, e.x, e.y, cos(ang) * base_sp, sin(ang) * base_sp, base_sp, {}, now_t); } else if (e.type == B_AIM) { float dx = px - e.x; float dy = py - e.y; float len = hypot(dx, dy); if (len < 1e-3) return; spawn_bullet(B_AIM, e.x, e.y, dx / len * base_sp, dy / len * base_sp, base_sp, {}, now_t); } else if (e.type == B_CIRCLE) { int cnt = (int)e.args[0]; cnt = clamp((int)(cnt * get_bullet_count_mult()), 1, 64); for (int i = 0; i < cnt; i++) { float ang = 2 * (float)M_PI * i / cnt; spawn_bullet(B_CIRCLE, e.x, e.y, cos(ang) * base_sp, sin(ang) * base_sp, base_sp, {}, now_t); } } else if (e.type == B_FAN) { int cnt = (int)e.args[0]; cnt = clamp((int)(cnt * get_bullet_count_mult()), 2, 64); float total_deg = clamp(e.args[1], 5.0f, 120.0f); float start_ang = A(e.args, 2) * M_PI / 180; float d_ang = total_deg * (float)M_PI / 180.0 / (cnt - 1); for (int i = 0; i < cnt; i++) { float ang = start_ang + i * d_ang; spawn_bullet(B_FAN, e.x, e.y, cos(ang) * base_sp, sin(ang) * base_sp, base_sp, {}, now_t); } } else if (e.type == B_SPIRAL) { // M7修复死参数 args[0]:螺旋臂数量 int arm_count = (int)e.args[0]; arm_count = clamp(arm_count, 1, 8); for (int a = 0; a < arm_count; a++) { std::vector<float> new_args = e.args; float arm_offset_rad = 2 * (float)M_PI * a / arm_count; if (new_args.size() >= 2) new_args[1] += arm_offset_rad * 180.0f / (float)M_PI; else new_args.push_back(arm_offset_rad * 180.0f / (float)M_PI); spawn_bullet(B_SPIRAL, e.x, e.y, 0, 0, base_sp, new_args, now_t); } } else if (e.type == B_BOUNCE) { float ang = A(e.args, 0) * M_PI / 180; std::vector<float> arg_copy = e.args; spawn_bullet(B_BOUNCE, e.x, e.y, cos(ang) * base_sp, sin(ang) * base_sp, base_sp, arg_copy, now_t); // 读取bounce_left,修改刚生成子弹 Bullet &last = bullets.back(); last.bounce_left = (int)e.args[1]; } else if (e.type == B_ACCEL) { float ang = A(e.args, 0) * M_PI / 180; float a = e.args[1]; spawn_bullet(B_ACCEL, e.x, e.y, cos(ang) * base_sp * 0.4f, sin(ang) * base_sp * 0.4f, base_sp * 0.4f, {a}, now_t); } else if (e.type == B_DELAY) { float ang = A(e.args, 0) * M_PI / 180; float dt = e.args[1]; spawn_bullet(B_DELAY, e.x, e.y, cos(ang) * base_sp, sin(ang) * base_sp, base_sp, {dt}, now_t); } else if (e.type == B_BLASTER) { Bullet b; b.type = B_BLASTER; b.x = e.x; b.y = e.y; b.vx = b.vy = 0; b.spiral_ang = A(e.args, 0) * M_PI / 180.f; b.delay_timer = e.args.size() >= 2 ? e.args[1] : 0.8f; b.acc = e.args.size() >= 3 ? e.args[2] : 0.35f; b.speed = e.args.size() >= 4 ? e.args[3] : 30.f; b.birth = now_t; b.bounce_left = 0; b.ch = 'D'; b.col = COLOR_BLASTER; b.active = true; bullets.push_back(b); } else if (e.type == B_BLASTER_AIM) { Bullet b; b.type = B_BLASTER_AIM; b.x = e.x; b.y = e.y; b.vx = b.vy = 0; float dx = px - e.x, dy = py - e.y; b.spiral_ang = atan2(dy, dx); b.delay_timer = e.args.size() >= 1 ? e.args[0] : 0.8f; b.acc = e.args.size() >= 2 ? e.args[1] : 0.35f; b.speed = e.args.size() >= 3 ? e.args[2] : 30.f; b.birth = now_t; b.bounce_left = 0; b.ch = 'D'; b.col = COLOR_BLASTER; b.active = true; bullets.push_back(b); }}
static int need_args(BulletType t) { switch(t) { case B_LINE: return 1; case B_AIM: return 0; case B_CIRCLE: return 1; case B_FAN: return 3; case B_BOUNCE: return 2; case B_ACCEL: return 2; case B_DELAY: return 2; case B_SPIRAL: return 1; default: return 0; } switch (t) { case B_LINE: return 1; case B_AIM: return 0; case B_CIRCLE: return 1; case B_FAN: return 3; case B_BOUNCE: return 2; case B_ACCEL: return 2; case B_DELAY: return 2; case B_BLASTER: return 1; // 至少角度 case B_BLASTER_AIM: return 0; // 自动瞄准 case B_SPIRAL: return 1; // M7修复:args[0]=臂数 args[1]=初始角度 default: return 0; }}
static std::string tolower_str(std::string s) { for (auto &ch : s) for(auto &ch : s) ch = tolower(static_cast<unsigned char>(ch)); return s; ch = tolower(static_cast<unsigned char>(ch)); return s;}
void load_danmaku(const std::string& fname) { note_list.clear(); std::ifstream f(fname); if(!f.is_open()) { set_color(COLOR_WARN); std::cout << "\n警告:无法打开 " << fname << ",DIY模式无弹幕!\n"; reset_color(); return; } std::string line; while(getline(f, line)) { size_t cmt_pos = line.find("//"); if(cmt_pos != std::string::npos) line = line.substr(0, cmt_pos); bool empty = true; for(char ch : line) { if(!std::isspace(static_cast<unsigned char>(ch))) { empty = false; break; } } if(empty) continue;// 【重写】加载带多stage、page、diff的danmaku文件void load_danmaku(const std::string &fname, std::vector<DanStage> &out_list) { out_list.clear(); std::ifstream f(fname); if (!f.is_open()) { set_color(COLOR_WARN); std::cout << "\n警告:无法打开 " << fname << ",DIY模式无弹幕!\n"; reset_color(); Sleep(600); return; }
std::stringstream ss(line); NoteEvent ne; std::string tname; if(!(ss >> ne.time >> ne.x >> ne.y >> tname)) { set_color(COLOR_WARN); std::cout << "跳过非法谱面行: " << line << "\n"; reset_color(); continue; } ne.type = str2type(tname); float arg; while(ss >> arg) ne.args.push_back(arg); std::string line; DanStage cur_st; bool in_stage = false; int line_no = 0;
int req = need_args(ne.type); if((int)ne.args.size() < req) { set_color(COLOR_WARN); std::cout << "参数不足,跳过行: " << line << "\n"; reset_color(); continue; } ne.time = clamp(ne.time, 0.0f, 999.0f); ne.x = clamp(ne.x, -2.0f, W+2.0f); ne.y = clamp(ne.y, -2.0f, H+2.0f); note_list.push_back(ne); } std::sort(note_list.begin(), note_list.end(), [](const NoteEvent& a, const NoteEvent& b) { return a.time < b.time; }); set_color(COLOR_INFO); std::cout << "成功加载谱面:" << fname << "\n"; reset_color(); Sleep(600); while (getline(f, line)) { line_no++;
size_t cmt_pos = line.find("//"); if (cmt_pos != std::string::npos) line = line.substr(0, cmt_pos);
std::stringstream ss(line); std::string tok; ss >> tok;
if (tok == "stage") { if (in_stage) { out_list.push_back(cur_st); cur_st = DanStage{}; } in_stage = true; cur_st.diff_mult = 1.0f; cur_st.base_speed = 1.0f; } else if (tok == "}") { if (in_stage) { out_list.push_back(cur_st); cur_st = DanStage{}; in_stage = false; } } else if (tok == "name") { std::string rest; getline(ss, rest); size_t q1 = rest.find('"'); size_t q2 = rest.find('"', q1 + 1); if (q1 != std::string::npos && q2 != std::string::npos) { cur_st.name = rest.substr(q1 + 1, q2 - q1 - 1); } } else if (tok == "page") { std::string rest; getline(ss, rest); size_t q1 = rest.find('"'); size_t q2 = rest.find('"', q1 + 1); if (q1 != std::string::npos && q2 != std::string::npos) { cur_st.pages.push_back(rest.substr(q1 + 1, q2 - q1 - 1)); } } else if (tok == "diff") { float v; if (ss >> v) cur_st.diff_mult = v; } else if (tok == "base_speed") { float v; if (ss >> v) cur_st.base_speed = v; } else if (tok == "note") { NoteEvent ne; std::string tname; ss >> ne.time >> ne.x >> ne.y >> tname; ne.type = str2type(tname);
std::string argtok; while (ss >> argtok) { if (argtok == "rand" || argtok == "r") { ne.args.push_back(RAND_ANGLE); } else { try { ne.args.push_back(std::stof(argtok)); } catch (...) { set_color(COLOR_WARN); std::cout << "第 " << line_no << " 行参数非法:" << argtok << "\n"; reset_color(); } } }
int req = need_args(ne.type); if ((int)ne.args.size() < req) { set_color(COLOR_WARN); std::cout << "第 " << line_no << " 行参数不足,需要 " << req << " 个,已忽略\n"; reset_color(); } if ((int)ne.args.size() >= req) { ne.time = clamp(ne.time, 0.0f, 999.0f); ne.x = clamp(ne.x, -2.0f, W + 2.0f); ne.y = clamp(ne.y, -2.0f, H + 2.0f); cur_st.notes.push_back(ne); } } }
if (in_stage) { out_list.push_back(cur_st); }
for (auto &s : out_list) { std::sort(s.notes.begin(), s.notes.end(), [](const NoteEvent &a, const NoteEvent &b) { return a.time < b.time; }); }
set_color(COLOR_INFO); std::cout << "成功加载谱面:" << fname << ",关卡数量:" << out_list.size() << "\n"; reset_color(); Sleep(600);}
struct DirItem { bool is_dir; std::string display_name; std::string full_path; bool is_dir; std::string display_name; std::string full_path;};
std::vector<DirItem> scan_dir(const std::string& base) { std::vector<DirItem> res; std::string pattern = base + "\\*"; WIN32_FIND_DATAA fd; HANDLE hFind = FindFirstFileA(pattern.c_str(), &fd); if(hFind == INVALID_HANDLE_VALUE) return res; do { std::string name = fd.cFileName; if(name == "." || name == "..") continue; std::string full = base + "/" + name; bool isd = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; if(isd) { res.push_back({true, name, full}); } else { std::string low = tolower_str(name); if(low.size() >= 9 && low.substr(low.size()-8) == ".danmaku") { res.push_back({false, name, full}); } } } while(FindNextFileA(hFind, &fd)); FindClose(hFind); std::sort(res.begin(), res.end(), [](const DirItem& a, const DirItem& b){ if(a.is_dir != b.is_dir) return a.is_dir > b.is_dir; return a.display_name < b.display_name; }); return res;std::vector<DirItem> scan_dir(const std::string &base) { std::vector<DirItem> res; std::string pattern = base + "\\*"; WIN32_FIND_DATAA fd; HANDLE hFind = FindFirstFileA(pattern.c_str(), &fd); if (hFind == INVALID_HANDLE_VALUE) return res;
do { std::string name = fd.cFileName; if (name == "." || name == "..") continue; std::string full = base + "/" + name; bool isd = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; if (isd) { res.push_back({true, name, full}); } else { std::string low = tolower_str(name); if (low.size() >= 9 && low.substr(low.size() - 8) == ".danmaku") { res.push_back({false, name, full}); } } } while (FindNextFileA(hFind, &fd)); FindClose(hFind);
std::sort(res.begin(), res.end(), [](const DirItem &a, const DirItem &b) { if (a.is_dir != b.is_dir) return a.is_dir > b.is_dir; return a.display_name < b.display_name; }); return res;}
std::string select_dan_file() { const int VIEW_H = 12; std::string cur_path = "."; while(true) { auto items = scan_dir(cur_path); if(items.empty()) { system("cls"); set_color(COLOR_WARN); std::cout << "当前目录【" << cur_path << "】为空\n"; reset_color(); Sleep(800); if(cur_path == ".") return ""; size_t pos = cur_path.find_last_of('/'); if(pos == std::string::npos) cur_path = "."; else cur_path = cur_path.substr(0, pos); continue; } int sel = 0; while(true) { update_key(); system("cls"); set_color(COLOR_TITLE); std::cout << "==== 选择DIY弹幕谱 ====\n"; std::cout << "当前目录:" << cur_path << "\n\n"; reset_color(); std::cout << "↑ ↓切换 | 回车进入文件夹/选中谱子 | B返回上级 | ESC返回菜单\n\n"; const int VIEW_H = 12; std::string cur_path = ".";
int top = clamp(sel - VIEW_H, 0, (int)items.size()-1); int bot = clamp(sel + VIEW_H, 0, (int)items.size()-1); if(top > 0) std::cout << " ↑ 更多上方\n"; for(int i=top; i<=bot; i++) { if(i == sel) { set_color(COLOR_PLAYER); if(items[i].is_dir) std::cout << " > [文件夹] " << items[i].display_name << "\n"; else std::cout << " > [谱子] " << items[i].display_name << "\n"; } else { if(items[i].is_dir) std::cout << " [文件夹] " << items[i].display_name << "\n"; else std::cout << " [谱子] " << items[i].display_name << "\n"; } reset_color(); } if(bot < (int)items.size()-1) std::cout << " ↓ 更多下方\n"; while (true) { auto items = scan_dir(cur_path); if (items.empty()) { clear_screen(); set_color(COLOR_WARN); std::cout << "当前目录【" << cur_path << "】为空\n"; reset_color(); Sleep(800); if (cur_path == ".") return ""; size_t pos = cur_path.find_last_of('/'); if (pos == std::string::npos) cur_path = "."; else cur_path = cur_path.substr(0, pos); continue; }
if(key[VK_UP] && !last_key[VK_UP]) sel = clamp(sel-1, 0, (int)items.size()-1); if(key[VK_DOWN] && !last_key[VK_DOWN]) sel = clamp(sel+1, 0, (int)items.size()-1); if(key['B'] && !last_key['B']) { if(cur_path == ".") continue; size_t pos = cur_path.find_last_of('/'); if(pos == std::string::npos) cur_path = "."; else cur_path = cur_path.substr(0, pos); break; } if(key[VK_RETURN] && !last_key[VK_RETURN]) { if(items[sel].is_dir) { cur_path = items[sel].full_path; break; } else { return items[sel].full_path; } } if(key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { return ""; } Sleep(80); } } int sel = 0; while (true) { update_key(); clear_screen();
set_color(COLOR_TITLE); std::cout << "==== 选择DIY弹幕谱 ====\n"; std::cout << "当前目录:" << cur_path << "\n\n"; reset_color(); std::cout << "↑ ↓切换 | 回车进入文件夹/选中谱子 | B返回上级 | " "ESC返回菜单\n\n";
int top = clamp(sel - VIEW_H, 0, (int)items.size() - 1); int bot = clamp(sel + VIEW_H, 0, (int)items.size() - 1); if (top > 0) std::cout << " ↑ 更多上方\n";
for (int i = top; i <= bot; i++) { if (i == sel) { set_color(COLOR_PLAYER); if (items[i].is_dir) std::cout << " > [文件夹] " << items[i].display_name << "\n"; else std::cout << " > [谱子] " << items[i].display_name << "\n"; } else { if (items[i].is_dir) std::cout << " [文件夹] " << items[i].display_name << "\n"; else std::cout << " [谱子] " << items[i].display_name << "\n"; } reset_color(); }
if (bot < (int)items.size() - 1) std::cout << " ↓ 更多下方\n";
if (key[VK_UP] && !last_key[VK_UP]) sel = clamp(sel - 1, 0, (int)items.size() - 1); if (key[VK_DOWN] && !last_key[VK_DOWN]) sel = clamp(sel + 1, 0, (int)items.size() - 1);
if (key['B'] && !last_key['B']) { if (cur_path == ".") continue; size_t pos = cur_path.find_last_of('/'); if (pos == std::string::npos) cur_path = "."; else cur_path = cur_path.substr(0, pos); break; }
if (key[VK_RETURN] && !last_key[VK_RETURN]) { if (items[sel].is_dir) { cur_path = items[sel].full_path; break; } else { return items[sel].full_path; } }
if (key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { return ""; }
Sleep(80); } }}
void enter_stage(int sid) { if(sid >= (int)stage_list.size()) { win = true; return; } cur_stage = sid; note_ptr = 0; game_timer = 0; bullets.clear(); overlay = OVERLAY_STORY; overlay_timer = 3.0f;// 【新增】预览面板:显示关卡信息,等待确认进入bool preview_stage(const DanStage &st) { clear_screen(); while (true) { update_key(); clear_screen();
set_color(COLOR_TITLE); std::cout << "==== 关卡预览 ====\n"; reset_color(); std::cout << "关卡名:" << st.name << "\n"; std::cout << "本关难度倍率:" << st.diff_mult << "\n"; std::cout << "弹幕速度倍率:" << st.base_speed << "\n"; std::cout << "剧情页数:" << st.pages.size() << "\n"; std::cout << "弹幕事件数量:" << st.notes.size() << "\n\n";
set_color(COLOR_INFO); std::cout << "按 C 开始挑战 | ESC 返回\n"; reset_color();
if (key['C'] && !last_key['C']) { return true; } // 改后if (key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { return false; // ESC 一律取消,与调用方 if (!preview_stage(...)) continue; 一致}
Sleep(80); }}
void enter_stage(int sid, std::vector<DanStage> &list) { if (sid >= (int)list.size()) { win = true; return; } cur_stage_idx = sid; note_ptr = 0; game_timer = 0; bullets.clear(); clear_screen();
if (list[sid].pages.empty()) { overlay = OVERLAY_NONE; // 无剧情直接开打 dlg.active = false; } else { overlay = OVERLAY_STORY; dlg.start(list[sid].pages); }}
void reset_game(GameMode m) { gmode = m; bullets.clear(); game_timer = 0; spawn_t = 0.0f; sc.reset(); pl.x = W/2.f; pl.y = H-6; pl.hp = 5; pl.max_hp = 5; pl.invincible = 0; gameover = false; win = false; overlay = OVERLAY_NONE; overlay_timer = 0; note_ptr = 0; memset(key, 0, sizeof(key)); memset(last_key, 0, sizeof(last_key)); if(gmode == MODE_CHALLENGE) { enter_stage(0); } gmode = m; bullets.clear(); game_timer = 0; spawn_t = 0.0f; sc.reset(); pl.x = W / 2.f; pl.y = H - 6; pl.hp = 5; pl.max_hp = 5; pl.invincible = 0; gameover = false; win = false; overlay = OVERLAY_NONE; overlay_timer = 0; note_ptr = 0; revive_count = 0; clear_screen(); // M1修复重置游戏清屏}
std::string hash_pass(const std::string &s) { unsigned long long h = 1469598103934665603ULL; for (unsigned char c : s) { h ^= c; h *= 1099511628211ULL; } std::ostringstream oss; oss << std::hex << h; return oss.str();}
bool valid_username(const std::string &s) { if (s.empty() || s.size() > 16) return false; for (unsigned char c : s) { if (!isalnum(c) && c != '_') return false; } return true;}
bool user_exists(const std::string &name, std::string *out_hash = nullptr) { std::ifstream f(USERS_FILE); std::string u, h; while (f >> u >> h) { if (u == name) { if (out_hash) *out_hash = h; return true; } } return false;}
bool register_user(const std::string &name, const std::string &pass) { if (!valid_username(name)) return false; if (user_exists(name)) return false;
std::ofstream f(USERS_FILE, std::ios::app); if (!f.is_open()) return false; f << name << " " << hash_pass(pass) << "\n"; return true;}
bool login_user(const std::string &name, const std::string &pass) { std::string h; if (!user_exists(name, &h)) return false; return h == hash_pass(pass);}
std::string input_visible() { std::string s; while (true) { int ch = _getch(); if (ch == 0 || ch == 224) { _getch(); continue; } if (ch == 13) break; if (ch == 8) { if (!s.empty()) { s.pop_back(); std::cout << "\b \b"; } } else if (ch >= 32 && ch < 127) { s.push_back((char)ch); std::cout << (char)ch; } } return s;}
std::string input_password() { std::string s; while (true) { int ch = _getch(); if (ch == 0 || ch == 224) { _getch(); continue; } if (ch == 13) break; if (ch == 8) { if (!s.empty()) { s.pop_back(); std::cout << "\b \b"; // 删掉一个星号 } } else if (ch >= 32 && ch < 127) { s.push_back((char)ch); std::cout << '*'; // 每输入一个字符显示一个星号 } } return s;}
// 返回:0 游客,1 已登录,-1 退出int login_screen() { while (true) { clear_screen();
set_color(COLOR_TITLE); std::cout << "=====================\n"; std::cout << " 控制台弹幕游戏\n"; std::cout << "=====================\n\n"; reset_color(); std::cout << "1 游客模式\n"; std::cout << "2 登录\n"; std::cout << "3 注册\n"; std::cout << "4 退出\n\n"; std::cout << "选择:";
int ch = _getch(); if (ch == 0 || ch == 224) { _getch(); continue; }
if (ch == '1') { cur_user = ""; return 0; } else if (ch == '2') { clear_screen(); std::cout << "用户名:"; std::string name = input_visible(); std::cout << "\n密码:"; std::string pass = input_password(); std::cout << "\n"; if (login_user(name, pass)) { cur_user = name; std::cout << "登录成功。\n"; Sleep(600); return 1; } else { set_color(COLOR_WARN); std::cout << "用户名或密码错误。\n"; reset_color(); Sleep(800); } } else if (ch == '3') { clear_screen(); std::cout << "新用户名(字母数字下划线,<=16):"; std::string name = input_visible(); std::cout << "\n"; if (!valid_username(name)) { set_color(COLOR_WARN); std::cout << "用户名非法。\n"; reset_color(); Sleep(800); continue; } if (user_exists(name)) { set_color(COLOR_WARN); std::cout << "用户名已存在。\n"; reset_color(); Sleep(800); continue; } std::cout << "密码:"; std::string p1 = input_password(); std::cout << "\n确认密码:"; std::string p2 = input_password(); std::cout << "\n"; if (p1 != p2 || p1.empty()) { set_color(COLOR_WARN); std::cout << "两次密码不一致或为空。\n"; reset_color(); Sleep(800); continue; } if (register_user(name, p1)) { cur_user = name; std::cout << "注册成功,已登录。\n"; Sleep(600); return 1; } else { set_color(COLOR_WARN); std::cout << "注册失败,无法写入 users.txt。\n"; reset_color(); Sleep(800); } } else if (ch == '4' || ch == 27) { return -1; } }}
void load_save() { best_endless[0] = best_endless[1] = best_endless[2] = 0; best_challenge = 0; saved_god = 0; saved_diff = 1;
std::ifstream f(save_path()); if (!f.is_open()) return;
std::string k; unsigned long long v; while (f >> k >> v) { if (k == "endless_easy") best_endless[0] = v; else if (k == "endless_normal") best_endless[1] = v; else if (k == "endless_hard") best_endless[2] = v; else if (k == "challenge") best_challenge = v; else if (k == "god") saved_god = (int)v; else if (k == "diff") saved_diff = (int)v; }}
void save_game() { std::ofstream f(save_path()); if (!f.is_open()) return; f << "endless_easy " << best_endless[0] << "\n"; f << "endless_normal " << best_endless[1] << "\n"; f << "endless_hard " << best_endless[2] << "\n"; f << "challenge " << best_challenge << "\n"; f << "god " << saved_god << "\n"; f << "diff " << saved_diff << "\n";}
void update_best() { if (gmode == MODE_ENDLESS) { int di = diff_index(); if (sc.score > best_endless[di]) best_endless[di] = sc.score; } else { if (sc.score > best_challenge) best_challenge = sc.score; }}
void build_builtin_stages() { DanStage tuto; tuto.name = "教学关 · 基础躲避"; tuto.pages = {"欢迎来到弹幕世界", "WASD移动,Shift低速", "X跳过打字,C继续剧情"}; tuto.diff_mult = 0.8f; tuto.base_speed = 0.8f; tuto.notes = { {1.0f, 32, 8, B_CIRCLE, {10}}, {2.5f, 16, 8, B_AIM, {}}, {2.5f, 48, 8, B_AIM, {}}, {4.0f, 32, 8, B_FAN, {7, 60, 180}}, }; dan_stage_list.push_back(tuto);
DanStage s1; s1.name = "符卡一 · 环舞"; s1.pages = {"环形弹幕向四周散开", "寻找空隙躲避"}; s1.diff_mult = 1.0f; s1.base_speed = 1.1f; s1.notes = { {0.5f, 32, 7, B_CIRCLE, {14}}, {2.0f, 32, 7, B_CIRCLE, {16}}, {3.2f, 12, 8, B_AIM, {}}, {3.2f, 52, 8, B_AIM, {}}, {4.5f, 32, 7, B_FAN, {10, 70, 180}}, {6.5f, 32, 7, B_CIRCLE, {18}}, }; dan_stage_list.push_back(s1);
DanStage s2; s2.name = "符卡二 · 回旋"; s2.pages = {"螺旋弹幕缓缓扩张", "不要被逼到角落"}; s2.diff_mult = 1.1f; s2.base_speed = 1.25f; s2.notes = { {0.5f, 32, 6, B_SPIRAL, {2,0.0f}}, // args[0]=螺旋臂数量 {2.5f, 10, 8, B_BOUNCE, {30, 2}}, {2.5f, 54, 8, B_BOUNCE, {150, 2}}, {4.8f, 32, 6, B_FAN, {10, 75, 180}}, {6.8f, 32, 6, B_SPIRAL, {2, 180.0f}}, }; dan_stage_list.push_back(s2);
DanStage s3; s3.name = "符卡三 · 疾行"; s3.pages = {"加速弹越飞越快", "反弹弹可在墙上来回弹"}; s3.diff_mult = 1.2f; s3.base_speed = 1.4f; s3.notes = { {0.5f, 32, 6, B_ACCEL, {90, 80}}, {1.8f, 16, 6, B_BOUNCE, {45, 2}}, {1.8f, 48, 6, B_BOUNCE, {135, 2}}, {3.5f, 32, 6, B_DELAY, {90, 1.0}}, {5.2f, 32, 6, B_CIRCLE, {20}}, {5.8f, 32, 6, B_SPIRAL, {2,0.0f}}, }; dan_stage_list.push_back(s3);
DanStage s4; s4.name = "符卡四 · 龙息"; s4.pages = {"龙骨炮蓄力时显示 3x3 警告框", "看到 D 立刻离开射线方向", "激光是线段,斜着也能命中"}; s4.diff_mult = 1.15f; s4.base_speed = 1.3f; s4.notes = { {0.5f, 32, 4, B_BLASTER, {90}}, {0.5f, 10, 16, B_BLASTER, {0}}, {0.5f, 54, 16, B_BLASTER, {180}}, {2.2f, 32, 4, B_BLASTER_AIM, {}}, {3.8f, 16, 16, B_BLASTER, {45}}, {3.8f, 48, 16, B_BLASTER, {135}}, {5.5f, 32, 4, B_BLASTER_AIM, {0.7f, 0.4f, 40}}, }; dan_stage_list.push_back(s4);}
void bullet_update(float dt) { if(overlay != OVERLAY_NONE || gameover || win) return; for(auto& b : bullets) { if(!b.active) continue; if(b.type == B_DELAY && b.delay_timer > 0) { b.delay_timer -= dt; if(b.delay_timer > 0) { if(b.x < -2 || b.x > W+2 || b.y < -2 || b.y > H+2) b.active = false; continue; } } if(b.type == B_ACCEL) { float len = hypot(b.vx, b.vy); if(len > 1e-3) { b.vx += b.vx / len * b.acc * dt; b.vy += b.vy / len * b.acc * dt; } } if(b.type == B_SPIRAL) { b.spiral_ang += dt * SPIRAL_ROT_SPEED; float life = game_timer - b.birth; float r = b.speed * life * SPIRAL_EXPAND_RATE; b.x += cos(b.spiral_ang) * r * dt; b.y += sin(b.spiral_ang) * r * dt; } else { b.x += b.vx * dt; b.y += b.vy * dt; } if (overlay != OVERLAY_NONE || gameover || win) return;
if(b.type == B_BOUNCE) { const float wall_margin = BULLET_R + 0.05f; if(b.x < wall_margin || b.x > W - wall_margin) { b.vx *= -1; b.x = clamp(b.x, wall_margin, W-wall_margin); b.bounce_left--; if(b.bounce_left <=0) b.active = false; } if(b.y < wall_margin || b.y > H - wall_margin) { b.vy *= -1; b.y = clamp(b.y, wall_margin, H-wall_margin); b.bounce_left--; if(b.bounce_left <=0) b.active = false; } } else { if(b.x < -2 || b.x > W+2 || b.y < -2 || b.y > H+2) { b.active = false; } } } bullets.erase(std::remove_if(bullets.begin(), bullets.end(), [](const Bullet& b) { return !b.active; }), bullets.end()); for (auto &b : bullets) { if (!b.active) continue;
if (b.type == B_DELAY && b.delay_timer > 0) { b.delay_timer -= dt; if (b.delay_timer > 0) { if (b.x < -2 || b.x > W + 2 || b.y < -2 || b.y > H + 2) b.active = false; continue; } }
if (b.type == B_BLASTER || b.type == B_BLASTER_AIM) { if (b.delay_timer > 0) { b.delay_timer -= dt; if (b.delay_timer < 0) b.delay_timer = 0; } else { b.acc -= dt; if (b.acc <= 0) b.active = false; } continue; }
if (b.type == B_ACCEL) { float len = hypot(b.vx, b.vy); if (len > 1e-3) { b.vx += b.vx / len * b.acc * dt; b.vy += b.vy / len * b.acc * dt; } }
if (b.type == B_SPIRAL) { // ========= S1修复螺旋弹运动学 正确公式 ========= b.spiral_ang += dt * SPIRAL_ROT_SPEED; float life = game_timer - b.birth; float vr = b.speed * SPIRAL_EXPAND_RATE; float r = vr * life; b.x = b.spiral_x0 + r * cos(b.spiral_ang); b.y = b.spiral_y0 + r * sin(b.spiral_ang); if (life > 5.0f) b.active = false; } else { b.x += b.vx * dt; b.y += b.vy * dt; }
if (b.type == B_BOUNCE) { const float wall_margin = BULLET_R + 0.05f; if (b.x < wall_margin || b.x > W - wall_margin) { b.vx *= -1; b.x = clamp(b.x, wall_margin, W - wall_margin); b.bounce_left--; if (b.bounce_left <= 0) b.active = false; } if (b.y < wall_margin || b.y > H - wall_margin) { b.vy *= -1; b.y = clamp(b.y, wall_margin, H - wall_margin); b.bounce_left--; if (b.bounce_left <= 0) b.active = false; } } else { if (b.x < -2 || b.x > W + 2 || b.y < -2 || b.y > H + 2) { b.active = false; } } }
bullets.erase(std::remove_if(bullets.begin(), bullets.end(), [](const Bullet &b) { return !b.active; }), bullets.end());}
void player_update(float dt) { if(gameover || win || overlay != OVERLAY_NONE) return; float dx=0, dy=0; if(key['W']) dy -=1; if(key['S']) dy +=1; if(key['A']) dx -=1; if(key['D']) dx +=1; if (gameover || win || overlay != OVERLAY_NONE) return;
float len = hypot(dx, dy); bool slow_key = key[VK_LSHIFT] || key[VK_RSHIFT]; //【评审修复】支持右Shift低速 float sp = slow_key ? PLAYER_SPEED_SLOW : PLAYER_SPEED; if(len > 1e-3) { dx /= len; dy /= len; } pl.x += dx * sp * dt; pl.y += dy * sp * dt; pl.x = clamp(pl.x, PLAYER_VIS_R, W-PLAYER_VIS_R); pl.y = clamp(pl.y, PLAYER_VIS_R, H-PLAYER_VIS_R); if(pl.invincible > 0) pl.invincible -= dt; float dx = 0, dy = 0; if (key['W']) dy -= 1; if (key['S']) dy += 1; if (key['A']) dx -= 1; if (key['D']) dx += 1;
float len = hypot(dx, dy); bool slow_key = key[VK_LSHIFT] || key[VK_RSHIFT]; float sp = slow_key ? PLAYER_SPEED_SLOW : PLAYER_SPEED;
if (len > 1e-3) { dx /= len; dy /= len; }
pl.x += dx * sp * dt; pl.y += dy * sp * dt;
pl.x = clamp(pl.x, 1.0f, (float)(W - 2)); pl.y = clamp(pl.y, 1.0f, (float)(H - 2));
if (pl.invincible > 0) pl.invincible -= dt;}
float point_seg_dist(float px, float py, float x0, float y0, float x1, float y1) { float dx = x1 - x0, dy = y1 - y0; float len2 = dx * dx + dy * dy; if (len2 < 1e-6f) return hypot(px - x0, py - y0); float t = ((px - x0) * dx + (py - y0) * dy) / len2; t = clamp(t, 0.0f, 1.0f); float cx = x0 + t * dx, cy = y0 + t * dy; return hypot(px - cx, py - cy);}
bool collision_and_graze_check() { if(gameover || win || pl.invincible>0 || overlay != OVERLAY_NONE) return false; bool grazed = false; for(auto& b : bullets) { if(!b.active) continue; if(b.type == B_DELAY && b.delay_timer > 0) continue; float dx = b.x - pl.x; float dy = b.y - pl.y; float dist = hypot(dx, dy); if(dist < PLAYER_HIT_R + BULLET_R) { if(!god_mode) { pl.hp--; pl.invincible = 1.2f; sc.hurt(); if(pl.hp <= 0) gameover = true; } return false; } if(!grazed && dist < GRAZE_R + BULLET_R) { grazed = true; } } if(grazed) { sc.add(GRAZE_SCORE * sc.mult); sc.refresh_combo(); } return grazed; if (gameover || win || pl.invincible > 0 || overlay != OVERLAY_NONE) return false;
bool grazed = false;
for (auto &b : bullets) { if (!b.active) continue; if (b.type == B_DELAY && b.delay_timer > 0) continue;
if (b.type == B_BLASTER || b.type == B_BLASTER_AIM) { if (b.delay_timer > 0) continue; // 蓄力不伤害
float x1 = b.x + cos(b.spiral_ang) * b.speed; float y1 = b.y + sin(b.spiral_ang) * b.speed; float d = point_seg_dist(pl.x, pl.y, b.x, b.y, x1, y1);
if (d < PLAYER_HIT_R + 0.5f) { if (!god_mode) { pl.hp--; pl.invincible = 1.2f; sc.hurt(); if (pl.hp <= 0) { pl.hp = 0; if (gmode == MODE_ENDLESS && revive_count < REVIVE_MAX) { overlay = OVERLAY_DEAD; } else { gameover = true; overlay = OVERLAY_GAMEOVER; update_best(); save_game(); } } } return false; } if (!grazed && d < GRAZE_R + 0.8f) grazed = true; continue; }
float dx = b.x - pl.x; float dy = b.y - pl.y; float dist = hypot(dx, dy);
if (dist < PLAYER_HIT_R + BULLET_R) { if (!god_mode) { pl.hp--; pl.invincible = 1.2f; sc.hurt(); if (pl.hp <= 0) { pl.hp = 0; if (gmode == MODE_ENDLESS && revive_count < REVIVE_MAX) { overlay = OVERLAY_DEAD; } else { gameover = true; overlay = OVERLAY_GAMEOVER; update_best(); save_game(); } } } return false; } if (!grazed && dist < GRAZE_R + BULLET_R) { grazed = true; } }
if (grazed) { sc.add(GRAZE_SCORE * sc.mult); sc.refresh_combo(); } return grazed;}
void spawn_logic(float dt) { if(gameover || win || overlay != OVERLAY_NONE) return; if(gmode == MODE_CHALLENGE) { Stage &st = stage_list[cur_stage]; while(note_ptr < (int)st.notes.size() && st.notes[note_ptr].time <= game_timer) { spawn_event(st.notes[note_ptr], pl.x, pl.y, game_timer, st.base_speed); //【评审修复】base_speed传入,接线完成 note_ptr++; } if(note_ptr >= (int)st.notes.size() && bullets.empty()) { enter_stage(cur_stage + 1); } } else if(gmode == MODE_DIY) { while(note_ptr < (int)note_list.size() && note_list[note_ptr].time <= game_timer) { spawn_event(note_list[note_ptr], pl.x, pl.y, game_timer); note_ptr++; } if(note_ptr >= (int)note_list.size() && bullets.empty()) win = true; } else if(gmode == MODE_ENDLESS) { spawn_t += dt; float sp_int = clamp(ENDLESS_SPAWN_BASE / diff_rate, ENDLESS_SPAWN_MIN, ENDLESS_SPAWN_MAX); if(spawn_t > sp_int) { spawn_t = 0; NoteEvent e; e.x = 1 + rand()%(W-2); //【评审修复】无尽出生点避开边框x=0 e.y = 2 + rand()%(H/3); int r = rand()%8; e.type = (BulletType)r; if(e.type == B_LINE) e.args = {(float)(rand()%360)}; else if(e.type == B_AIM) {} else if(e.type == B_CIRCLE) e.args = {(float)(CIRCLE_MIN_CNT + rand()%CIRCLE_RAND_ADD)}; else if(e.type == B_FAN) { int fan_cnt = FAN_CNT; float fan_total = FAN_MIN_DEG + (FAN_MAX_DEG - FAN_MIN_DEG) * (rand() / (RAND_MAX + 1.0f)); float dx = pl.x - e.x; float dy = pl.y - e.y; float center_deg = atan2(dy, dx) * 180.0 / M_PI; float start_deg = center_deg - fan_total / 2.0f; e.args = {(float)fan_cnt, fan_total, start_deg}; } else if(e.type == B_SPIRAL) e.args = {2.0f}; else if(e.type == B_BOUNCE) e.args = {(float)(rand()%360), 2.f}; else if(e.type == B_ACCEL) e.args = {(float)(rand()%360), 75.f}; else if(e.type == B_DELAY) e.args = {(float)(rand()%360), 0.9f}; spawn_event(e, pl.x, pl.y, game_timer); } }void spawn_logic(float dt, std::vector<DanStage> &stage_list) { if (gameover || win || overlay != OVERLAY_NONE) return;
if (gmode == MODE_CHALLENGE || gmode == MODE_DIY) { DanStage &st = stage_list[cur_stage_idx]; while (note_ptr < (int)st.notes.size() && st.notes[note_ptr].time <= game_timer) { // M6 + M9修复:全局diff_rate ×关卡diff_mult,共同缩放弹幕速度 float total_speed_scale = st.base_speed * st.diff_mult * diff_rate; spawn_event(st.notes[note_ptr], pl.x, pl.y, game_timer, total_speed_scale); note_ptr++; } if (note_ptr >= (int)st.notes.size() && bullets.empty()) { overlay = OVERLAY_CLEARWAIT; } } else if (gmode == MODE_ENDLESS) { spawn_t += dt; float sp_int = clamp(ENDLESS_SPAWN_BASE / diff_rate / get_bullet_count_mult(), ENDLESS_SPAWN_MIN, ENDLESS_SPAWN_MAX); if (spawn_t > sp_int) { spawn_t = 0;
NoteEvent e; e.x = 1 + rand() % (W - 2); e.y = 2 + rand() % (H / 3);
int r = rand() % 10; if (r == 8) e.type = B_BLASTER; else if (r == 9) e.type = B_BLASTER_AIM; else e.type = (BulletType)r;
if (e.type == B_LINE) { e.args = {(float)(rand() % 360)}; } else if (e.type == B_AIM) { } else if (e.type == B_CIRCLE) { e.args = {(float)(CIRCLE_MIN_CNT + rand() % CIRCLE_RAND_ADD)}; } else if (e.type == B_FAN) { int fan_cnt = FAN_CNT; float fan_total = FAN_MIN_DEG + (FAN_MAX_DEG - FAN_MIN_DEG) * (rand() / (RAND_MAX + 1.0f)); float dx = pl.x - e.x; float dy = pl.y - e.y; float center_deg = atan2(dy, dx) * 180.0 / (float)M_PI; float start_deg = center_deg - fan_total / 2.0f; e.args = {(float)fan_cnt, fan_total, start_deg}; } else if (e.type == B_SPIRAL) { e.args = {2.0f, 0.f}; } else if (e.type == B_BOUNCE) { e.args = {(float)(rand() % 360), 2.f}; } else if (e.type == B_ACCEL) { e.args = {(float)(rand() % 360), 75.f}; } else if (e.type == B_DELAY) { e.args = {(float)(rand() % 360), 0.9f}; } else if (e.type == B_BLASTER) { e.args = {(float)(rand() % 360)}; } else if (e.type == B_BLASTER_AIM) { }
spawn_event(e, pl.x, pl.y, game_timer); } }}
void render() { COORD pos = {0,0}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); char buf[H][W+1]; int color_buf[H][W]; for(int y=0; y<H; y++) { for(int x=0; x<W; x++) { buf[y][x]=' '; color_buf[y][x]=C_WHITE; } buf[y][W] = '\0'; } for(int x=0; x<W; x++) buf[0][x] = '-', buf[H-1][x] = '-'; for(int y=0; y<H; y++) buf[y][0] = '|', buf[y][W-1] = '|';void render(std::vector<DanStage> &stage_list) { COORD pos = {0, 0}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
for(auto& b : bullets) { if(!b.active) continue; if(b.type == B_DELAY && b.delay_timer > 0) continue; int bx = (int)(b.x + 0.5f); int by = (int)(b.y + 0.5f); //【评审修复】子弹不覆盖边框字符 if(bx>=1 && bx<W-1 && by>=1 && by<H-1) { buf[by][bx] = b.ch; color_buf[by][bx] = b.col; } } int px = (int)(pl.x + 0.5f); int py = (int)(pl.y + 0.5f); bool draw_player = true; if(pl.invincible > 0 && fmod(pl.invincible*12,1)>=0.5) draw_player = false; if(draw_player && px>=1 && px<W-1 && py>=1 && py<H-1) { buf[py][px] = '*'; color_buf[py][px] = COLOR_PLAYER; } char buf[H][W + 1]; int color_buf[H][W];
std::string out; for(int y=0; y<H; y++) { int lastcol = color_buf[y][0]; set_color(lastcol); out += buf[y][0]; for(int x=1; x<W; x++) { if(color_buf[y][x] != lastcol) { lastcol = color_buf[y][x]; set_color(lastcol); } out += buf[y][x]; } reset_color(); out += "\n"; } std::cout << out; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { buf[y][x] = ' '; color_buf[y][x] = C_WHITE; } buf[y][W] = '\0'; }
set_color(COLOR_UI); std::cout << "HP:" << pl.hp << "/" << pl.max_hp << " Score:" << sc.score << " x" << sc.mult; if(gmode == MODE_CHALLENGE) std::cout << " Stage:" << cur_stage+1 << "/" << stage_list.size(); bool slow_key = key[VK_LSHIFT] || key[VK_RSHIFT]; if(slow_key) std::cout << " [SLOW]"; if(god_mode) { set_color(C_LMAGENTA); std::cout << " [GOD]"; set_color(COLOR_UI); } if(gameover) { set_color(COLOR_WARN); std::cout << " GAME OVER"; } if(win) { set_color(COLOR_FAN); std::cout << " CLEAR!"; } reset_color(); std::cout << "\n"; for (int x = 0; x < W; x++) buf[0][x] = '-', buf[H - 1][x] = '-'; for (int y = 0; y < H; y++) buf[y][0] = '|', buf[y][W - 1] = '|';
if(overlay == OVERLAY_HELP) { set_color(COLOR_TITLE); std::cout << "\n==== HELP ====\n"; std::cout << "WASD移动 | Shift低速 | R重开 | H帮助 | ESC返回菜单\n"; std::cout << "#直线 @自机狙 O环 %扇形 &螺旋 ?反弹 !加速 +滞留\n"; std::cout << "任意键关闭帮助\n"; reset_color(); } if(overlay == OVERLAY_STORY) { Stage &st = stage_list[cur_stage]; set_color(COLOR_INFO); std::cout << "\n==== " << st.name << " ====\n" << st.story << "\n"; reset_color(); } //【评审修复】overlay关闭后打印空行清除文本残影 if(overlay == OVERLAY_NONE) { std::cout << std::string(W, ' ') << "\n"; std::cout << std::string(W, ' ') << "\n"; } for (auto &b : bullets) { if (!b.active) continue; if (b.type == B_DELAY && b.delay_timer > 0) continue;
// ===== 龙骨炮:蓄力警告 + 激光 ===== if (b.type == B_BLASTER || b.type == B_BLASTER_AIM) { float ca = cos(b.spiral_ang), sa = sin(b.spiral_ang); int bx = (int)(b.x + 0.5f); int by = (int)(b.y + 0.5f);
if (b.delay_timer > 0) { // ---- 蓄力阶段:3×3 警告框 + 闪烁 + 虚线预警 ---- bool blink = fmod(b.delay_timer * 6.0f, 1.0f) < 0.5f;
// 3×3 炮台框 for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { int nx = bx + dx, ny = by + dy; if (nx < 1 || nx >= W - 1 || ny < 1 || ny >= H - 1) continue; if (dx == 0 && dy == 0) { buf[ny][nx] = blink ? 'D' : '!'; color_buf[ny][nx] = blink ? C_BRIGHT : C_LRED; } else { buf[ny][nx] = '.'; color_buf[ny][nx] = C_LRED; } } }
// 激光路径虚线预警(每 2 格一个) for (float t = 2.0f; t <= b.speed; t += 2.0f) { int lx = (int)(b.x + ca * t + 0.5f); int ly = (int)(b.y + sa * t + 0.5f); if (lx < 1 || lx >= W - 1 || ly < 1 || ly >= H - 1) continue; buf[ly][lx] = blink ? ':' : '.'; color_buf[ly][lx] = C_LRED; } } else { // ---- 激光阶段:亮白密集粗线 ---- char lch = '='; if (fabs(ca) < 0.35f) lch = '|'; else if (fabs(sa) < 0.35f) lch = '-'; else lch = (ca * sa > 0) ? '\\' : '/';
// 步长 0.4,密集覆盖 for (float t = 0; t <= b.speed; t += 0.4f) { int lx = (int)(b.x + ca * t + 0.5f); int ly = (int)(b.y + sa * t + 0.5f); if (lx < 1 || lx >= W - 1 || ly < 1 || ly >= H - 1) continue; buf[ly][lx] = lch; color_buf[ly][lx] = C_BRIGHT; }
// 炮口 D 也显示 if (bx >= 1 && bx < W - 1 && by >= 1 && by < H - 1) { buf[by][bx] = 'D'; color_buf[by][bx] = C_BRIGHT; } } continue; }
// ===== 普通子弹 ===== int bx = (int)(b.x + 0.5f); int by = (int)(b.y + 0.5f); if (bx >= 1 && bx < W - 1 && by >= 1 && by < H - 1) { buf[by][bx] = b.ch; color_buf[by][bx] = b.col; } }
int px = (int)(pl.x + 0.5f); int py = (int)(pl.y + 0.5f); bool draw_player = true; if (pl.invincible > 0 && fmod(pl.invincible * 12, 1) >= 0.5) draw_player = false; if (pl.hp <= 0) draw_player = false;
if (draw_player && px >= 1 && px < W - 1 && py >= 1 && py < H - 1) { buf[py][px] = '*'; color_buf[py][px] = COLOR_PLAYER; }
// 渲染屏幕画面,不再每行reset for (int y = 0; y < H; y++) { int lastcol = color_buf[y][0]; set_color(lastcol); for (int x = 0; x < W; x++) { if (color_buf[y][x] != lastcol) { lastcol = color_buf[y][x]; set_color(lastcol); } std::cout << buf[y][x]; } std::cout << "\n"; } reset_color(); // 画面渲染完统一重置颜色!
set_color(COLOR_UI); std::cout << "HP:" << pl.hp << "/" << pl.max_hp << " Score:" << sc.score << " x" << sc.mult; if (gmode == MODE_CHALLENGE || gmode == MODE_DIY) { std::cout << " Stage:" << cur_stage_idx + 1 << "/" << stage_list.size(); } bool slow_key = key[VK_LSHIFT] || key[VK_RSHIFT]; if (slow_key) std::cout << " [SLOW]"; if (god_mode) { set_color(C_LMAGENTA); std::cout << " [GOD]"; set_color(COLOR_UI); } if (gameover) { set_color(COLOR_WARN); std::cout << " GAME OVER"; } if (win) { set_color(COLOR_FAN); std::cout << " ALL CLEAR!"; } reset_color(); std::cout << "\n";
if (overlay == OVERLAY_HELP) { set_color(COLOR_TITLE); std::cout << "\n==== 帮助 ====\n"; reset_color(); set_color(COLOR_INFO); std::cout << "WASD 移动 | Shift 低速 | H 帮助 | ESC 暂停\n"; std::cout << "R 快速重开本关\n"; std::cout << "剧情:X 快进本页 | C 下一页\n"; std::cout << "通关:C 进入下一关\n"; std::cout << "暂停:1 继续 2 重开 3 返回菜单 4 切换账号\n"; std::cout << "死亡(无尽):1 结束 2 扣分续命,最多 " << REVIVE_MAX << " 次,费用随难度和次数增加\n"; std::cout << "结束:1 重开 2 返回菜单 3 切换账号\n"; std::cout << "弹幕:#直线 @自机狙 O环 %扇形 &螺旋 ?反弹 !加速 +滞留 D龙骨炮\n"; set_color(COLOR_TITLE); std::cout << "按 H 关闭帮助\n"; reset_color(); }
if (overlay == OVERLAY_STORY) { set_color(COLOR_INFO); std::cout << "\n==== " << stage_list[cur_stage_idx].name << " ====\n"; std::cout << dlg.get_display(); if (dlg.active) { std::cout << "\nX=快进 | C=下一页"; } reset_color(); }
if (overlay == OVERLAY_CLEARWAIT) { set_color(COLOR_FAN); std::cout << "\n==== 本关Clear! ====\n"; std::cout << "按 C 进入下一关"; reset_color(); }
if (overlay == OVERLAY_PAUSE) { set_color(COLOR_TITLE); std::cout << "\n==== 暂停 ====\n"; std::cout << "1 继续 2 重开 3 返回菜单\n"; reset_color(); }
if (overlay == OVERLAY_DEAD) { unsigned long long cost = get_revive_cost(); set_color(COLOR_WARN); std::cout << "\n==== 你倒下了 ====\n"; std::cout << "1 结束 2 扣除 " << cost << " 分续命(当前 " << sc.score << ")\n"; std::cout << "已续命:" << revive_count << "/" << REVIVE_MAX << "\n"; if (revive_count >= REVIVE_MAX) std::cout << "续命次数已用完\n"; else if (sc.score < cost) { set_color(C_GRAY); std::cout << "分数不足,无法续命\n"; } reset_color(); }
if (overlay == OVERLAY_GAMEOVER) { set_color(win ? COLOR_FAN : COLOR_WARN); std::cout << (win ? "\n==== ALL CLEAR! ====\n" : "\n==== GAME OVER ====\n"); std::cout << "Score: " << sc.score << "\n"; if (gmode == MODE_ENDLESS) std::cout << "无尽最高分:" << best_endless[diff_index()] << "\n"; else std::cout << "挑战最高分:" << best_challenge << "\n"; std::cout << "1 重开 2 返回菜单\n"; reset_color(); }
if (overlay == OVERLAY_NONE) { std::cout << std::string(W, ' ') << "\n"; std::cout << std::string(W, ' ') << "\n"; }}
bool select_god() { system("cls"); set_color(COLOR_TITLE); std::cout << "==== 无敌模式 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n"; std::string opt[] = {"关闭无敌", "开启无敌"}; int sel = 0; while(true) { update_key(); system("cls"); set_color(COLOR_TITLE); std::cout << "==== 无敌模式 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n"; for(int i=0; i<2; i++) { if(i == sel) { set_color(COLOR_PLAYER); std::cout << " > " << opt[i] << "\n"; } else { std::cout << " " << opt[i] << "\n"; } reset_color(); } if(key[VK_UP] && !last_key[VK_UP]) { sel = clamp(sel-1,0,1); } if(key[VK_DOWN] && !last_key[VK_DOWN]) { sel = clamp(sel+1,0,1); } if(key[VK_RETURN] && !last_key[VK_RETURN]) { return sel == 1; } if(key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { return false; } Sleep(80); } set_color(COLOR_TITLE); std::cout << "==== 无敌模式 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n";
std::string opt[] = {"关闭无敌", "开启无敌"}; int sel = saved_god ? 1 : 0;
while (true) { update_key(); clear_screen();
set_color(COLOR_TITLE); std::cout << "==== 无敌模式 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n";
for (int i = 0; i < 2; i++) { if (i == sel) { set_color(COLOR_PLAYER); std::cout << " > " << opt[i] << "\n"; } else { std::cout << " " << opt[i] << "\n"; } reset_color(); }
if (key[VK_UP] && !last_key[VK_UP]) { sel = clamp(sel - 1, 0, 1); } if (key[VK_DOWN] && !last_key[VK_DOWN]) { sel = clamp(sel + 1, 0, 1); } if (key[VK_RETURN] && !last_key[VK_RETURN]) { saved_god = (sel == 1) ? 1 : 0; save_game(); return sel == 1; } if (key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { return false; }
Sleep(80); }}
Difficulty select_diff() { system("cls"); set_color(COLOR_TITLE); std::cout << "==== 难度选择 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n"; std::string opt[] = {"简单", "普通", "困难"}; int sel = 1; while(true) { update_key(); system("cls"); set_color(COLOR_TITLE); std::cout << "==== 难度选择 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n"; for(int i=0; i<3; i++) { if(i == sel) { set_color(COLOR_PLAYER); std::cout << " > " << opt[i] << "\n"; } else { std::cout << " " << opt[i] << "\n"; } reset_color(); } if(key[VK_UP] && !last_key[VK_UP]) { sel = clamp(sel-1,0,2); } if(key[VK_DOWN] && !last_key[VK_DOWN]) { sel = clamp(sel+1,0,2); } if(key[VK_RETURN] && !last_key[VK_RETURN]) { if(sel ==0) diff_rate = 0.65f; if(sel ==1) diff_rate = 1.00f; if(sel ==2) diff_rate = 1.40f; return (Difficulty)sel; } if(key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { diff_rate = 1.00f; //【评审修复】ESC分支补diff_rate赋值 return D_NORMAL; } Sleep(80); } clear_screen(); set_color(COLOR_TITLE); std::cout << "==== 难度选择 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n";
std::string opt[] = {"简单", "普通", "困难"}; int sel = clamp(saved_diff, 0, 2);
while (true) { update_key(); clear_screen();
set_color(COLOR_TITLE); std::cout << "==== 难度选择 ====\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n";
for (int i = 0; i < 3; i++) { if (i == sel) { set_color(COLOR_PLAYER); std::cout << " > " << opt[i] << "\n"; } else { std::cout << " " << opt[i] << "\n"; } reset_color(); }
if (key[VK_UP] && !last_key[VK_UP]) { sel = clamp(sel - 1, 0, 2); } if (key[VK_DOWN] && !last_key[VK_DOWN]) { sel = clamp(sel + 1, 0, 2); } if (key[VK_RETURN] && !last_key[VK_RETURN]) { if (sel == 0) diff_rate = 0.65f; if (sel == 1) diff_rate = 1.00f; if (sel == 2) diff_rate = 1.40f; saved_diff = sel; save_game(); return (Difficulty)sel; } if (key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { if (saved_diff == 0) diff_rate = 0.65f; else if (saved_diff == 1) diff_rate = 1.00f; else diff_rate = 1.40f; return (Difficulty)saved_diff; }
Sleep(80); }}
GameMode main_menu() { system("cls"); set_color(COLOR_TITLE); std::cout << "=====================\n"; std::cout << " 控制台弹幕游戏\n"; std::cout << "=====================\n\n"; reset_color(); std::string opt[] = {"挑战模式", "无尽模式", "DIY弹幕", "退出"}; int sel = 0; while(true) { update_key(); system("cls"); set_color(COLOR_TITLE); std::cout << "=====================\n"; std::cout << " 控制台弹幕游戏\n"; std::cout << "=====================\n\n"; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n"; for(int i=0; i<4; i++) { if(i == sel) { set_color(COLOR_PLAYER); std::cout << " > " << opt[i] << "\n"; } else { std::cout << " " << opt[i] << "\n"; } reset_color(); } if(key[VK_UP] && !last_key[VK_UP]) { sel = clamp(sel-1,0,3); } if(key[VK_DOWN] && !last_key[VK_DOWN]) { sel = clamp(sel+1,0,3); } if(key[VK_RETURN] && !last_key[VK_RETURN]) { if(sel == 0) return MODE_CHALLENGE; if(sel == 1) return MODE_ENDLESS; if(sel == 2) return MODE_DIY; if(sel == 3) exit(0); } if(key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { return MODE_CHALLENGE; } Sleep(80); } std::string opt[] = {"挑战模式", "无尽模式", "DIY弹幕", "切换账号", "退出"}; int sel = 0;
while (true) { update_key(); clear_screen();
// 身份 + 最高分(必须在 clear_screen 之后、每次循环都打印) set_color(COLOR_INFO); if (cur_user.empty()) std::cout << "当前身份:游客\n"; else std::cout << "当前身份:" << cur_user << "\n"; std::cout << "无尽最高分:简单 " << best_endless[0] << " / 普通 " << best_endless[1] << " / 困难 " << best_endless[2] << "\n"; std::cout << "挑战最高分:" << best_challenge << "\n\n"; reset_color();
set_color(COLOR_TITLE); std::cout << "=====================\n" << " 控制台弹幕游戏\n" << "=====================\n\n" << std::flush; reset_color(); std::cout << "↑ ↓ 选择,回车确认\n\n";
for (int i = 0; i < 5; i++) { if (i == sel) { set_color(COLOR_PLAYER); std::cout << " > " << opt[i] << "\n"; } else { std::cout << " " << opt[i] << "\n"; } reset_color(); }
if (key[VK_UP] && !last_key[VK_UP]) sel = clamp(sel - 1, 0, 4); if (key[VK_DOWN] && !last_key[VK_DOWN]) sel = clamp(sel + 1, 0, 4);
if (key[VK_RETURN] && !last_key[VK_RETURN]) { if (sel == 0) return MODE_CHALLENGE; if (sel == 1) return MODE_ENDLESS; if (sel == 2) return MODE_DIY; if (sel == 3) { g_logout_request = true; return MODE_CHALLENGE; } if (sel == 4) exit(0); } if (key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { g_logout_request = true; return MODE_CHALLENGE; }
Sleep(80); }}
int main() { srand((unsigned)time(NULL)); build_stages(); CONSOLE_CURSOR_INFO info; info.dwSize = 1; info.bVisible = FALSE; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
float accumulator = 0.f; DWORD prev_tick = GetTickCount(); // 安全地设置窗口大小:先扩缓冲 → 缩窗口 → 缩缓冲 { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(hConsole, &csbi); SHORT tw = (SHORT)(W + 6); SHORT th = (SHORT)(H + 12); if (csbi.dwSize.X < tw || csbi.dwSize.Y < th) { COORD big; big.X = csbi.dwSize.X > tw ? csbi.dwSize.X : tw; big.Y = csbi.dwSize.Y > th ? csbi.dwSize.Y : th; SetConsoleScreenBufferSize(hConsole, big); } SMALL_RECT winRect = {0, 0, (SHORT)(tw - 1), (SHORT)(th - 1)}; SetConsoleWindowInfo(hConsole, TRUE, &winRect); COORD bufSize; bufSize.X = tw; bufSize.Y = th; SetConsoleScreenBufferSize(hConsole, bufSize); }
while(true) { std::string danfile; GameMode md = main_menu(); if(md == MODE_DIY) { danfile = select_dan_file(); if(danfile.empty()) continue; god_mode = select_god(); select_diff(); running = true; reset_game(md); load_danmaku(danfile); } else { god_mode = select_god(); select_diff(); running = true; reset_game(md); } srand((unsigned)time(NULL)); build_builtin_stages();
accumulator = 0.f; prev_tick = GetTickCount(); CONSOLE_CURSOR_INFO info; info.dwSize = 1; info.bVisible = FALSE; SetConsoleCursorInfo(hConsole, &info);
while(running) { DWORD now_tick = GetTickCount(); float real_dt = (now_tick - prev_tick) / 1000.0f; prev_tick = now_tick; if(real_dt > 0.2f) real_dt = 0.2f; accumulator += real_dt; if(accumulator > 0.25f) accumulator = 0.25f; float accumulator = 0.f; DWORD prev_tick = GetTickCount();
update_key(); while (true) { int lg = login_screen(); if (lg == -1) break;
if(key['H'] && !last_key['H']) { if(overlay == OVERLAY_HELP) overlay = OVERLAY_NONE; else overlay = OVERLAY_HELP; } if(key[' '] && !last_key[' '] && overlay == OVERLAY_STORY) { overlay = OVERLAY_NONE; } if(key['R'] && !last_key['R']) { reset_game(gmode); if(gmode == MODE_DIY) { load_danmaku(danfile); } } if(key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { running = false; } load_save();
while(accumulator >= FIXED_DT) { if(overlay == OVERLAY_STORY) { overlay_timer -= FIXED_DT; if(overlay_timer <=0) overlay = OVERLAY_NONE; } if(!gameover && !win && overlay == OVERLAY_NONE) { game_timer += FIXED_DT; sc.add_tick(FIXED_DT, diff_rate); sc.tick(FIXED_DT); } spawn_logic(FIXED_DT); bullet_update(FIXED_DT); player_update(FIXED_DT); collision_and_graze_check(); accumulator -= FIXED_DT; } bool logout = false; while (!logout) { g_logout_request = false; std::string danfile; GameMode md = main_menu(); if (g_logout_request) { logout = true; break; }
render(); Sleep(FRAME_DELAY); } } reset_color(); return 0;} std::vector<DanStage> *use_list = nullptr; bool start_ok = false;
```附带一份谱子```test.danmaku// ============================================== //// 琪露诺 · 冰精之九// 总时长:195s(3分15秒),弹幕总数 >700// 弹幕类型:circle / fan / spiral / aim / delay / bounce / line============================================== // if (md == MODE_DIY) { danfile = select_dan_file(); if (danfile.empty()) continue; load_danmaku(danfile, diy_stage_list); if (diy_stage_list.empty()) continue; use_list = &diy_stage_list; god_mode = select_god(); select_diff(); reset_game(md); cur_stage_idx = 0; if (!preview_stage((*use_list)[cur_stage_idx])) continue; enter_stage(0, *use_list); start_ok = true; } else if (md == MODE_CHALLENGE) { use_list = &dan_stage_list; god_mode = select_god(); select_diff(); reset_game(md); cur_stage_idx = 0; if (!preview_stage((*use_list)[cur_stage_idx])) continue; enter_stage(0, *use_list); start_ok = true; } else if (md == MODE_ENDLESS) { use_list = nullptr; god_mode = select_god(); select_diff(); reset_game(md); start_ok = true; } if (!start_ok) continue;
// ---------- PHASE 1 开场冰雾 0~25s ----------1.00 32 6 circle 162.20 32 6 circle 183.40 32 6 fan 12 70 1804.10 10 7 aim4.10 54 7 aim5.30 32 6 circle 206.50 32 6 fan 14 80 1807.20 16 7 aim7.20 48 7 aim8.40 32 6 circle 229.60 32 6 fan 14 85 18010.30 8 7 aim10.30 56 7 aim11.50 32 6 circle 2412.70 32 6 fan 16 90 18013.40 20 7 aim13.40 44 7 aim14.60 32 6 circle 2415.80 32 6 fan 16 90 18016.50 12 7 aim16.50 52 7 aim17.70 32 6 circle 2618.90 32 6 fan 18 95 18019.60 24 7 aim19.60 40 7 aim20.80 32 6 circle 2622.00 32 6 fan 18 95 18023.20 32 6 circle 2824.40 32 6 fan 20 100 180 running = true; accumulator = 0.f; prev_tick = GetTickCount();
// ---------- PHASE 2 环冰阵 25~55s ----------25.00 32 6 circle 2826.00 12 6 circle 1226.00 52 6 circle 1227.00 32 6 circle 3028.00 16 6 circle 1228.00 48 6 circle 1229.00 32 6 circle 3030.00 20 6 circle 1430.00 44 6 circle 1431.00 32 6 circle 3232.00 8 6 circle 1432.00 56 6 circle 1433.00 32 6 circle 3234.00 24 6 circle 1434.00 40 6 circle 1435.00 32 6 circle 3436.00 12 6 circle 1636.00 52 6 circle 1637.00 32 6 circle 3438.00 16 6 circle 1638.00 48 6 circle 1639.00 32 6 circle 3640.00 20 6 circle 1640.00 44 6 circle 1641.00 32 6 circle 3642.00 8 6 circle 1842.00 56 6 circle 1843.00 32 6 circle 3844.00 24 6 circle 1844.00 40 6 circle 1845.00 32 6 circle 3846.00 12 6 circle 1846.00 52 6 circle 1847.00 32 6 circle 4048.00 16 6 circle 2048.00 48 6 circle 2049.00 32 6 circle 4050.00 20 6 circle 2050.00 44 6 circle 2051.00 32 6 circle 4252.00 8 6 circle 2052.00 56 6 circle 2053.00 32 6 circle 4254.00 24 6 circle 2254.00 40 6 circle 22 while (running) { DWORD now_tick = GetTickCount(); float real_dt = (now_tick - prev_tick) / 1000.0f; prev_tick = now_tick; if (real_dt > 0.2f) real_dt = 0.2f; accumulator += real_dt; if (accumulator > 0.25f) accumulator = 0.25f;
// ---------- PHASE3 冰扇交错 55~85s ----------55.00 32 6 fan 20 110 18056.20 10 6 fan 12 70 18056.20 54 6 fan 12 70 18057.40 32 6 fan 22 115 18058.60 14 6 fan 12 75 18058.60 50 6 fan 12 75 18059.80 32 6 fan 22 115 18061.00 18 6 fan 14 75 18061.00 46 6 fan 14 75 18062.20 32 6 fan 24 120 18063.40 22 6 fan 14 80 18063.40 42 6 fan 14 80 18064.60 32 6 fan 24 120 18065.80 8 6 fan 14 80 18065.80 56 6 fan 14 80 18067.00 32 6 fan 26 125 18068.20 12 6 fan 16 85 18068.20 52 6 fan 16 85 18069.40 32 6 fan 26 125 18070.60 16 6 fan 16 85 18070.60 48 6 fan 16 85 18071.80 32 6 fan 28 130 18073.00 20 6 fan 16 90 18073.00 44 6 fan 16 90 18074.20 32 6 fan 28 130 18075.40 24 6 fan 18 90 18075.40 40 6 fan 18 90 18076.60 32 6 fan 30 135 18077.80 10 6 fan 18 95 18077.80 54 6 fan 18 95 18079.00 32 6 fan 30 135 18080.20 14 6 fan 18 95 18080.20 50 6 fan 18 95 18081.40 32 6 fan 32 140 18082.60 18 6 fan 20 100 18082.60 46 6 fan 20 100 18083.80 32 6 fan 32 140 180 update_key();
// ---------- PHASE4 冰螺旋 85~115s ----------85.00 32 6 spiral 286.50 10 6 spiral 286.50 54 6 spiral 288.00 32 6 spiral 289.50 14 6 spiral 289.50 50 6 spiral 291.00 32 6 spiral 292.50 18 6 spiral 292.50 46 6 spiral 294.00 32 6 spiral 295.50 22 6 spiral 295.50 42 6 spiral 297.00 32 6 spiral 298.50 8 6 spiral 298.50 56 6 spiral 2100.00 32 6 spiral 2101.50 12 6 spiral 2101.50 52 6 spiral 2103.00 32 6 spiral 2104.50 16 6 spiral 2104.50 48 6 spiral 2106.00 32 6 spiral 2107.50 20 6 spiral 2107.50 44 6 spiral 2109.00 32 6 spiral 2110.50 24 6 spiral 2110.50 40 6 spiral 2112.00 32 6 spiral 2113.50 10 6 spiral 2113.50 54 6 spiral 2 // ---------- 全局快捷键(剧情期间禁用会冲突的键) ---------- if (key[VK_ESCAPE] && !last_key[VK_ESCAPE]) { if (overlay == OVERLAY_NONE) { overlay = OVERLAY_PAUSE; clear_screen(); } else if (overlay == OVERLAY_PAUSE) { overlay = OVERLAY_NONE; clear_screen(); } }
// ---------- PHASE5 滞留冰狙 115~145s ----------115.00 32 6 delay 180 1.2116.00 12 6 aim116.00 52 6 aim117.00 32 6 delay 170 1.2118.00 16 6 aim118.00 48 6 aim119.00 32 6 delay 190 1.2120.00 20 6 aim120.00 44 6 aim121.00 32 6 delay 160 1.2122.00 24 6 aim122.00 40 6 aim123.00 32 6 delay 200 1.2124.00 8 6 aim124.00 56 6 aim125.00 32 6 delay 150 1.2126.00 14 6 aim126.00 50 6 aim127.00 32 6 delay 210 1.2128.00 18 6 aim128.00 46 6 aim129.00 32 6 delay 140 1.2130.00 22 6 aim130.00 42 6 aim131.00 32 6 delay 220 1.2132.00 10 6 aim132.00 54 6 aim133.00 32 6 delay 130 1.2134.00 12 6 aim134.00 52 6 aim135.00 32 6 delay 230 1.2136.00 16 6 aim136.00 48 6 aim137.00 32 6 delay 120 1.2138.00 20 6 aim138.00 44 6 aim139.00 32 6 delay 240 1.2140.00 24 6 aim140.00 40 6 aim141.00 32 6 delay 110 1.2142.00 8 6 aim142.00 56 6 aim143.00 32 6 delay 250 1.2 if (overlay != OVERLAY_STORY && overlay != OVERLAY_CLEARWAIT && overlay != OVERLAY_PAUSE && overlay != OVERLAY_DEAD && overlay != OVERLAY_GAMEOVER) { if (key['H'] && !last_key['H']) { overlay = (overlay == OVERLAY_HELP) ? OVERLAY_NONE : OVERLAY_HELP; clear_screen(); } if (key['R'] && !last_key['R']) { reset_game(gmode); if (gmode == MODE_CHALLENGE) { cur_stage_idx = 0; enter_stage(0, dan_stage_list); } else if (gmode == MODE_DIY) { cur_stage_idx = 0; enter_stage(0, diy_stage_list); } accumulator = 0.f; clear_screen(); } }
// ---------- PHASE6 反弹冰刃 145~170s ----------145.00 10 7 bounce 45 3145.00 54 7 bounce 135 3146.20 14 7 bounce 50 3146.20 50 7 bounce 130 3147.40 18 7 bounce 55 3147.40 46 7 bounce 125 3148.60 22 7 bounce 60 3148.60 42 7 bounce 120 3149.80 8 7 bounce 40 3149.80 56 7 bounce 140 3151.00 12 7 bounce 65 3151.00 52 7 bounce 115 3152.20 16 7 bounce 70 3152.20 48 7 bounce 110 3153.40 20 7 bounce 75 3153.40 44 7 bounce 105 3154.60 24 7 bounce 80 3154.60 40 7 bounce 100 3155.80 10 7 bounce 35 3155.80 54 7 bounce 145 3157.00 14 7 bounce 85 3157.00 50 7 bounce 95 3158.20 18 7 bounce 30 3158.20 46 7 bounce 150 3159.40 22 7 bounce 90 3159.40 42 7 bounce 90 3160.60 8 7 bounce 25 3160.60 56 7 bounce 155 3161.80 12 7 bounce 95 3161.80 52 7 bounce 85 3163.00 16 7 bounce 20 3163.00 48 7 bounce 160 3164.20 20 7 bounce 100 3164.20 44 7 bounce 80 3165.40 24 7 bounce 15 3165.40 40 7 bounce 165 3166.60 10 7 bounce 105 3166.60 54 7 bounce 75 3167.80 14 7 bounce 10 3167.80 50 7 bounce 170 3 // ---------- 剧情状态:独立处理,不推进游戏时间 ---------- if (overlay == OVERLAY_STORY) { accumulator = 0.f; // 剧情期间彻底冻结游戏时钟 dlg.update(real_dt); // 打字机按真实时间推进
// ---------- FINAL 终符:「冰瀑九重天」170~195s 高密度混合【大量穿插】 ----------170.00 32 6 circle 44170.20 14 6 aim170.20 50 6 aim170.50 32 6 fan 34 145 180170.70 32 6 spiral 2171.00 32 6 delay 180 1.0171.50 12 6 aim171.50 52 6 aim171.80 18 7 bounce 40 2171.80 46 7 bounce 140 2172.00 32 6 circle 44172.30 32 6 fan 34 145 180172.50 16 7 bounce 45 2172.50 48 7 bounce 135 2172.70 32 6 spiral 2173.00 20 6 aim173.00 44 6 aim if (key['X'] && !last_key['X']) dlg.fast_forward();
173.50 32 6 circle 44173.70 24 6 aim173.70 40 6 aim174.00 32 6 fan 34 145 180174.20 32 6 delay 180 1.0174.50 32 6 spiral 2174.80 8 7 bounce 50 2174.80 56 7 bounce 130 2175.00 16 6 aim175.00 48 6 aim175.30 12 7 bounce 52 2175.30 52 7 bounce 128 2175.50 32 6 delay 180 1.0176.00 20 7 bounce 50 2176.00 44 7 bounce 130 2 if (key['C'] && !last_key['C']) { // 允许随时翻页(即使没打完),也可改成 if (dlg.page_done()) if (!dlg.next_page()) { overlay = OVERLAY_NONE; dlg.stop(); clear_screen(); // 干净地回到游戏画面 } }
177.00 32 6 circle 46177.20 18 6 aim177.20 46 6 aim177.50 32 6 fan 36 150 180177.70 32 6 spiral 2178.00 14 7 bounce 54 2178.00 50 7 bounce 126 2178.50 20 6 aim178.50 44 6 aim178.80 32 6 delay 180 1.0179.00 24 7 bounce 55 2179.00 40 7 bounce 125 2179.30 10 6 aim179.30 54 6 aim if (use_list) render(*use_list); else render(dan_stage_list); Sleep(FRAME_DELAY); continue; // 跳过一切游戏逻辑 }
180.50 32 6 circle 46180.70 16 7 bounce 58 2180.70 48 7 bounce 122 2181.00 32 6 fan 36 150 180181.20 32 6 spiral 2181.50 22 6 aim181.50 42 6 aim181.80 32 6 delay 180 1.0182.00 24 6 aim182.00 40 6 aim182.30 14 7 bounce 60 2182.30 50 7 bounce 120 2183.00 8 7 bounce 60 2183.00 56 7 bounce 120 2 // ---------- 暂停 ---------- if (overlay == OVERLAY_PAUSE) { accumulator = 0.f; if (key['1'] && !last_key['1']) { overlay = OVERLAY_NONE; clear_screen(); } if (key['2'] && !last_key['2']) { reset_game(gmode); if (gmode == MODE_CHALLENGE) { cur_stage_idx = 0; enter_stage(0, dan_stage_list); } else if (gmode == MODE_DIY) { cur_stage_idx = 0; enter_stage(0, diy_stage_list); } accumulator = 0.f; clear_screen(); } if (key['3'] && !last_key['3']) { update_best(); save_game(); running = false; break; }
184.00 32 6 circle 48184.20 20 6 aim184.20 44 6 aim184.50 32 6 fan 38 155 180184.70 32 6 spiral 2185.00 18 7 bounce 62 2185.00 46 7 bounce 118 2185.50 8 6 aim185.50 56 6 aim185.80 32 6 delay 180 1.0186.00 22 7 bounce 64 2186.00 42 7 bounce 116 2186.30 12 6 aim186.30 52 6 aim186.50 12 7 bounce 65 2186.50 52 7 bounce 115 2 if (use_list) render(*use_list); else render(dan_stage_list); Sleep(80); continue; }
187.50 32 6 circle 48187.70 24 6 aim187.70 40 6 aim188.00 32 6 fan 38 155 180188.20 32 6 spiral 2188.50 16 7 bounce 68 2188.50 48 7 bounce 112 2189.00 12 6 aim189.00 52 6 aim189.30 32 6 delay 180 1.0189.50 20 7 bounce 70 2189.50 44 7 bounce 110 2189.80 14 6 aim189.80 50 6 aim // ---------- 死亡续命 ---------- if (overlay == OVERLAY_DEAD) { accumulator = 0.f; unsigned long long cost = get_revive_cost();
191.00 32 6 circle 50191.20 18 6 aim191.20 46 6 aim191.50 32 6 fan 40 160 180191.70 32 6 spiral 2192.00 22 7 bounce 72 2192.00 42 7 bounce 108 2192.50 16 6 aim192.50 48 6 aim192.80 32 6 delay 180 1.0193.00 20 7 bounce 75 2193.00 44 7 bounce 105 2193.30 10 6 aim193.30 54 6 aim if (key['1'] && !last_key['1']) { gameover = true; overlay = OVERLAY_GAMEOVER; update_best(); save_game(); clear_screen(); } else if (key['2'] && !last_key['2']) { if (revive_count < REVIVE_MAX && sc.score >= cost) { sc.score -= cost; revive_count++; pl.hp = 1; pl.invincible = 3.0f; sc.hurt(); bullets.clear(); pl.x = W / 2.f; pl.y = H - 6.f; overlay = OVERLAY_NONE; accumulator = 0.f; clear_screen(); } }
194.50 32 6 circle 50194.70 14 7 bounce 78 2194.70 50 7 bounce 102 2195.00 32 6 fan 40 160 180 if (use_list) render(*use_list); else render(dan_stage_list); Sleep(80); continue; }
// ---------- 结束/通关菜单 ---------- if (overlay == OVERLAY_GAMEOVER || win) { accumulator = 0.f;
if (key['1'] && !last_key['1']) { reset_game(gmode); if (gmode == MODE_CHALLENGE) { cur_stage_idx = 0; enter_stage(0, dan_stage_list); } else if (gmode == MODE_DIY) { cur_stage_idx = 0; enter_stage(0, diy_stage_list); } accumulator = 0.f; clear_screen(); } if (key['2'] && !last_key['2']) { running = false; break; }
if (use_list) render(*use_list); else render(dan_stage_list); Sleep(80); continue; }
// ---------- 正常游戏 ---------- if (accumulator > 0.25f) accumulator = 0.25f;
if (key['C'] && !last_key['C'] && overlay == OVERLAY_CLEARWAIT && use_list != nullptr) { cur_stage_idx++; if (cur_stage_idx >= (int)use_list->size()) { win = true; overlay = OVERLAY_GAMEOVER; update_best(); save_game(); } else { if (!preview_stage((*use_list)[cur_stage_idx])) { running = false; break; } enter_stage(cur_stage_idx, *use_list); } }
while (accumulator >= FIXED_DT) { if (!gameover && !win && overlay == OVERLAY_NONE) { game_timer += FIXED_DT; sc.add_tick(FIXED_DT, diff_rate); sc.tick(FIXED_DT); } spawn_logic(FIXED_DT, use_list ? *use_list : dan_stage_list); bullet_update(FIXED_DT); player_update(FIXED_DT); collision_and_graze_check(); accumulator -= FIXED_DT; }
if (use_list) render(*use_list); else render(dan_stage_list); Sleep(FRAME_DELAY); } if (g_logout_request) { logout = true; } } // while(!logout) } // while(true)
reset_color(); return 0;}```附带谱子(ANSI编码,.danmaku文件)```danmakustagename "反弹子+龙骨炮"page "无伤就可以出新手村了"diff 0.5base_speed 2.0note 0.5 32 4 bounce rand 30note 1.0 8 6 bounce rand 30note 1.5 55 5 bounce rand 30note 2.0 20 8 bounce rand 30note 2.0 4 2 blaster_aim 0.7 0.4 45note 2.5 44 3 bounce rand 30note 3.0 12 7 bounce rand 30note 3.5 50 6 bounce rand 20note 4.0 28 5 bounce rand 30note 4.0 60 2 blaster_aim 0.7 0.4 45note 4.5 60 8 bounce rand 30note 5.0 16 4 bounce rand 20note 5.5 38 6 bounce rand 30note 6.0 6 5 bounce rand 30note 6.0 4 2 blaster_aim 0.6 0.4 50note 6.5 52 7 bounce rand 20note 7.0 24 3 bounce rand 30note 7.5 46 8 bounce rand 30note 8.0 10 6 bounce rand 20note 8.0 60 2 blaster_aim 0.6 0.4 50note 8.5 34 4 bounce rand 30note 9.0 58 5 bounce rand 30note 9.5 18 7 bounce rand 20note 10.0 40 6 bounce rand 30note 10.0 32 2 blaster_aim 0.5 0.5 55}```