#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <windows.h>
const int W = 64;
const int H = 32;
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 FIXED_DT = 1.0f / 60.0f;
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 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;
const float BULLET_BASE_SPEED = 20.f;
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 int CIRCLE_MIN_CNT = 12;
const int CIRCLE_RAND_ADD = 10;
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;
const float SCORE_BASE = 10.0f;
const float GRAZE_SCORE = 25.0f;
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;
}
void set_color(int c) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
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;
}
}
enum BulletType {
B_LINE,
B_AIM,
B_CIRCLE,
B_FAN,
B_SPIRAL,
B_BOUNCE,
B_ACCEL,
B_DELAY
};
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;
};
struct NoteEvent {
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;
};
enum GameMode {
MODE_CHALLENGE,
MODE_ENDLESS,
MODE_DIY
};
enum OverlayState {
OVERLAY_NONE,
OVERLAY_HELP,
OVERLAY_STORY
};
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;
}
};
struct Player {
float x, y;
int hp;
int max_hp;
float invincible;
};
std::vector<Bullet> bullets;
std::vector<NoteEvent> note_list;
std::vector<Stage> stage_list;
ScoreMgr sc;
Player pl;
GameMode gmode;
OverlayState overlay = OVERLAY_NONE;
float overlay_timer = 0.f;
int cur_stage = 0;
int note_ptr = 0;
float game_timer;
bool running;
bool gameover;
bool win;
float spawn_t;
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 '*';
}
}
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;
}
}
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;
}
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";
}
}
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);
}
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);
}
//【评审修复】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);
}
}
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;
}
}
static std::string tolower_str(std::string s) {
for(auto &ch : 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;
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);
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);
}
struct DirItem {
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::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";
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;
}
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);
}
}
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(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;
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;
}
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;
}
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 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] = '|';
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;
}
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;
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";
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";
}
}
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);
}
}
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);
}
}
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);
}
}
int main() {
srand((unsigned)time(NULL));
build_stages();
CONSOLE_CURSOR_INFO info;
info.dwSize = 1;
info.bVisible = FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
float accumulator = 0.f;
DWORD prev_tick = GetTickCount();
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);
}
accumulator = 0.f;
prev_tick = GetTickCount();
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;
update_key();
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;
}
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;
}
render();
Sleep(FRAME_DELAY);
}
}
reset_color();
return 0;
}
附带一份谱子
// ============================================== //
// 琪露诺 · 冰精之九
// 总时长:195s(3分15秒),弹幕总数 >700
// 弹幕类型:circle / fan / spiral / aim / delay / bounce / line============================================== //
// ---------- PHASE 1 开场冰雾 0~25s ----------
1.00 32 6 circle 16
2.20 32 6 circle 18
3.40 32 6 fan 12 70 180
4.10 10 7 aim
4.10 54 7 aim
5.30 32 6 circle 20
6.50 32 6 fan 14 80 180
7.20 16 7 aim
7.20 48 7 aim
8.40 32 6 circle 22
9.60 32 6 fan 14 85 180
10.30 8 7 aim
10.30 56 7 aim
11.50 32 6 circle 24
12.70 32 6 fan 16 90 180
13.40 20 7 aim
13.40 44 7 aim
14.60 32 6 circle 24
15.80 32 6 fan 16 90 180
16.50 12 7 aim
16.50 52 7 aim
17.70 32 6 circle 26
18.90 32 6 fan 18 95 180
19.60 24 7 aim
19.60 40 7 aim
20.80 32 6 circle 26
22.00 32 6 fan 18 95 180
23.20 32 6 circle 28
24.40 32 6 fan 20 100 180
// ---------- PHASE 2 环冰阵 25~55s ----------
25.00 32 6 circle 28
26.00 12 6 circle 12
26.00 52 6 circle 12
27.00 32 6 circle 30
28.00 16 6 circle 12
28.00 48 6 circle 12
29.00 32 6 circle 30
30.00 20 6 circle 14
30.00 44 6 circle 14
31.00 32 6 circle 32
32.00 8 6 circle 14
32.00 56 6 circle 14
33.00 32 6 circle 32
34.00 24 6 circle 14
34.00 40 6 circle 14
35.00 32 6 circle 34
36.00 12 6 circle 16
36.00 52 6 circle 16
37.00 32 6 circle 34
38.00 16 6 circle 16
38.00 48 6 circle 16
39.00 32 6 circle 36
40.00 20 6 circle 16
40.00 44 6 circle 16
41.00 32 6 circle 36
42.00 8 6 circle 18
42.00 56 6 circle 18
43.00 32 6 circle 38
44.00 24 6 circle 18
44.00 40 6 circle 18
45.00 32 6 circle 38
46.00 12 6 circle 18
46.00 52 6 circle 18
47.00 32 6 circle 40
48.00 16 6 circle 20
48.00 48 6 circle 20
49.00 32 6 circle 40
50.00 20 6 circle 20
50.00 44 6 circle 20
51.00 32 6 circle 42
52.00 8 6 circle 20
52.00 56 6 circle 20
53.00 32 6 circle 42
54.00 24 6 circle 22
54.00 40 6 circle 22
// ---------- PHASE3 冰扇交错 55~85s ----------
55.00 32 6 fan 20 110 180
56.20 10 6 fan 12 70 180
56.20 54 6 fan 12 70 180
57.40 32 6 fan 22 115 180
58.60 14 6 fan 12 75 180
58.60 50 6 fan 12 75 180
59.80 32 6 fan 22 115 180
61.00 18 6 fan 14 75 180
61.00 46 6 fan 14 75 180
62.20 32 6 fan 24 120 180
63.40 22 6 fan 14 80 180
63.40 42 6 fan 14 80 180
64.60 32 6 fan 24 120 180
65.80 8 6 fan 14 80 180
65.80 56 6 fan 14 80 180
67.00 32 6 fan 26 125 180
68.20 12 6 fan 16 85 180
68.20 52 6 fan 16 85 180
69.40 32 6 fan 26 125 180
70.60 16 6 fan 16 85 180
70.60 48 6 fan 16 85 180
71.80 32 6 fan 28 130 180
73.00 20 6 fan 16 90 180
73.00 44 6 fan 16 90 180
74.20 32 6 fan 28 130 180
75.40 24 6 fan 18 90 180
75.40 40 6 fan 18 90 180
76.60 32 6 fan 30 135 180
77.80 10 6 fan 18 95 180
77.80 54 6 fan 18 95 180
79.00 32 6 fan 30 135 180
80.20 14 6 fan 18 95 180
80.20 50 6 fan 18 95 180
81.40 32 6 fan 32 140 180
82.60 18 6 fan 20 100 180
82.60 46 6 fan 20 100 180
83.80 32 6 fan 32 140 180
// ---------- PHASE4 冰螺旋 85~115s ----------
85.00 32 6 spiral 2
86.50 10 6 spiral 2
86.50 54 6 spiral 2
88.00 32 6 spiral 2
89.50 14 6 spiral 2
89.50 50 6 spiral 2
91.00 32 6 spiral 2
92.50 18 6 spiral 2
92.50 46 6 spiral 2
94.00 32 6 spiral 2
95.50 22 6 spiral 2
95.50 42 6 spiral 2
97.00 32 6 spiral 2
98.50 8 6 spiral 2
98.50 56 6 spiral 2
100.00 32 6 spiral 2
101.50 12 6 spiral 2
101.50 52 6 spiral 2
103.00 32 6 spiral 2
104.50 16 6 spiral 2
104.50 48 6 spiral 2
106.00 32 6 spiral 2
107.50 20 6 spiral 2
107.50 44 6 spiral 2
109.00 32 6 spiral 2
110.50 24 6 spiral 2
110.50 40 6 spiral 2
112.00 32 6 spiral 2
113.50 10 6 spiral 2
113.50 54 6 spiral 2
// ---------- PHASE5 滞留冰狙 115~145s ----------
115.00 32 6 delay 180 1.2
116.00 12 6 aim
116.00 52 6 aim
117.00 32 6 delay 170 1.2
118.00 16 6 aim
118.00 48 6 aim
119.00 32 6 delay 190 1.2
120.00 20 6 aim
120.00 44 6 aim
121.00 32 6 delay 160 1.2
122.00 24 6 aim
122.00 40 6 aim
123.00 32 6 delay 200 1.2
124.00 8 6 aim
124.00 56 6 aim
125.00 32 6 delay 150 1.2
126.00 14 6 aim
126.00 50 6 aim
127.00 32 6 delay 210 1.2
128.00 18 6 aim
128.00 46 6 aim
129.00 32 6 delay 140 1.2
130.00 22 6 aim
130.00 42 6 aim
131.00 32 6 delay 220 1.2
132.00 10 6 aim
132.00 54 6 aim
133.00 32 6 delay 130 1.2
134.00 12 6 aim
134.00 52 6 aim
135.00 32 6 delay 230 1.2
136.00 16 6 aim
136.00 48 6 aim
137.00 32 6 delay 120 1.2
138.00 20 6 aim
138.00 44 6 aim
139.00 32 6 delay 240 1.2
140.00 24 6 aim
140.00 40 6 aim
141.00 32 6 delay 110 1.2
142.00 8 6 aim
142.00 56 6 aim
143.00 32 6 delay 250 1.2
// ---------- PHASE6 反弹冰刃 145~170s ----------
145.00 10 7 bounce 45 3
145.00 54 7 bounce 135 3
146.20 14 7 bounce 50 3
146.20 50 7 bounce 130 3
147.40 18 7 bounce 55 3
147.40 46 7 bounce 125 3
148.60 22 7 bounce 60 3
148.60 42 7 bounce 120 3
149.80 8 7 bounce 40 3
149.80 56 7 bounce 140 3
151.00 12 7 bounce 65 3
151.00 52 7 bounce 115 3
152.20 16 7 bounce 70 3
152.20 48 7 bounce 110 3
153.40 20 7 bounce 75 3
153.40 44 7 bounce 105 3
154.60 24 7 bounce 80 3
154.60 40 7 bounce 100 3
155.80 10 7 bounce 35 3
155.80 54 7 bounce 145 3
157.00 14 7 bounce 85 3
157.00 50 7 bounce 95 3
158.20 18 7 bounce 30 3
158.20 46 7 bounce 150 3
159.40 22 7 bounce 90 3
159.40 42 7 bounce 90 3
160.60 8 7 bounce 25 3
160.60 56 7 bounce 155 3
161.80 12 7 bounce 95 3
161.80 52 7 bounce 85 3
163.00 16 7 bounce 20 3
163.00 48 7 bounce 160 3
164.20 20 7 bounce 100 3
164.20 44 7 bounce 80 3
165.40 24 7 bounce 15 3
165.40 40 7 bounce 165 3
166.60 10 7 bounce 105 3
166.60 54 7 bounce 75 3
167.80 14 7 bounce 10 3
167.80 50 7 bounce 170 3
// ---------- FINAL 终符:「冰瀑九重天」170~195s 高密度混合【大量穿插】 ----------
170.00 32 6 circle 44
170.20 14 6 aim
170.20 50 6 aim
170.50 32 6 fan 34 145 180
170.70 32 6 spiral 2
171.00 32 6 delay 180 1.0
171.50 12 6 aim
171.50 52 6 aim
171.80 18 7 bounce 40 2
171.80 46 7 bounce 140 2
172.00 32 6 circle 44
172.30 32 6 fan 34 145 180
172.50 16 7 bounce 45 2
172.50 48 7 bounce 135 2
172.70 32 6 spiral 2
173.00 20 6 aim
173.00 44 6 aim
173.50 32 6 circle 44
173.70 24 6 aim
173.70 40 6 aim
174.00 32 6 fan 34 145 180
174.20 32 6 delay 180 1.0
174.50 32 6 spiral 2
174.80 8 7 bounce 50 2
174.80 56 7 bounce 130 2
175.00 16 6 aim
175.00 48 6 aim
175.30 12 7 bounce 52 2
175.30 52 7 bounce 128 2
175.50 32 6 delay 180 1.0
176.00 20 7 bounce 50 2
176.00 44 7 bounce 130 2
177.00 32 6 circle 46
177.20 18 6 aim
177.20 46 6 aim
177.50 32 6 fan 36 150 180
177.70 32 6 spiral 2
178.00 14 7 bounce 54 2
178.00 50 7 bounce 126 2
178.50 20 6 aim
178.50 44 6 aim
178.80 32 6 delay 180 1.0
179.00 24 7 bounce 55 2
179.00 40 7 bounce 125 2
179.30 10 6 aim
179.30 54 6 aim
180.50 32 6 circle 46
180.70 16 7 bounce 58 2
180.70 48 7 bounce 122 2
181.00 32 6 fan 36 150 180
181.20 32 6 spiral 2
181.50 22 6 aim
181.50 42 6 aim
181.80 32 6 delay 180 1.0
182.00 24 6 aim
182.00 40 6 aim
182.30 14 7 bounce 60 2
182.30 50 7 bounce 120 2
183.00 8 7 bounce 60 2
183.00 56 7 bounce 120 2
184.00 32 6 circle 48
184.20 20 6 aim
184.20 44 6 aim
184.50 32 6 fan 38 155 180
184.70 32 6 spiral 2
185.00 18 7 bounce 62 2
185.00 46 7 bounce 118 2
185.50 8 6 aim
185.50 56 6 aim
185.80 32 6 delay 180 1.0
186.00 22 7 bounce 64 2
186.00 42 7 bounce 116 2
186.30 12 6 aim
186.30 52 6 aim
186.50 12 7 bounce 65 2
186.50 52 7 bounce 115 2
187.50 32 6 circle 48
187.70 24 6 aim
187.70 40 6 aim
188.00 32 6 fan 38 155 180
188.20 32 6 spiral 2
188.50 16 7 bounce 68 2
188.50 48 7 bounce 112 2
189.00 12 6 aim
189.00 52 6 aim
189.30 32 6 delay 180 1.0
189.50 20 7 bounce 70 2
189.50 44 7 bounce 110 2
189.80 14 6 aim
189.80 50 6 aim
191.00 32 6 circle 50
191.20 18 6 aim
191.20 46 6 aim
191.50 32 6 fan 40 160 180
191.70 32 6 spiral 2
192.00 22 7 bounce 72 2
192.00 42 7 bounce 108 2
192.50 16 6 aim
192.50 48 6 aim
192.80 32 6 delay 180 1.0
193.00 20 7 bounce 75 2
193.00 44 7 bounce 105 2
193.30 10 6 aim
193.30 54 6 aim
194.50 32 6 circle 50
194.70 14 7 bounce 78 2
194.70 50 7 bounce 102 2
195.00 32 6 fan 40 160 180