版本比较
【C++/EasyX】飞机大战小游戏源码分享与讲解
正文
增加 1207 行删除 1183 行
20 行未改动2122232425252627282953 行未改动83848586878889909192938788899091929394959697989910010110210310410510697989910010110210310410510610710810911011111211011111211311411511611711811611711811912012112212312412512212312412512612712812913013113213313413512913013113213313413513613713813914014114214314414514613914014114214314414514614714814915015115215315015115215315415515615730 行未改动18818919019119219319419519619719819920020120220320420520620720820919219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122221721821922022322422522622722222322422522622722822923023123223323423523623723823924024124224324424524622822923023123223323423523623723823924024124224324424524624724824925025125225324824925025125225325425525425525625725825926026126225725826326426526026126226626726826926426526627027127227326826927027427527627727227327427527627827928028128228327827928428528628128228328428528728828929029129229329428929029129529629729829329429529930030130229729829930030130230330430530630730830330430530630730830931031131231331431531031131231631731831932032131632232331831932432532632132232332432532632732832933033133233333433533033133633733833333433934034133633733833934034134234234334434534634734834934434534634734834935035035135235335435535635735235335435535635735835935835936036136236336436536636136236336436536636736736836937037137237337436937037137237537637737837937437538038138237737837938038138238338338438538638738838939039139238738839339439539039139239339439539639739839940040140240340439639739839940040140240340440540640740840941041140640740840941041141241341441541641741841241341441541641741841942042142242342442542642742242342842943042542642742843143243343443543043143243343443543643743643743843944044144244344443944044144244344444544544644744844945045145244744844945045145245345445345445545645745845946046145645745845946046146246246346446546646746846946446547047147246746846947047347447547647747247347847948047547647747847948048148248148248348448548648748848948448548648748848949049149049149249349449549649749849349449549649749849950049950050150250350450550650750250350450550650750850850951051151251351451551051151651751851351451551952052152251751851952052152252352452552652752852952452552652752852953053053153253353453553653753853953453554054154253753853954054154254354454554654754854955055155255355455555655755855956056156256354354454554654754854955055155255355455555655755855956056156256356456556656756856957057157256756857357457557057157257357657757857958057557657757857958058158258358458558658758858959059159258158258358458558658758858959059159259359459559659759859959459559659759859960060160060160260360460560660760860961060560660760860961061161261361461161261361461561661761861962062161661761861962062162262362462562662762862963062262362462562662762862963063163263363463563663763863964063563663763863964064164264364464564664764864965064164264364464564664764864965065165265365465565665765865965465565665765865966066166266366466566066166266366466566666766866967067167267367466967067167267367467567667767867968068168267567667767867968068168268368468568668768868969069168668768868969069169269369269369469569669769869970069569669769869970070170270370470170270370470570670770870971071171271370870971471571671171271371771871972071571671771871972172272372472572672172272372472572772872973073173272772872973373473573673173273373473573673773873973773873974074174274374474574674774874374474574674975075175275374874975075175275375475575675775875976075575675775875976076176276376476576676776876176276376476576676776876977077177277377477577077177277377477577677677777877978078178278377877978478578678178278778878978478578678778878979079179279379479079179279379479579679779879980080179679779879980080180280380480580280380480580680780880981081181280780881381481581081181281381481581681781881982082182281781881982082182282382482582682782882982482582682782882983083183283383483583683183283383483583683783883984084184284383883984084184284384484584684784884985084584684784884985085185185285385485585685785885385485986086185685786286386485986086186286386586686786886987086586686786886987087187287387187287387487587687787887988087588188288388487988588688788888388488588989089189289389488989089189289389489589589689789889990090190289790390489990090190290390490590690790890991091191291391491591691791891992090590690790890991091191291391491591691791891992092192292392492592692792292392492592692792892993093193293392892993093193293393493593693793893994093593693793893994094194294394494594694794894995095195295395495595695795894194294394494594694794894995095195295395495595695795895996096196296396496596096196296396496596696796896997097197297397497597696696796896997097197297397497597697797897998098198298398498598098198298398698798898999098598698798898999099199299399499199299399499599699799899910001001996997998999100010011002100310041005100610071008100310041005100610071009101010111012101310141009101010111012101310141015101610171018101910201021102210231015101610171018101910201021102210231024102510261027102810291030102510261027102810291030103110321033103410351036103710321033103410351036103710381039104010411042104310441045104610471048103810391040104110421043104410451046104710481049105010511052105310541055105010511052105310541055105610571058105910601061106210631064106510661067105610571058105910601061106210631064106510661067106810691070107110721073107410691070107110721075107610771078107910741075107610771078107910801081108210831084108510861081108210831087108810891090108510861087109110921093109410891095109610911092109310941095109610971098109911001101110211031097109810991100110111021103110411051106110711081109111011051106110711081109111011111112111311141115111611171118111911201121111111121113111411151116111711181119112011211122112311241125112611271128112311241125112611271128112911301131113211291130113111321133113411351136113711381139113411351136113711381139114011401141114211431144114511461147114211431144114811491150115111461147114811491150115111521153115411551156115711581153115911601155115611571161116211631164115911601161116511661167116811631164116911701171116611671172117311741169117011711172117311741175117611771178117911801181117611771178117911801181118211831184118511861187118811821183118411851186118711881189119011911192119311941195119011911192119311941195119611971198119912001201120212031204120512061196119711981199120012011202120312041205120612071208120912101211121212131208121412151210121112121213121412151216121712181219122012211222122312241225122612271228122912301216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123212331234123512361237123812391240124112421243124412381239124012411242124312441245124612471248124912501251124612471248124912501251125212531252125312541255125612571258125912601255125612571258125912601261126212631264126112621263126412651266126712681269127012711266126712681269127012721273127412751276127712721273127412751276127712781279128012811282128312841285128612871278127912801281128212831284128512861287128812891290129112921293129412951290129112921293129412951296129712981296129712981299130013011302130313041305130013011302130313041306130713081309131013111306130713121313131413091310131513161317131213181319131413151316131713181319132013211322132013211322132313241325132613271328132913301325132613271328132913301331133113321333133413351336133713381339134013411342133313341335134313441345134613371338133913471348134913501341134213511352135313441345134613471348135413551356135713581359135013511352135313541360136113621363136413651356136613671358135913601361136213681369137013711372137313641365136613671368136913701371137213731374137513741375137613771378137913801381138213831384138513861377137813791380138113821387138813891390139113921393138413941395138613871388139613971398139913901391139213931394139513961397139813991400140114021403140414051406140714081409141014011402140314041405141114121413141414151416140714171418140914101411141914201421142214131414141514161417141814191420142114231424142514261427142814291430143114321423142414251426142714281429143014311432143314331434143514361437143814391440144114421443144414351436143714381445144614471448144914401441144214431444144514461447144814491450145114521453145414551456145714501451145214531454145514561457145814591460146114621463146414651466146714681459146014611462146314641465146914701471147214731474147514761467146814691470147114721473147714781479148014811482148314841475147614771478147914801481148214831485148614871488148914901491149214931494148514951496149714981489149915001491149214931494149514961497149814991500150115021503150415051506150715081509151015111512150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231514151515161517151815191520152115221523152415251526152715281529153015311532153315341524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156420 行未改动+ 激光 (Z键):发射一道贯穿屏幕的激光,持续对敌人造成伤害。
+ 狂暴模式 (X键):短时间内大幅提升攻击力,并进入狂暴状态。
+ 追踪导弹 (H键):一次性发射 5 枚自动追踪敌人的导弹。+ 追踪导弹 (H键):发射 1 枚自动追踪敌人的导弹。
+ 散射子弹 (G键):发射扇形扩散的子弹,覆盖更大范围。
+ 动态难度与成长系统:随着得分增加,游戏等级提升,敌人变得更强大,同时玩家的基础攻击力也会增长。击杀敌人会获得技能能量,用于释放技能。53 行未改动enum { ENEMY_NORMAL, ENEMY_BOSS };enum { BULLET_NORMAL, BULLET_HOMING, BULLET_SPREAD };
struct Bullet { int x, y; bool live; int shooterType; int direction; int type; int targetEnemyIndex; double angle; int x, y; bool live; int shooterType; int direction; int type; int targetEnemyIndex; double angle;};
struct Enemy { int x, y; bool live; int hp; int initialHp; int type; int width, height; int laserTimer; bool isFiringLaser; int targetX; int shootTimer; int x, y; bool live; int hp; int initialHp; int type; int width, height; int laserTimer; bool isFiringLaser; int targetX; int shootTimer;};
struct Plane { int x, y; int hp; int maxHp; int x, y; int hp; int maxHp;};
struct PowerUp { int x, y; bool live; int type; int x, y; bool live; int type;};
struct Explosion { int x, y; bool active; int frame; int maxFrame; int x, y; bool active; int frame; int maxFrame;};
struct Particle { int x, y; double vx, vy; int life; int color; bool active; int type; double size; int x, y; double vx, vy; int life; int color; bool active; int type; double size;};
struct SkillSystem { double bombEnergy; double laserEnergy; double rageEnergy; double homingMissileEnergy; double spreadShotEnergy; bool rageActive; int rageTimer; double originalDamage; double bombEnergy; double laserEnergy; double rageEnergy; double homingMissileEnergy; double spreadShotEnergy; bool rageActive; int rageTimer; double originalDamage;};
struct Achievement { const char* name; const char* desc; bool unlocked; function<bool()> checkCondition; const char* name; const char* desc; bool unlocked; function<bool()> checkCondition;};
Plane p;Bullet b[MAX_BULLETS];30 行未改动char bossWarningText[100] = "";int bossWarningTimer = 0;
vector<Achievement> achievements = { { "First Blood", "Kill your first enemy", false, []() { return sc >= 5; } }, { "Combo Master", "Achieve a 10x combo", false, []() { return combo >= 10; } }, { "Boss Slayer", "Defeat a boss", false, []() { return sc >= 1000; } } { "First Blood", "Kill your first enemy", false, []() { return sc >= 5; } }, { "Combo Master", "Achieve a 10x combo", false, []() { return combo >= 10; } }, { "Boss Slayer", "Defeat a boss", false, []() { return sc >= 1000; } }};
int highScore = 0;
vector<int> cityBuildingHeights;
void InitGame() { p.x = W / 2 - 10; p.y = H - 80; p.hp = 10; p.maxHp = 10; p.x = W / 2 - 10; p.y = H - 80; p.hp = 10; p.maxHp = 10;
for (int i = 0; i < MAX_BULLETS; i++) { b[i].live = false; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_NORMAL; b[i].targetEnemyIndex = -1; b[i].angle = 0.0; } for (int i = 0; i < MAX_ENEMIES; i++) { e[i].live = false; e[i].type = ENEMY_NORMAL; e[i].width = 30; e[i].height = 30; e[i].laserTimer = 0; e[i].isFiringLaser = false; e[i].targetX = 0; e[i].shootTimer = 0; } for (int i = 0; i < MAX_POWERUPS; i++) pu[i].live = false; for (int i = 0; i < MAX_EXPLOSIONS; i++) pxe[i].active = false; for (int i = 0; i < MAX_PARTICLES; i++) { particles[i].active = false; particles[i].type = PARTICLE_EXPLOSION; particles[i].size = 2.0; } for (int i = 0; i < MAX_BULLETS; i++) { b[i].live = false; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_NORMAL; b[i].targetEnemyIndex = -1; b[i].angle = 0.0; } for (int i = 0; i < MAX_ENEMIES; i++) { e[i].live = false; e[i].type = ENEMY_NORMAL; e[i].width = 30; e[i].height = 30; e[i].laserTimer = 0; e[i].isFiringLaser = false; e[i].targetX = 0; e[i].shootTimer = 0; } for (int i = 0; i < MAX_POWERUPS; i++) pu[i].live = false; for (int i = 0; i < MAX_EXPLOSIONS; i++) pxe[i].active = false; for (int i = 0; i < MAX_PARTICLES; i++) { particles[i].active = false; particles[i].type = PARTICLE_EXPLOSION; particles[i].size = 2.0; }
skills.bombEnergy = 0.0; skills.laserEnergy = 0.0; skills.rageEnergy = 0.0; skills.homingMissileEnergy = 0.0; skills.spreadShotEnergy = 0.0; skills.rageActive = false; skills.rageTimer = 0; skills.originalDamage = shanghai; skills.bombEnergy = 0.0; skills.laserEnergy = 0.0; skills.rageEnergy = 0.0; skills.homingMissileEnergy = 0.0; skills.spreadShotEnergy = 0.0; skills.rageActive = false; skills.rageTimer = 0; skills.originalDamage = shanghai;
laserActive = false; laserTimer = 0; laserActive = false; laserTimer = 0;
bombShockwaveActive = false; shockwaveRadius = 0; shockwaveAge = 0; bombShockwaveActive = false; shockwaveRadius = 0; shockwaveAge = 0;
screenShakeTimer = 0; screenShakeOffsetX = 0; screenShakeOffsetY = 0; screenShakeTimer = 0; screenShakeOffsetX = 0; screenShakeOffsetY = 0;
combo = 0; comboTimer = 0; lastKillTime = 0; combo = 0; comboTimer = 0; lastKillTime = 0;
bossSpawnedThisLevel = false; bossAttackPattern = 0; bossAttackTimer = 0; strcpy(bossWarningText, ""); bossWarningTimer = 0; bossSpawnedThisLevel = false; bossAttackPattern = 0; bossAttackTimer = 0; strcpy(bossWarningText, ""); bossWarningTimer = 0;
bc = ec = sc = lv = 1; srand((unsigned int)time(NULL)); bc = ec = sc = lv = 1; srand((unsigned int)time(NULL));
cityBuildingHeights.clear(); int numBuildings = W / CITY_BUILDING_WIDTH; for (int i = 0; i < numBuildings; i++) { cityBuildingHeights.push_back(rand() % (CITY_BUILDING_HEIGHT_MAX - CITY_BUILDING_HEIGHT_MIN + 1) + CITY_BUILDING_HEIGHT_MIN); } cityBuildingHeights.clear(); int numBuildings = W / CITY_BUILDING_WIDTH; for (int i = 0; i < numBuildings; i++) { cityBuildingHeights.push_back(rand() % (CITY_BUILDING_HEIGHT_MAX - CITY_BUILDING_HEIGHT_MIN + 1) + CITY_BUILDING_HEIGHT_MIN); }}
void DrawStart() { cleardevice(); setfillcolor(BLACK); bar(0, 0, W, H); cleardevice(); setfillcolor(BLACK); bar(0, 0, W, H);
setcolor(YELLOW); settextstyle(30, 0, "Arial"); outtextxy(W / 2 - 100, H / 3, "Aircraft Battle"); setcolor(YELLOW); settextstyle(30, 0, "Arial"); outtextxy(W / 2 - 100, H / 3, "Aircraft Battle");
setcolor(WHITE); settextstyle(16, 0, "Consolas"); outtextxy(W / 2 - 60, H / 2, "Press SPACE to start"); outtextxy(W / 2 - 60, H / 2 + 30, "Arrow keys: move"); outtextxy(W / 2 - 60, H / 2 + 60, "SPACE: shoot"); outtextxy(W / 2 - 60, H / 2 + 90, "F: use BOMB"); outtextxy(W / 2 - 60, H / 2 + 120, "Z: use LASER"); outtextxy(W / 2 - 60, H / 2 + 150, "X: use RAGE (10s +5 damage)"); outtextxy(W / 2 - 60, H / 2 + 180, "H: use HOMING MISSILE (5 missiles)"); outtextxy(W / 2 - 60, H / 2 + 210, "G: use SPREAD SHOT (7 bullets)"); outtextxy(W / 2 - 60, H / 2 + 240, "P: pause"); outtextxy(W / 2 - 60, H / 2 + 270, "ESC: quit"); setcolor(WHITE); settextstyle(16, 0, "Consolas"); outtextxy(W / 2 - 60, H / 2, "Press SPACE to start"); outtextxy(W / 2 - 60, H / 2 + 30, "Arrow keys: move"); outtextxy(W / 2 - 60, H / 2 + 60, "SPACE: shoot"); outtextxy(W / 2 - 60, H / 2 + 90, "F: use BOMB"); outtextxy(W / 2 - 60, H / 2 + 120, "Z: use LASER"); outtextxy(W / 2 - 60, H / 2 + 150, "X: use RAGE (10s +5 damage)"); outtextxy(W / 2 - 60, H / 2 + 180, "H: use HOMING MISSILE (5 missiles)"); outtextxy(W / 2 - 60, H / 2 + 210, "G: use SPREAD SHOT (7 bullets)"); outtextxy(W / 2 - 60, H / 2 + 240, "P: pause"); outtextxy(W / 2 - 60, H / 2 + 270, "ESC: quit");
char hsStr[50]; sprintf(hsStr, "High Score: %d", highScore); outtextxy(W / 2 - 60, H / 2 + 300, hsStr); char hsStr[50]; sprintf(hsStr, "High Score: %d", highScore); outtextxy(W / 2 - 60, H / 2 + 300, hsStr);}
void DrawCity() { int offset_y = screenShakeOffsetY; int offset_y = screenShakeOffsetY;
setfillcolor(RGB(30, 30, 50)); bar(0, H + offset_y, W, H + 20 + offset_y); setfillcolor(RGB(30, 30, 50)); bar(0, H + offset_y, W, H + 20 + offset_y);
setfillcolor(RGB(40, 40, 60)); for (int i = 0; i < cityBuildingHeights.size(); i++) { int buildingX = i * CITY_BUILDING_WIDTH; int buildingHeight = cityBuildingHeights[i]; bar(buildingX, H - buildingHeight + offset_y, buildingX + CITY_BUILDING_WIDTH, H + offset_y); } setfillcolor(RGB(40, 40, 60)); for (int i = 0; i < cityBuildingHeights.size(); i++) { int buildingX = i * CITY_BUILDING_WIDTH; int buildingHeight = cityBuildingHeights[i]; bar(buildingX, H - buildingHeight + offset_y, buildingX + CITY_BUILDING_WIDTH, H + offset_y); }}
void DrawPlayer() { int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY; int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY;
int drawX = p.x + offset_x; int drawY = p.y + offset_y; int drawX = p.x + offset_x; int drawY = p.y + offset_y;
POINT playerBody[] = { {drawX + 10, drawY}, {drawX, drawY + 30}, {drawX + 20, drawY + 30} }; setfillcolor(RGB(30, 144, 255)); fillpolygon(playerBody, 3); POINT playerBody[] = { {drawX + 10, drawY}, {drawX, drawY + 30}, {drawX + 20, drawY + 30} }; setfillcolor(RGB(30, 144, 255)); fillpolygon(playerBody, 3);
POINT core[] = { {drawX + 10, drawY + 5}, {drawX + 5, drawY + 25}, {drawX + 15, drawY + 25} }; setfillcolor(WHITE); fillpolygon(core, 3); POINT core[] = { {drawX + 10, drawY + 5}, {drawX + 5, drawY + 25}, {drawX + 15, drawY + 25} }; setfillcolor(WHITE); fillpolygon(core, 3);
POINT leftWing[] = { {drawX - 10, drawY + 15}, {drawX, drawY + 8}, {drawX + 5, drawY + 15}, {drawX, drawY + 23} }; setfillcolor(RGB(100, 149, 237)); fillpolygon(leftWing, 4); POINT leftWing[] = { {drawX - 10, drawY + 15}, {drawX, drawY + 8}, {drawX + 5, drawY + 15}, {drawX, drawY + 23} }; setfillcolor(RGB(100, 149, 237)); fillpolygon(leftWing, 4);
POINT rightWing[] = { {drawX + 20 + 10, drawY + 15}, {drawX + 20, drawY + 8}, {drawX + 20 - 5, drawY + 15}, {drawX + 20, drawY + 23} }; fillpolygon(rightWing, 4); POINT rightWing[] = { {drawX + 20 + 10, drawY + 15}, {drawX + 20, drawY + 8}, {drawX + 20 - 5, drawY + 15}, {drawX + 20, drawY + 23} }; fillpolygon(rightWing, 4);
setfillcolor(RED); bar(drawX + 3, drawY - 5, drawX + 6, drawY); bar(drawX + 14, drawY - 5, drawX + 17, drawY); bar(drawX + 8, drawY - 8, drawX + 12, drawY - 2); setfillcolor(RED); bar(drawX + 3, drawY - 5, drawX + 6, drawY); bar(drawX + 14, drawY - 5, drawX + 17, drawY); bar(drawX + 8, drawY - 8, drawX + 12, drawY - 2);
setfillcolor(YELLOW); fillcircle(drawX + 10, drawY + 10, 3); setfillcolor(YELLOW); fillcircle(drawX + 10, drawY + 10, 3);
if (p.hp > 0) { setfillcolor(GREEN); int w = (int)((20.0 * p.hp) / 10); bar(drawX, drawY + 32, drawX + w, drawY + 36); setcolor(WHITE); rectangle(drawX, drawY + 32, drawX + 20, drawY + 36); } if (p.hp > 0) { setfillcolor(GREEN); int w = (int)((20.0 * p.hp) / 10); bar(drawX, drawY + 32, drawX + w, drawY + 36); setcolor(WHITE); rectangle(drawX, drawY + 32, drawX + 20, drawY + 36); }}
void DrawBullets() { int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY; int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY;
for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live) { if (b[i].shooterType == 0) { if (b[i].type == BULLET_NORMAL) { setfillcolor(BLUE); } else if (b[i].type == BULLET_HOMING) { setfillcolor(RGB(0, 255, 255)); } else if (b[i].type == BULLET_SPREAD) { setfillcolor(RGB(255, 255, 0)); } } else if (b[i].shooterType == 1) { setfillcolor(RED); } else { setfillcolor(YELLOW); } for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live) { if (b[i].shooterType == 0) { if (b[i].type == BULLET_NORMAL) { setfillcolor(BLUE); } else if (b[i].type == BULLET_HOMING) { setfillcolor(RGB(0, 255, 255)); } else if (b[i].type == BULLET_SPREAD) { setfillcolor(RGB(255, 255, 0)); } } else if (b[i].shooterType == 1) { setfillcolor(RED); } else { setfillcolor(YELLOW); }
if (b[i].type == BULLET_HOMING) { POINT missile[] = { {b[i].x + offset_x, b[i].y - 3 + offset_y}, {b[i].x - 3 + offset_x, b[i].y + offset_y}, {b[i].x + offset_x, b[i].y + 3 + offset_y}, {b[i].x + 3 + offset_x, b[i].y + offset_y} }; fillpolygon(missile, 4); } else { bar(b[i].x + offset_x, b[i].y + offset_y, b[i].x + 4 + offset_x, b[i].y + 10 + offset_y); } } } if (b[i].type == BULLET_HOMING) { POINT missile[] = { {b[i].x + offset_x, b[i].y - 3 + offset_y}, {b[i].x - 3 + offset_x, b[i].y + offset_y}, {b[i].x + offset_x, b[i].y + 3 + offset_y}, {b[i].x + 3 + offset_x, b[i].y + offset_y} }; fillpolygon(missile, 4); } else { bar(b[i].x + offset_x, b[i].y + offset_y, b[i].x + 4 + offset_x, b[i].y + 10 + offset_y); } } }}
void DrawEnemies() { int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY; int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY;
for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { int drawX = e[i].x + offset_x; int drawY = e[i].y + offset_y; for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { int drawX = e[i].x + offset_x; int drawY = e[i].y + offset_y;
if (e[i].type == ENEMY_BOSS) { POINT bossBody[] = { {drawX + e[i].width / 2, drawY + e[i].height}, {drawX, drawY}, {drawX + e[i].width, drawY} }; setfillcolor(RGB(40, 40, 40)); fillpolygon(bossBody, 3); if (e[i].type == ENEMY_BOSS) { POINT bossBody[] = { {drawX + e[i].width / 2, drawY + e[i].height}, {drawX, drawY}, {drawX + e[i].width, drawY} }; setfillcolor(RGB(40, 40, 40)); fillpolygon(bossBody, 3);
POINT core[] = { {drawX + e[i].width / 2, drawY + e[i].height - 5}, {drawX + e[i].width / 4, drawY + 5}, {drawX + 3 * e[i].width / 4, drawY + 5} }; setfillcolor(RGB(139, 0, 0)); fillpolygon(core, 3); POINT core[] = { {drawX + e[i].width / 2, drawY + e[i].height - 5}, {drawX + e[i].width / 4, drawY + 5}, {drawX + 3 * e[i].width / 4, drawY + 5} }; setfillcolor(RGB(139, 0, 0)); fillpolygon(core, 3);
POINT leftWing[] = { {drawX - 15, drawY + 3 * e[i].height / 4}, {drawX, drawY + e[i].height / 2}, {drawX - 10, drawY + e[i].height / 4}, {drawX - 20, drawY + e[i].height / 2} }; setfillcolor(RGB(60, 60, 60)); fillpolygon(leftWing, 4); POINT leftWing[] = { {drawX - 15, drawY + 3 * e[i].height / 4}, {drawX, drawY + e[i].height / 2}, {drawX - 10, drawY + e[i].height / 4}, {drawX - 20, drawY + e[i].height / 2} }; setfillcolor(RGB(60, 60, 60)); fillpolygon(leftWing, 4);
POINT rightWing[] = { {drawX + e[i].width + 15, drawY + 3 * e[i].height / 4}, {drawX + e[i].width, drawY + e[i].height / 2}, {drawX + e[i].width + 10, drawY + e[i].height / 4}, {drawX + e[i].width + 20, drawY + e[i].height / 2} }; fillpolygon(rightWing, 4); POINT rightWing[] = { {drawX + e[i].width + 15, drawY + 3 * e[i].height / 4}, {drawX + e[i].width, drawY + e[i].height / 2}, {drawX + e[i].width + 10, drawY + e[i].height / 4}, {drawX + e[i].width + 20, drawY + e[i].height / 2} }; fillpolygon(rightWing, 4);
setfillcolor(RGB(0, 191, 255)); bar(drawX + e[i].width / 2 - 2, drawY + 5, drawX + e[i].width / 2 + 2, drawY + e[i].height - 5); setfillcolor(RGB(0, 191, 255)); bar(drawX + e[i].width / 2 - 2, drawY + 5, drawX + e[i].width / 2 + 2, drawY + e[i].height - 5);
setfillcolor(RED); bar(drawX + 5, drawY + e[i].height, drawX + 15, drawY + e[i].height + 10); bar(drawX + e[i].width - 15, drawY + e[i].height, drawX + e[i].width - 5, drawY + e[i].height + 10); bar(drawX + e[i].width / 2 - 5, drawY + e[i].height, drawX + e[i].width / 2 + 5, drawY + e[i].height + 10); setfillcolor(RED); bar(drawX + 5, drawY + e[i].height, drawX + 15, drawY + e[i].height + 10); bar(drawX + e[i].width - 15, drawY + e[i].height, drawX + e[i].width - 5, drawY + e[i].height + 10); bar(drawX + e[i].width / 2 - 5, drawY + e[i].height, drawX + e[i].width / 2 + 5, drawY + e[i].height + 10);
setfillcolor(BLACK); bar(drawX + e[i].width / 2 - 3, drawY - 5, drawX + e[i].width / 2 + 3, drawY); setfillcolor(BLACK); bar(drawX + e[i].width / 2 - 3, drawY - 5, drawX + e[i].width / 2 + 3, drawY);
if (e[i].isFiringLaser) { setcolor(RGB(0, 191, 255)); setlinestyle(PS_SOLID, 5); line(drawX + 10, drawY + e[i].height + 10, drawX + 10, H); line(drawX + e[i].width / 2, drawY + e[i].height + 10, drawX + e[i].width / 2, H); line(drawX + e[i].width - 10, drawY + e[i].height + 10, drawX + e[i].width - 10, H); setlinestyle(PS_SOLID, 1); } if (e[i].isFiringLaser) { setcolor(RGB(0, 191, 255)); setlinestyle(PS_SOLID, 5); line(drawX + 10, drawY + e[i].height + 10, drawX + 10, H); line(drawX + e[i].width / 2, drawY + e[i].height + 10, drawX + e[i].width / 2, H); line(drawX + e[i].width - 10, drawY + e[i].height + 10, drawX + e[i].width - 10, H); setlinestyle(PS_SOLID, 1); }
} else { POINT enemyBody[] = { {drawX + 15, drawY + 30}, {drawX, drawY}, {drawX + 30, drawY} }; setfillcolor(RGB(255, 105, 180)); fillpolygon(enemyBody, 3); } else { POINT enemyBody[] = { {drawX + 15, drawY + 30}, {drawX, drawY}, {drawX + 30, drawY} }; setfillcolor(RGB(255, 105, 180)); fillpolygon(enemyBody, 3);
POINT leftWing[] = { {drawX - 5, drawY + 20}, {drawX, drawY + 10}, {drawX + 5, drawY + 20}, {drawX, drawY + 25} }; setfillcolor(RGB(255, 20, 147)); fillpolygon(leftWing, 4); POINT leftWing[] = { {drawX - 5, drawY + 20}, {drawX, drawY + 10}, {drawX + 5, drawY + 20}, {drawX, drawY + 25} }; setfillcolor(RGB(255, 20, 147)); fillpolygon(leftWing, 4);
POINT rightWing[] = { {drawX + 25, drawY + 20}, {drawX + 30, drawY + 10}, {drawX + 35, drawY + 20}, {drawX + 30, drawY + 25} }; fillpolygon(rightWing, 4); POINT rightWing[] = { {drawX + 25, drawY + 20}, {drawX + 30, drawY + 10}, {drawX + 35, drawY + 20}, {drawX + 30, drawY + 25} }; fillpolygon(rightWing, 4);
setfillcolor(RGB(220, 20, 60)); bar(drawX + 13, drawY - 5, drawX + 17, drawY); setfillcolor(RGB(220, 20, 60)); bar(drawX + 13, drawY - 5, drawX + 17, drawY);
setfillcolor(RED); bar(drawX + 14, drawY + 30, drawX + 16, drawY + 35); } setfillcolor(RED); bar(drawX + 14, drawY + 30, drawX + 16, drawY + 35); }
if (e[i].hp > 0) { if (e[i].type == ENEMY_BOSS) { setfillcolor(RGB(0, 191, 255)); } else { setfillcolor(RED); } if (e[i].hp > 0) { if (e[i].type == ENEMY_BOSS) { setfillcolor(RGB(0, 191, 255)); } else { setfillcolor(RED); }
int w = (int)((static_cast<double>(e[i].width) * e[i].hp) / e[i].initialHp); bar(drawX, drawY - 6, drawX + w, drawY - 2); setcolor(WHITE); rectangle(drawX, drawY - 6, drawX + e[i].width, drawY - 2); } } } int w = (int)((static_cast<double>(e[i].width) * e[i].hp) / e[i].initialHp); bar(drawX, drawY - 6, drawX + w, drawY - 2); setcolor(WHITE); rectangle(drawX, drawY - 6, drawX + e[i].width, drawY - 2); } } }}
void DrawPowerUps() { int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY; int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY;
for (int i = 0; i < MAX_POWERUPS; i++) { if (pu[i].live) { switch (pu[i].type) { case POWERUP_ATTACK: setfillcolor(RED); solidcircle(pu[i].x + offset_x, pu[i].y + offset_y, 6); setcolor(YELLOW); settextstyle(10, 0, "Arial"); outtextxy(pu[i].x - 3 + offset_x, pu[i].y - 5 + offset_y, "A"); break; case POWERUP_HP: setfillcolor(GREEN); solidcircle(pu[i].x + offset_x, pu[i].y + offset_y, 6); setcolor(WHITE); settextstyle(10, 0, "Arial"); outtextxy(pu[i].x - 2 + offset_x, pu[i].y - 5 + offset_y, "+"); break; case POWERUP_BOMB: setfillcolor(YELLOW); solidcircle(pu[i].x + offset_x, pu[i].y + offset_y, 6); setcolor(WHITE); settextstyle(10, 0, "Arial"); outtextxy(pu[i].x - 3 + offset_x, pu[i].y - 5 + offset_y, "B"); break; } } } for (int i = 0; i < MAX_POWERUPS; i++) { if (pu[i].live) { switch (pu[i].type) { case POWERUP_ATTACK: setfillcolor(RED); solidcircle(pu[i].x + offset_x, pu[i].y + offset_y, 6); setcolor(YELLOW); settextstyle(10, 0, "Arial"); outtextxy(pu[i].x - 3 + offset_x, pu[i].y - 5 + offset_y, "A"); break; case POWERUP_HP: setfillcolor(GREEN); solidcircle(pu[i].x + offset_x, pu[i].y + offset_y, 6); setcolor(WHITE); settextstyle(10, 0, "Arial"); outtextxy(pu[i].x - 2 + offset_x, pu[i].y - 5 + offset_y, "+"); break; case POWERUP_BOMB: setfillcolor(YELLOW); solidcircle(pu[i].x + offset_x, pu[i].y + offset_y, 6); setcolor(WHITE); settextstyle(10, 0, "Arial"); outtextxy(pu[i].x - 3 + offset_x, pu[i].y - 5 + offset_y, "B"); break; } } }}
void DrawExplosions() { int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY; int offset_x = screenShakeOffsetX; int offset_y = screenShakeOffsetY;
for (int i = 0; i < MAX_PARTICLES; i++) { if (particles[i].active) { int drawX = (int)particles[i].x + offset_x; int drawY = (int)particles[i].y + offset_y; for (int i = 0; i < MAX_PARTICLES; i++) { if (particles[i].active) { int drawX = (int)particles[i].x + offset_x; int drawY = (int)particles[i].y + offset_y;
if (particles[i].type == PARTICLE_EXPLOSION) { setfillcolor(particles[i].color); solidcircle(drawX, drawY, (int)particles[i].size); } else if (particles[i].type == PARTICLE_JET_TRAIL) { int gray = 255 - (int)((particles[i].life * 255.0) / 20.0); if (gray < 0) gray = 0; if (gray > 255) gray = 255; setfillcolor(RGB(gray, gray, gray)); solidcircle(drawX, drawY, (int)particles[i].size); } else if (particles[i].type == PARTICLE_BLEED) { setfillcolor(RED); solidcircle(drawX, drawY, (int)particles[i].size); } else if (particles[i].type == PARTICLE_BOMB_WAVE) { setfillcolor(RGB(255, 255, 200)); solidcircle(drawX, drawY, (int)particles[i].size); } } } if (particles[i].type == PARTICLE_EXPLOSION) { setfillcolor(particles[i].color); solidcircle(drawX, drawY, (int)particles[i].size); } else if (particles[i].type == PARTICLE_JET_TRAIL) { int gray = 255 - (int)((particles[i].life * 255.0) / 20.0); if (gray < 0) gray = 0; if (gray > 255) gray = 255; setfillcolor(RGB(gray, gray, gray)); solidcircle(drawX, drawY, (int)particles[i].size); } else if (particles[i].type == PARTICLE_BLEED) { setfillcolor(RED); solidcircle(drawX, drawY, (int)particles[i].size); } else if (particles[i].type == PARTICLE_BOMB_WAVE) { setfillcolor(RGB(255, 255, 200)); solidcircle(drawX, drawY, (int)particles[i].size); } } }
for (int i = 0; i < MAX_EXPLOSIONS; i++) { if (pxe[i].active) { int drawX = pxe[i].x + offset_x; int drawY = pxe[i].y + offset_y; setcolor(RGB(255, 100, 0)); circle(drawX, drawY, pxe[i].frame); } } for (int i = 0; i < MAX_EXPLOSIONS; i++) { if (pxe[i].active) { int drawX = pxe[i].x + offset_x; int drawY = pxe[i].y + offset_y; setcolor(RGB(255, 100, 0)); circle(drawX, drawY, pxe[i].frame); } }}
void CreateExplosion(int x, int y) { for (int i = 0; i < MAX_EXPLOSIONS; i++) { if (!pxe[i].active) { pxe[i].x = x; pxe[i].y = y; pxe[i].active = true; pxe[i].frame = 0; pxe[i].maxFrame = 10; break; } } for (int i = 0; i < MAX_EXPLOSIONS; i++) { if (!pxe[i].active) { pxe[i].x = x; pxe[i].y = y; pxe[i].active = true; pxe[i].frame = 0; pxe[i].maxFrame = 10; break; } }
for (int j = 0; j < 20; j++) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { particles[idx].x = x; particles[idx].y = y; particles[idx].vx = (rand() % 11) - 5; particles[idx].vy = (rand() % 11) - 5; particles[idx].life = 20 + rand() % 20; int hue = rand() % 40; particles[idx].color = RGB(255, 150 - (hue * 3), 0); particles[idx].active = true; particles[idx].type = PARTICLE_EXPLOSION; particles[idx].size = 2.0; } } for (int j = 0; j < 20; j++) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { particles[idx].x = x; particles[idx].y = y; particles[idx].vx = (rand() % 11) - 5; particles[idx].vy = (rand() % 11) - 5; particles[idx].life = 20 + rand() % 20; int hue = rand() % 40; particles[idx].color = RGB(255, 150 - (hue * 3), 0); particles[idx].active = true; particles[idx].type = PARTICLE_EXPLOSION; particles[idx].size = 2.0; } }}
const double M_PI = 3.14159265358979323846;void CreateBombWaveParticles(int centerX, int centerY, int numParticles) { for (int j = 0; j < numParticles; j++) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { double angle = (rand() % 360) * M_PI / 180.0; double speed = 3.0 + (rand() % 5); particles[idx].x = centerX; particles[idx].y = centerY; particles[idx].vx = cos(angle) * speed; particles[idx].vy = sin(angle) * speed; particles[idx].life = 10 + rand() % 10; particles[idx].color = RGB(255, 255, 200); particles[idx].active = true; particles[idx].type = PARTICLE_BOMB_WAVE; particles[idx].size = 1.0 + (rand() % 3); } } for (int j = 0; j < numParticles; j++) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { double angle = (rand() % 360) * M_PI / 180.0; double speed = 3.0 + (rand() % 5); particles[idx].x = centerX; particles[idx].y = centerY; particles[idx].vx = cos(angle) * speed; particles[idx].vy = sin(angle) * speed; particles[idx].life = 10 + rand() % 10; particles[idx].color = RGB(255, 255, 200); particles[idx].active = true; particles[idx].type = PARTICLE_BOMB_WAVE; particles[idx].size = 1.0 + (rand() % 3); } }}
void CreateJetTrail(int x, int y, int direction) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { particles[idx].x = x + rand() % 6 - 3; particles[idx].y = y + (direction ? 5 : -5); particles[idx].vx = (rand() % 3) - 1; particles[idx].vy = (direction ? 1 : -1) * (rand() % 2 + 1); particles[idx].life = 15 + rand() % 10; particles[idx].color = RGB(200, 200, 200); particles[idx].active = true; particles[idx].type = PARTICLE_JET_TRAIL; particles[idx].size = 1.5; } int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { particles[idx].x = x + rand() % 6 - 3; particles[idx].y = y + (direction ? 5 : -5); particles[idx].vx = (rand() % 3) - 1; particles[idx].vy = (direction ? 1 : -1) * (rand() % 2 + 1); particles[idx].life = 15 + rand() % 10; particles[idx].color = RGB(200, 200, 200); particles[idx].active = true; particles[idx].type = PARTICLE_JET_TRAIL; particles[idx].size = 1.5; }}
void CreateBleedingParticles(int x, int y, int count) { for (int j = 0; j < count; j++) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { particles[idx].x = x + rand() % 20 - 10; particles[idx].y = y + rand() % 20 - 10; particles[idx].vx = (rand() % 5) - 2; particles[idx].vy = (rand() % 5) - 2; particles[idx].life = 10 + rand() % 10; particles[idx].color = RGB(200, 0, 0); particles[idx].active = true; particles[idx].type = PARTICLE_BLEED; particles[idx].size = 1.0 + (rand() % 2); } } for (int j = 0; j < count; j++) { int idx = rand() % MAX_PARTICLES; if (!particles[idx].active) { particles[idx].x = x + rand() % 20 - 10; particles[idx].y = y + rand() % 20 - 10; particles[idx].vx = (rand() % 5) - 2; particles[idx].vy = (rand() % 5) - 2; particles[idx].life = 10 + rand() % 10; particles[idx].color = RGB(200, 0, 0); particles[idx].active = true; particles[idx].type = PARTICLE_BLEED; particles[idx].size = 1.0 + (rand() % 2); } }}
void UpdateExplosions() { for (int i = 0; i < MAX_EXPLOSIONS; i++) { if (pxe[i].active) { pxe[i].frame++; if (pxe[i].frame >= pxe[i].maxFrame) { pxe[i].active = false; } } } for (int i = 0; i < MAX_EXPLOSIONS; i++) { if (pxe[i].active) { pxe[i].frame++; if (pxe[i].frame >= pxe[i].maxFrame) { pxe[i].active = false; } } }
for (int i = 0; i < MAX_PARTICLES; i++) { if (particles[i].active) { particles[i].x += particles[i].vx; particles[i].y += particles[i].vy; particles[i].life--; if (particles[i].life <= 0) { particles[i].active = false; } } } for (int i = 0; i < MAX_PARTICLES; i++) { if (particles[i].active) { particles[i].x += particles[i].vx; particles[i].y += particles[i].vy; particles[i].life--; if (particles[i].life <= 0) { particles[i].active = false; } } }}
void DrawGameOver() { setfillcolor(BLACK); bar(0, 0, W, H); setfillcolor(BLACK); bar(0, 0, W, H);
setcolor(RED); settextstyle(40, 0, "Arial"); outtextxy(W / 2 - 80, H / 3, "GAME OVER"); setcolor(RED); settextstyle(40, 0, "Arial"); outtextxy(W / 2 - 80, H / 3, "GAME OVER");
setcolor(YELLOW); settextstyle(24, 0, "Arial"); char s[50]; sprintf(s, "END SCORE: %d", sc); outtextxy(W / 2 - 60, H / 2, s); setcolor(YELLOW); settextstyle(24, 0, "Arial"); char s[50]; sprintf(s, "END SCORE: %d", sc); outtextxy(W / 2 - 60, H / 2, s);
if (sc > highScore) { highScore = sc; } sprintf(s, "HIGH SCORE: %d", highScore); outtextxy(W / 2 - 60, H / 2 + 30, s); if (sc > highScore) { highScore = sc; } sprintf(s, "HIGH SCORE: %d", highScore); outtextxy(W / 2 - 60, H / 2 + 30, s);
setcolor(WHITE); settextstyle(16, 0, "Consolas"); outtextxy(W / 2 - 70, H / 2 + 70, "Returning to menu..."); setcolor(WHITE); settextstyle(16, 0, "Consolas"); outtextxy(W / 2 - 70, H / 2 + 70, "Returning to menu...");
outtextxy(W / 2 - 70, H / 2 + 110, "Achievements Unlocked:"); int achCount = 0; for (const auto& ach : achievements) { if (ach.unlocked) { outtextxy(W / 2 - 70, H / 2 + 130 + achCount * 20, ach.name); achCount++; if (achCount >= 3) break; } } outtextxy(W / 2 - 70, H / 2 + 110, "Achievements Unlocked:"); int achCount = 0; for (const auto& ach : achievements) { if (ach.unlocked) { outtextxy(W / 2 - 70, H / 2 + 130 + achCount * 20, ach.name); achCount++; if (achCount >= 3) break; } }}
void GameDraw() { BeginBatchDraw(); cleardevice(); setfillcolor(BLACK); bar(0, 0, W, H); BeginBatchDraw(); cleardevice(); setfillcolor(BLACK); bar(0, 0, W, H);
DrawCity(); DrawEnemies(); DrawBullets(); DrawPowerUps(); DrawExplosions(); DrawPlayer(); DrawCity(); DrawEnemies(); DrawBullets(); DrawPowerUps(); DrawExplosions(); DrawPlayer();
if (laserActive) { setcolor(RGB(0, 255, 255)); setlinestyle(PS_SOLID, 3); for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { int px = p.x + 10 + screenShakeOffsetX; int py = p.y - 5 + screenShakeOffsetY; int ex = e[i].x + e[i].width / 2 + screenShakeOffsetX; int ey = e[i].y + e[i].height / 2 + screenShakeOffsetY; line(px, py, ex, ey); } } setlinestyle(PS_SOLID, 1); } if (laserActive) { setcolor(RGB(0, 255, 255)); setlinestyle(PS_SOLID, 3); for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { int px = p.x + 10 + screenShakeOffsetX; int py = p.y - 5 + screenShakeOffsetY; int ex = e[i].x + e[i].width / 2 + screenShakeOffsetX; int ey = e[i].y + e[i].height / 2 + screenShakeOffsetY; line(px, py, ex, ey); } } setlinestyle(PS_SOLID, 1); }
setcolor(WHITE); settextstyle(16, 0, "Consolas"); char s[30]; sprintf(s, "score : %d", sc); outtextxy(10 + screenShakeOffsetX, 10 + screenShakeOffsetY, s); sprintf(s, "level : %d", lv); outtextxy(10 + screenShakeOffsetX, 30 + screenShakeOffsetY, s); setcolor(WHITE); settextstyle(16, 0, "Consolas"); char s[30]; sprintf(s, "score : %d", sc); outtextxy(10 + screenShakeOffsetX, 10 + screenShakeOffsetY, s); sprintf(s, "level : %d", lv); outtextxy(10 + screenShakeOffsetX, 30 + screenShakeOffsetY, s);
sprintf(s, "attack: %.1f", shanghai); outtextxy(10 + screenShakeOffsetX, 50 + screenShakeOffsetY, s); sprintf(s, "attack: %.1f", shanghai); outtextxy(10 + screenShakeOffsetX, 50 + screenShakeOffsetY, s);
sprintf(s, "HP: %d/%d", p.hp, p.maxHp); outtextxy(10 + screenShakeOffsetX, 70 + screenShakeOffsetY, s); sprintf(s, "HP: %d/%d", p.hp, p.maxHp); outtextxy(10 + screenShakeOffsetX, 70 + screenShakeOffsetY, s);
if (combo > 1) { setcolor(YELLOW); settextstyle(20, 0, "Arial"); sprintf(s, "%dx COMBO!", combo); int flashIntensity = (GetTickCount() / 100) % 2; if (flashIntensity) { outtextxy(W / 2 - textwidth(s) / 2 + screenShakeOffsetX, 10 + screenShakeOffsetY, s); } settextstyle(16, 0, "Consolas"); setcolor(WHITE); } if (combo > 1) { setcolor(YELLOW); settextstyle(20, 0, "Arial"); sprintf(s, "%dx COMBO!", combo); int flashIntensity = (GetTickCount() / 100) % 2; if (flashIntensity) { outtextxy(W / 2 - textwidth(s) / 2 + screenShakeOffsetX, 10 + screenShakeOffsetY, s); } settextstyle(16, 0, "Consolas"); setcolor(WHITE); }
if (bossWarningTimer > 0) { setcolor(RED); settextstyle(24, 0, "Arial"); int flashIntensity = (GetTickCount() / 100) % 2; if (flashIntensity) { outtextxy(W / 2 - textwidth(bossWarningText) / 2 + screenShakeOffsetX, H / 4 + screenShakeOffsetY, bossWarningText); } settextstyle(16, 0, "Consolas"); setcolor(WHITE); } if (bossWarningTimer > 0) { setcolor(RED); settextstyle(24, 0, "Arial"); int flashIntensity = (GetTickCount() / 100) % 2; if (flashIntensity) { outtextxy(W / 2 - textwidth(bossWarningText) / 2 + screenShakeOffsetX, H / 4 + screenShakeOffsetY, bossWarningText); } settextstyle(16, 0, "Consolas"); setcolor(WHITE); }
setcolor(WHITE); outtextxy(10 + screenShakeOffsetX, 90 + screenShakeOffsetY, "Skills:"); setcolor(WHITE); outtextxy(10 + screenShakeOffsetX, 90 + screenShakeOffsetY, "Skills:");
setfillcolor(BLUE); int bombWidth = (int)((100.0 * skills.bombEnergy) / 100.0); bar(10 + screenShakeOffsetX, 110 + screenShakeOffsetY, 10 + bombWidth + screenShakeOffsetX, 120 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 110 + screenShakeOffsetY, 110 + screenShakeOffsetX, 120 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 110 + screenShakeOffsetY, "Bomb(F)"); setfillcolor(BLUE); int bombWidth = (int)((100.0 * skills.bombEnergy) / 100.0); bar(10 + screenShakeOffsetX, 110 + screenShakeOffsetY, 10 + bombWidth + screenShakeOffsetX, 120 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 110 + screenShakeOffsetY, 110 + screenShakeOffsetX, 120 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 110 + screenShakeOffsetY, "Bomb(F)");
setfillcolor(GREEN); int laserWidth = (int)((100.0 * skills.laserEnergy) / 100.0); bar(10 + screenShakeOffsetX, 130 + screenShakeOffsetY, 10 + laserWidth + screenShakeOffsetX, 140 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 130 + screenShakeOffsetY, 110 + screenShakeOffsetX, 140 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 130 + screenShakeOffsetY, "Laser(Z)"); setfillcolor(GREEN); int laserWidth = (int)((100.0 * skills.laserEnergy) / 100.0); bar(10 + screenShakeOffsetX, 130 + screenShakeOffsetY, 10 + laserWidth + screenShakeOffsetX, 140 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 130 + screenShakeOffsetY, 110 + screenShakeOffsetX, 140 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 130 + screenShakeOffsetY, "Laser(Z)");
setfillcolor(RED); int rageWidth = (int)((100.0 * skills.rageEnergy) / 100.0); bar(10 + screenShakeOffsetX, 150 + screenShakeOffsetY, 10 + rageWidth + screenShakeOffsetX, 160 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 150 + screenShakeOffsetY, 110 + screenShakeOffsetX, 160 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 150 + screenShakeOffsetY, "Rage(X)"); setfillcolor(RED); int rageWidth = (int)((100.0 * skills.rageEnergy) / 100.0); bar(10 + screenShakeOffsetX, 150 + screenShakeOffsetY, 10 + rageWidth + screenShakeOffsetX, 160 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 150 + screenShakeOffsetY, 110 + screenShakeOffsetX, 160 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 150 + screenShakeOffsetY, "Rage(X)");
setfillcolor(RGB(0, 255, 255)); int homingWidth = (int)((100.0 * skills.homingMissileEnergy) / 100.0); bar(10 + screenShakeOffsetX, 170 + screenShakeOffsetY, 10 + homingWidth + screenShakeOffsetX, 180 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 170 + screenShakeOffsetY, 110 + screenShakeOffsetX, 180 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 170 + screenShakeOffsetY, "Homing(H)"); setfillcolor(RGB(0, 255, 255)); int homingWidth = (int)((100.0 * skills.homingMissileEnergy) / 100.0); bar(10 + screenShakeOffsetX, 170 + screenShakeOffsetY, 10 + homingWidth + screenShakeOffsetX, 180 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 170 + screenShakeOffsetY, 110 + screenShakeOffsetX, 180 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 170 + screenShakeOffsetY, "Homing(H)");
setfillcolor(RGB(255, 255, 0)); int spreadWidth = (int)((100.0 * skills.spreadShotEnergy) / 100.0); bar(10 + screenShakeOffsetX, 190 + screenShakeOffsetY, 10 + spreadWidth + screenShakeOffsetX, 200 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 190 + screenShakeOffsetY, 110 + screenShakeOffsetX, 200 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 190 + screenShakeOffsetY, "Spread(G)"); setfillcolor(RGB(255, 255, 0)); int spreadWidth = (int)((100.0 * skills.spreadShotEnergy) / 100.0); bar(10 + screenShakeOffsetX, 190 + screenShakeOffsetY, 10 + spreadWidth + screenShakeOffsetX, 200 + screenShakeOffsetY); setcolor(WHITE); rectangle(10 + screenShakeOffsetX, 190 + screenShakeOffsetY, 110 + screenShakeOffsetX, 200 + screenShakeOffsetY); outtextxy(115 + screenShakeOffsetX, 190 + screenShakeOffsetY, "Spread(G)");
if (skills.rageActive) { setcolor(YELLOW); settextstyle(14, 0, "Arial"); outtextxy(W / 2 - 50 + screenShakeOffsetX, H - 30 + screenShakeOffsetY, "RAGE MODE!"); settextstyle(16, 0, "Consolas"); setcolor(WHITE); } if (skills.rageActive) { setcolor(YELLOW); settextstyle(14, 0, "Arial"); outtextxy(W / 2 - 50 + screenShakeOffsetX, H - 30 + screenShakeOffsetY, "RAGE MODE!"); settextstyle(16, 0, "Consolas"); setcolor(WHITE); }
if (bombShockwaveActive) { int currentRadius = (shockwaveRadius * shockwaveAge) / BOMB_SHOCKWAVE_LIFETIME; if (bombShockwaveActive) { int currentRadius = (shockwaveRadius * shockwaveAge) / BOMB_SHOCKWAVE_LIFETIME;
int waveThickness = 10 - (shockwaveAge * 10 / BOMB_SHOCKWAVE_LIFETIME); if (waveThickness < 1) waveThickness = 1; int waveThickness = 10 - (shockwaveAge * 10 / BOMB_SHOCKWAVE_LIFETIME); if (waveThickness < 1) waveThickness = 1;
setcolor(WHITE); setlinestyle(PS_SOLID, waveThickness); circle(shockwaveCenterX + screenShakeOffsetX, shockwaveCenterY + screenShakeOffsetY, currentRadius); setlinestyle(PS_SOLID, 1); } setcolor(WHITE); setlinestyle(PS_SOLID, waveThickness); circle(shockwaveCenterX + screenShakeOffsetX, shockwaveCenterY + screenShakeOffsetY, currentRadius); setlinestyle(PS_SOLID, 1); }
if (gs == OVER) { DrawGameOver(); } else if (gs == PAUSE) { setcolor(WHITE); settextstyle(30, 0, "Arial"); outtextxy(W / 2 - 60 + screenShakeOffsetX, H / 2 + screenShakeOffsetY, "PAUSED"); settextstyle(16, 0, "Consolas"); outtextxy(W / 2 - 80 + screenShakeOffsetX, H / 2 + 40 + screenShakeOffsetY, "Press P to resume"); } if (gs == OVER) { DrawGameOver(); } else if (gs == PAUSE) { setcolor(WHITE); settextstyle(30, 0, "Arial"); outtextxy(W / 2 - 60 + screenShakeOffsetX, H / 2 + screenShakeOffsetY, "PAUSED"); settextstyle(16, 0, "Consolas"); outtextxy(W / 2 - 80 + screenShakeOffsetX, H / 2 + 40 + screenShakeOffsetY, "Press P to resume"); }
EndBatchDraw(); EndBatchDraw();}
bool Hit(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2) { return x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2; return x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2;}
void TriggerScreenShake(int duration, int intensity) { screenShakeTimer = duration; screenShakeOffsetX = (rand() % (intensity * 2 + 1)) - intensity; screenShakeOffsetY = (rand() % (intensity * 2 + 1)) - intensity; screenShakeTimer = duration; screenShakeOffsetX = (rand() % (intensity * 2 + 1)) - intensity; screenShakeOffsetY = (rand() % (intensity * 2 + 1)) - intensity;}
void UseSkill(int skill) { if (skill == SKILL_BOMB && skills.bombEnergy >= 100.0) { bombShockwaveActive = true; shockwaveCenterX = p.x + 10; shockwaveCenterY = p.y + 15; shockwaveRadius = BOMB_SHOCKWAVE_MAX_RADIUS; shockwaveAge = 0; CreateBombWaveParticles(shockwaveCenterX, shockwaveCenterY, 50); if (skill == SKILL_BOMB && skills.bombEnergy >= 100.0) { bombShockwaveActive = true; shockwaveCenterX = p.x + 10; shockwaveCenterY = p.y + 15; shockwaveRadius = BOMB_SHOCKWAVE_MAX_RADIUS; shockwaveAge = 0; CreateBombWaveParticles(shockwaveCenterX, shockwaveCenterY, 50);
TriggerScreenShake(SCREEN_SHAKE_DURATION, 3); TriggerScreenShake(SCREEN_SHAKE_DURATION, 3);
skills.bombEnergy = 0.0; } else if (skill == SKILL_LASER && skills.laserEnergy >= 100.0) { laserActive = true; laserTimer = LASER_DURATION_FRAMES; skills.laserEnergy = 0.0; } else if (skill == SKILL_RAGE && skills.rageEnergy >= 100.0 && !skills.rageActive) { skills.rageActive = true; skills.rageTimer = 600; shanghai += 10.0; skills.rageEnergy = 0.0; } else if (skill == SKILL_HOMING_MISSILE && skills.homingMissileEnergy >= 100.0) { int missilesFired = 0; for (int i = 0; i < MAX_BULLETS && missilesFired < 5; i++) { if (!b[i].live) { b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_HOMING; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2; skills.bombEnergy = 0.0; } else if (skill == SKILL_LASER && skills.laserEnergy >= 100.0) { laserActive = true; laserTimer = LASER_DURATION_FRAMES; skills.laserEnergy = 0.0; } else if (skill == SKILL_RAGE && skills.rageEnergy >= 100.0 && !skills.rageActive) { skills.rageActive = true; skills.rageTimer = 600; shanghai += 10.0; skills.rageEnergy = 0.0; } else if (skill == SKILL_HOMING_MISSILE && skills.homingMissileEnergy >= 100.0) { int missilesFired = 0; for (int i = 0; i < MAX_BULLETS && missilesFired < 5; i++) { if (!b[i].live) { b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_HOMING; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2;
double minDist = DBL_MAX; int closestEnemyIdx = -1; for (int j = 0; j < MAX_ENEMIES; j++) { if (e[j].live) { double dist = sqrt(pow(b[i].x - (e[j].x + e[j].width / 2), 2) + pow(b[i].y - (e[j].y + e[j].height / 2), 2)); if (dist < minDist) { minDist = dist; closestEnemyIdx = j; } } } b[i].targetEnemyIndex = closestEnemyIdx; double minDist = DBL_MAX; int closestEnemyIdx = -1; for (int j = 0; j < MAX_ENEMIES; j++) { if (e[j].live) { double dist = sqrt(pow(b[i].x - (e[j].x + e[j].width / 2), 2) + pow(b[i].y - (e[j].y + e[j].height / 2), 2)); if (dist < minDist) { minDist = dist; closestEnemyIdx = j; } } } b[i].targetEnemyIndex = closestEnemyIdx;
missilesFired++; } } skills.homingMissileEnergy = 0.0; } else if (skill == SKILL_SPREAD_SHOT && skills.spreadShotEnergy >= 100.0) { int centerBulletIdx = -1; for (int i = 0; i < MAX_BULLETS; i++) { if (!b[i].live) { centerBulletIdx = i; b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_SPREAD; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2; break; } } if (centerBulletIdx != -1) { int shotsPerSide = NUM_SPREAD_SHOTS / 2; for (int side = -shotsPerSide; side <= shotsPerSide; side++) { if (side == 0) continue; missilesFired++; } } skills.homingMissileEnergy = 0.0; } else if (skill == SKILL_SPREAD_SHOT && skills.spreadShotEnergy >= 100.0) { int centerBulletIdx = -1; for (int i = 0; i < MAX_BULLETS; i++) { if (!b[i].live) { centerBulletIdx = i; b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_SPREAD; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2; break; } } if (centerBulletIdx != -1) { int shotsPerSide = NUM_SPREAD_SHOTS / 2; for (int side = -shotsPerSide; side <= shotsPerSide; side++) { if (side == 0) continue;
for (int i = 0; i < MAX_BULLETS; i++) { if (!b[i].live) { b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_SPREAD; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2 + (side * SPREAD_SHOT_ANGLE_INCREMENT * M_PI / 180.0); break; } } } } skills.spreadShotEnergy = 0.0; } for (int i = 0; i < MAX_BULLETS; i++) { if (!b[i].live) { b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_SPREAD; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2 + (side * SPREAD_SHOT_ANGLE_INCREMENT * M_PI / 180.0); break; } } } } skills.spreadShotEnergy = 0.0; }}
void Update() { if (GetAsyncKeyState(VK_LEFT) & 0x8000 && p.x > 5) p.x -= 5; if (GetAsyncKeyState(VK_RIGHT) & 0x8000 && p.x < W - 25) p.x += 5; if (GetAsyncKeyState(VK_UP) & 0x8000 && p.y > 5) p.y -= 5; if (GetAsyncKeyState(VK_DOWN) & 0x8000 && p.y < H - 30) p.y += 5; if (GetAsyncKeyState(VK_LEFT) & 0x8000 && p.x > 5) p.x -= 5; if (GetAsyncKeyState(VK_RIGHT) & 0x8000 && p.x < W - 25) p.x += 5; if (GetAsyncKeyState(VK_UP) & 0x8000 && p.y > 5) p.y -= 5; if (GetAsyncKeyState(VK_DOWN) & 0x8000 && p.y < H - 30) p.y += 5;
static bool pPressedLastFrame = false; bool pCurrentState = (GetAsyncKeyState('P') & 0x8000) != 0; if (pCurrentState && !pPressedLastFrame) { if (gs == PLAY) { gs = PAUSE; } else if (gs == PAUSE) { gs = PLAY; } } pPressedLastFrame = pCurrentState; static bool pPressedLastFrame = false; bool pCurrentState = (GetAsyncKeyState('P') & 0x8000) != 0; if (pCurrentState && !pPressedLastFrame) { if (gs == PLAY) { gs = PAUSE; } else if (gs == PAUSE) { gs = PLAY; } } pPressedLastFrame = pCurrentState;
if (gs == PLAY) { static bool fPressedLastFrame = false; static bool zPressedLastFrame = false; static bool xPressedLastFrame = false; static bool hPressedLastFrame = false; static bool gPressedLastFrame = false; if (gs == PLAY) { static bool fPressedLastFrame = false; static bool zPressedLastFrame = false; static bool xPressedLastFrame = false; static bool hPressedLastFrame = false; static bool gPressedLastFrame = false;
bool fCurrentState = (GetAsyncKeyState('F') & 0x8000) != 0; bool zCurrentState = (GetAsyncKeyState('Z') & 0x8000) != 0; bool xCurrentState = (GetAsyncKeyState('X') & 0x8000) != 0; bool hCurrentState = (GetAsyncKeyState('H') & 0x8000) != 0; bool gCurrentState = (GetAsyncKeyState('G') & 0x8000) != 0; bool fCurrentState = (GetAsyncKeyState('F') & 0x8000) != 0; bool zCurrentState = (GetAsyncKeyState('Z') & 0x8000) != 0; bool xCurrentState = (GetAsyncKeyState('X') & 0x8000) != 0; bool hCurrentState = (GetAsyncKeyState('H') & 0x8000) != 0; bool gCurrentState = (GetAsyncKeyState('G') & 0x8000) != 0;
if (fCurrentState && !fPressedLastFrame && skills.bombEnergy >= 100.0 && !bombShockwaveActive) { UseSkill(SKILL_BOMB); } if (zCurrentState && !zPressedLastFrame && skills.laserEnergy >= 100.0 && !laserActive) { UseSkill(SKILL_LASER); } if (xCurrentState && !xPressedLastFrame && skills.rageEnergy >= 100.0 && !skills.rageActive) { UseSkill(SKILL_RAGE); } if (hCurrentState && !hPressedLastFrame && skills.homingMissileEnergy >= 100.0) { UseSkill(SKILL_HOMING_MISSILE); } if (gCurrentState && !gPressedLastFrame && skills.spreadShotEnergy >= 100.0) { UseSkill(SKILL_SPREAD_SHOT); } if (fCurrentState && !fPressedLastFrame && skills.bombEnergy >= 100.0 && !bombShockwaveActive) { UseSkill(SKILL_BOMB); } if (zCurrentState && !zPressedLastFrame && skills.laserEnergy >= 100.0 && !laserActive) { UseSkill(SKILL_LASER); } if (xCurrentState && !xPressedLastFrame && skills.rageEnergy >= 100.0 && !skills.rageActive) { UseSkill(SKILL_RAGE); } if (hCurrentState && !hPressedLastFrame && skills.homingMissileEnergy >= 100.0) { UseSkill(SKILL_HOMING_MISSILE); } if (gCurrentState && !gPressedLastFrame && skills.spreadShotEnergy >= 100.0) { UseSkill(SKILL_SPREAD_SHOT); }
fPressedLastFrame = fCurrentState; zPressedLastFrame = zCurrentState; xPressedLastFrame = xCurrentState; hPressedLastFrame = hCurrentState; gPressedLastFrame = gCurrentState; } fPressedLastFrame = fCurrentState; zPressedLastFrame = zCurrentState; xPressedLastFrame = xCurrentState; hPressedLastFrame = hCurrentState; gPressedLastFrame = gCurrentState; }
static DWORD lastShotTime = 0; if ((GetAsyncKeyState(VK_SPACE) & 0x8000) && GetTickCount() - lastShotTime > 150 && !laserActive && !bombShockwaveActive) { for (int i = 0; i < MAX_BULLETS; i++) { if (!b[i].live) { b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_NORMAL; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2; break; } } lastShotTime = GetTickCount(); } static DWORD lastShotTime = 0; if ((GetAsyncKeyState(VK_SPACE) & 0x8000) && GetTickCount() - lastShotTime > 150 && !laserActive && !bombShockwaveActive) { for (int i = 0; i < MAX_BULLETS; i++) { if (!b[i].live) { b[i].x = p.x + 8; b[i].y = p.y; b[i].live = true; b[i].shooterType = 0; b[i].direction = 0; b[i].type = BULLET_NORMAL; b[i].targetEnemyIndex = -1; b[i].angle = -M_PI / 2; break; } } lastShotTime = GetTickCount(); }
if (laserActive) { for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { e[i].hp -= (int)(shanghai * 3.0); if (e[i].hp <= 0) { sc += 5 * lv * e[i].initialHp; combo++; comboTimer = COMBO_TIMEOUT_FRAMES; CreateExplosion(e[i].x + e[i].width / 2, e[i].y + e[i].height / 2); e[i].live = false; } } } laserTimer--; if (laserTimer <= 0) { laserActive = false; } } if (laserActive) { for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { e[i].hp -= (int)(shanghai * 3.0); if (e[i].hp <= 0) { sc += 5 * lv * e[i].initialHp; combo++; comboTimer = COMBO_TIMEOUT_FRAMES; CreateExplosion(e[i].x + e[i].width / 2, e[i].y + e[i].height / 2); e[i].live = false; } } } laserTimer--; if (laserTimer <= 0) { laserActive = false; } }
if (bombShockwaveActive) { shockwaveAge++; if (shockwaveAge >= BOMB_SHOCKWAVE_LIFETIME) { bombShockwaveActive = false; if (bombShockwaveActive) { shockwaveAge++; if (shockwaveAge >= BOMB_SHOCKWAVE_LIFETIME) { bombShockwaveActive = false;
for (int id : enemiesHitByBomb) { if (e[id].live) { sc += 5 * lv * e[id].initialHp; combo++; comboTimer = COMBO_TIMEOUT_FRAMES; CreateExplosion(e[id].x + e[id].width / 2, e[id].y + e[id].height / 2); for (int id : enemiesHitByBomb) { if (e[id].live) { sc += 5 * lv * e[id].initialHp; combo++; comboTimer = COMBO_TIMEOUT_FRAMES; CreateExplosion(e[id].x + e[id].width / 2, e[id].y + e[id].height / 2);
skills.bombEnergy += 10.0; skills.laserEnergy += 8.0; skills.rageEnergy += 5.0; skills.bombEnergy += 10.0; skills.laserEnergy += 8.0; skills.rageEnergy += 5.0;
if (skills.bombEnergy > 100.0) skills.bombEnergy = 100.0; if (skills.laserEnergy > 100.0) skills.laserEnergy = 100.0; if (skills.rageEnergy > 100.0) skills.rageEnergy = 100.0; if (skills.bombEnergy > 100.0) skills.bombEnergy = 100.0; if (skills.laserEnergy > 100.0) skills.laserEnergy = 100.0; if (skills.rageEnergy > 100.0) skills.rageEnergy = 100.0;
e[id].live = false; e[id].live = false;
if (e[id].type == ENEMY_BOSS) { achievements[2].unlocked = achievements[2].checkCondition(); } } } enemiesHitByBomb.clear(); } else { int currentRadius = (shockwaveRadius * shockwaveAge) / BOMB_SHOCKWAVE_LIFETIME; for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { int dx = (e[i].x + e[i].width / 2) - shockwaveCenterX; int dy = (e[i].y + e[i].height / 2) - shockwaveCenterY; double distance = sqrt(dx * dx + dy * dy); if (e[id].type == ENEMY_BOSS) { achievements[2].unlocked = achievements[2].checkCondition(); } } } enemiesHitByBomb.clear(); } else { int currentRadius = (shockwaveRadius * shockwaveAge) / BOMB_SHOCKWAVE_LIFETIME; for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { int dx = (e[i].x + e[i].width / 2) - shockwaveCenterX; int dy = (e[i].y + e[i].height / 2) - shockwaveCenterY; double distance = sqrt(dx * dx + dy * dy);
if (distance <= currentRadius) { bool alreadyRecorded = false; for (int recordedId : enemiesHitByBomb) { if (recordedId == i) { alreadyRecorded = true; break; } } if (!alreadyRecorded) { enemiesHitByBomb.push_back(i); CreateExplosion(e[i].x + e[i].width / 2, e[i].y + e[i].height / 2); } } } } } } if (distance <= currentRadius) { bool alreadyRecorded = false; for (int recordedId : enemiesHitByBomb) { if (recordedId == i) { alreadyRecorded = true; break; } } if (!alreadyRecorded) { enemiesHitByBomb.push_back(i); CreateExplosion(e[i].x + e[i].width / 2, e[i].y + e[i].height / 2); } } } } } }
if (screenShakeTimer > 0) { screenShakeTimer--; if (screenShakeTimer > 0) { screenShakeOffsetX = (rand() % 7) - 3; screenShakeOffsetY = (rand() % 7) - 3; } else { screenShakeOffsetX = 0; screenShakeOffsetY = 0; } } if (screenShakeTimer > 0) { screenShakeTimer--; if (screenShakeTimer > 0) { screenShakeOffsetX = (rand() % 7) - 3; screenShakeOffsetY = (rand() % 7) - 3; } else { screenShakeOffsetX = 0; screenShakeOffsetY = 0; } }
if (comboTimer > 0) { comboTimer--; } else { if (combo > 1) { combo = 0; } } if (comboTimer > 0) { comboTimer--; } else { if (combo > 1) { combo = 0; } }
if (bossWarningTimer > 0) { bossWarningTimer--; } if (bossWarningTimer > 0) { bossWarningTimer--; }
for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live) { if (b[i].type == BULLET_HOMING) { if (b[i].targetEnemyIndex != -1 && e[b[i].targetEnemyIndex].live) { int targetX = e[b[i].targetEnemyIndex].x + e[b[i].targetEnemyIndex].width / 2; int targetY = e[b[i].targetEnemyIndex].y + e[b[i].targetEnemyIndex].height / 2; for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live) { if (b[i].type == BULLET_HOMING) { if (b[i].targetEnemyIndex != -1 && e[b[i].targetEnemyIndex].live) { int targetX = e[b[i].targetEnemyIndex].x + e[b[i].targetEnemyIndex].width / 2; int targetY = e[b[i].targetEnemyIndex].y + e[b[i].targetEnemyIndex].height / 2;
double targetAngle = atan2(targetY - b[i].y, targetX - b[i].x); double targetAngle = atan2(targetY - b[i].y, targetX - b[i].x);
double angleDiff = targetAngle - b[i].angle; while (angleDiff > M_PI) angleDiff -= 2 * M_PI; while (angleDiff < -M_PI) angleDiff += 2 * M_PI; double angleDiff = targetAngle - b[i].angle; while (angleDiff > M_PI) angleDiff -= 2 * M_PI; while (angleDiff < -M_PI) angleDiff += 2 * M_PI;
double maxTurn = 0.1; if (angleDiff > maxTurn) angleDiff = maxTurn; if (angleDiff < -maxTurn) angleDiff = -maxTurn; double maxTurn = 0.1; if (angleDiff > maxTurn) angleDiff = maxTurn; if (angleDiff < -maxTurn) angleDiff = -maxTurn;
b[i].angle += angleDiff; } b[i].angle += angleDiff; }
b[i].x += cos(b[i].angle) * HOMING_MISSILE_SPEED; b[i].y += sin(b[i].angle) * HOMING_MISSILE_SPEED; b[i].x += cos(b[i].angle) * HOMING_MISSILE_SPEED; b[i].y += sin(b[i].angle) * HOMING_MISSILE_SPEED;
if (b[i].x < -10 || b[i].x > W + 10 || b[i].y < -10 || b[i].y > H + 10) { b[i].live = false; } } else if (b[i].type == BULLET_SPREAD) { b[i].x += cos(b[i].angle) * 8; b[i].y += sin(b[i].angle) * 8; if (b[i].x < -10 || b[i].x > W + 10 || b[i].y < -10 || b[i].y > H + 10) { b[i].live = false; } } else if (b[i].type == BULLET_SPREAD) { b[i].x += cos(b[i].angle) * 8; b[i].y += sin(b[i].angle) * 8;
if (b[i].x < -10 || b[i].x > W + 10 || b[i].y < -10 || b[i].y > H + 10) { b[i].live = false; } } else { if (b[i].direction == 0) { b[i].y -= 8; } else { b[i].y += 8; } if (b[i].y < -10 || b[i].y > H + 10) b[i].live = false; } } } if (b[i].x < -10 || b[i].x > W + 10 || b[i].y < -10 || b[i].y > H + 10) { b[i].live = false; } } else { if (b[i].direction == 0) { b[i].y -= 8; } else { b[i].y += 8; } if (b[i].y < -10 || b[i].y > H + 10) b[i].live = false; } } }
const int ENEMY_SPAWN_RATE = 60; if (ec++ % ENEMY_SPAWN_RATE == 0) { for (int i = 0; i < MAX_ENEMIES; i++) { if (!e[i].live) { if (lv >= BOSS_LEVEL && !bossSpawnedThisLevel) { e[i].x = W / 2 - 50; e[i].y = -60; e[i].live = true; e[i].type = ENEMY_BOSS; e[i].hp = 200 + lv * 30; e[i].initialHp = e[i].hp; e[i].width = 100; e[i].height = 60; e[i].laserTimer = 0; e[i].isFiringLaser = false; e[i].targetX = rand() % (W - e[i].width); e[i].shootTimer = 0; const int ENEMY_SPAWN_RATE = 60; if (ec++ % ENEMY_SPAWN_RATE == 0) { for (int i = 0; i < MAX_ENEMIES; i++) { if (!e[i].live) { if (lv % BOSS_LEVEL == 0 && !bossSpawnedThisLevel) { e[i].x = W / 2 - 50; e[i].y = -60; e[i].live = true; e[i].type = ENEMY_BOSS; e[i].hp = 200 + lv * 30; e[i].initialHp = e[i].hp; e[i].width = 100; e[i].height = 60; e[i].laserTimer = 0; e[i].isFiringLaser = false; e[i].targetX = rand() % (W - e[i].width); e[i].shootTimer = 0;
bossSpawnedThisLevel = true; bossSpawnedThisLevel = true;
strcpy(bossWarningText, "BOSS APPEARS!"); bossWarningTimer = 120; break; } else { e[i].x = rand() % (W - 30); e[i].y = -30; e[i].live = true; e[i].type = ENEMY_NORMAL; e[i].hp = rand() % 11 + 20 + lv; e[i].initialHp = e[i].hp; e[i].width = 30; e[i].height = 30; e[i].laserTimer = 0; e[i].isFiringLaser = false; e[i].targetX = 0; e[i].shootTimer = 0; break; } } } } strcpy(bossWarningText, "BOSS APPEARS!"); bossWarningTimer = 120; break; } else { e[i].x = rand() % (W - 30); e[i].y = -30; e[i].live = true; e[i].type = ENEMY_NORMAL; e[i].hp = rand() % 11 + 20 + lv; e[i].initialHp = e[i].hp; e[i].width = 30; e[i].height = 30; e[i].laserTimer = 0; e[i].isFiringLaser = false; e[i].targetX = 0; e[i].shootTimer = 0; break; } } } }
if (bossSpawnedThisLevel) { for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type == ENEMY_BOSS) { if (abs(e[i].x - e[i].targetX) < 2) { e[i].targetX = rand() % (W - e[i].width); } else { if (e[i].x < e[i].targetX) { e[i].x += 1; } else if (e[i].x > e[i].targetX) { e[i].x -= 1; } } e[i].y = 50; if (bossSpawnedThisLevel) { for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type == ENEMY_BOSS) { if (abs(e[i].x - e[i].targetX) < 2) { e[i].targetX = rand() % (W - e[i].width); } else { if (e[i].x < e[i].targetX) { e[i].x += 1; } else if (e[i].x > e[i].targetX) { e[i].x -= 1; } } e[i].y = 50;
e[i].laserTimer++; if (e[i].laserTimer > BOSS_ATTACK_INTERVAL_FRAMES && !e[i].isFiringLaser) { e[i].isFiringLaser = true; e[i].laserTimer = 0; if (screenShakeTimer <= 0) { TriggerScreenShake(5, 1); } } e[i].laserTimer++; if (e[i].laserTimer > BOSS_ATTACK_INTERVAL_FRAMES && !e[i].isFiringLaser) { e[i].isFiringLaser = true; e[i].laserTimer = 0; if (screenShakeTimer <= 0) { TriggerScreenShake(5, 1); } }
if (e[i].isFiringLaser) { e[i].laserTimer++; if (e[i].laserTimer >= BOSS_LASER_DURATION_FRAMES) { e[i].isFiringLaser = false; } } break; } } } if (e[i].isFiringLaser) { e[i].laserTimer++; if (e[i].laserTimer >= BOSS_LASER_DURATION_FRAMES) { e[i].isFiringLaser = false; } } break; } } }
for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type == ENEMY_NORMAL) { e[i].shootTimer++; if (e[i].shootTimer > ENEMY_SHOOT_INTERVAL_FRAMES) { e[i].shootTimer = 0; for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type == ENEMY_NORMAL) { e[i].shootTimer++; if (e[i].shootTimer > ENEMY_SHOOT_INTERVAL_FRAMES) { e[i].shootTimer = 0;
for (int j = 0; j < MAX_BULLETS; j++) { if (!b[j].live) { b[j].x = e[i].x + e[i].width / 2 - 2; b[j].y = e[i].y + e[i].height; b[j].live = true; b[j].shooterType = 1; b[j].direction = 1; b[j].type = BULLET_NORMAL; b[j].targetEnemyIndex = -1; b[j].angle = M_PI / 2; break; } } } } } for (int j = 0; j < MAX_BULLETS; j++) { if (!b[j].live) { b[j].x = e[i].x + e[i].width / 2 - 2; b[j].y = e[i].y + e[i].height; b[j].live = true; b[j].shooterType = 1; b[j].direction = 1; b[j].type = BULLET_NORMAL; b[j].targetEnemyIndex = -1; b[j].angle = M_PI / 2; break; } } } } }
for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { if (e[i].type == ENEMY_BOSS) { } else { e[i].y += 2; } if (e[i].y > H) e[i].live = false; } } for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live) { if (e[i].type == ENEMY_BOSS) { } else { e[i].y += 2; } if (e[i].y > H) e[i].live = false; } }
for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type == ENEMY_BOSS && e[i].isFiringLaser) { int laserLeft = e[i].x + 5; int laserRight = e[i].x + e[i].width - 5; int laserTop = e[i].y + e[i].height; for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type == ENEMY_BOSS && e[i].isFiringLaser) { int laserLeft = e[i].x + 5; int laserRight = e[i].x + e[i].width - 5; int laserTop = e[i].y + e[i].height;
int playerCenterX = p.x + 10; int playerCenterY = p.y + 15; int playerCenterX = p.x + 10; int playerCenterY = p.y + 15;
if (playerCenterX >= laserLeft && playerCenterX <= laserRight && playerCenterY >= laserTop) { p.hp -= 1; if (playerCenterX >= laserLeft && playerCenterX <= laserRight && playerCenterY >= laserTop) { p.hp -= 1;
CreateBleedingParticles(p.x + 10, p.y + 15, 2); CreateBleedingParticles(p.x + 10, p.y + 15, 2);
if (p.hp <= 0) { CreateExplosion(p.x + 10, p.y + 15); Sleep(1000); gs = OVER; gameOverTime = GetTickCount(); } } } } if (p.hp <= 0) { CreateExplosion(p.x + 10, p.y + 15); Sleep(1000); gs = OVER; gameOverTime = GetTickCount(); } } } }
if (!laserActive && !bombShockwaveActive) { for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live && b[i].shooterType == 0) { for (int j = 0; j < MAX_ENEMIES; j++) { if (e[j].live && Hit(b[i].x, b[i].y, 4, 10, e[j].x, e[j].y, e[j].width, e[j].height)) { b[i].live = false; e[j].hp -= (int)shanghai; if (!laserActive && !bombShockwaveActive) { for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live && b[i].shooterType == 0) { for (int j = 0; j < MAX_ENEMIES; j++) { if (e[j].live && Hit(b[i].x, b[i].y, 4, 10, e[j].x, e[j].y, e[j].width, e[j].height)) { b[i].live = false; int damage = (int)shanghai; if (b[i].type == BULLET_SPREAD) { damage *= 2; } e[j].hp -= damage;
if (e[j].hp > 0) { CreateBleedingParticles(e[j].x + e[j].width / 2, e[j].y + e[j].height / 2, 3); } if (e[j].hp > 0) { CreateBleedingParticles(e[j].x + e[j].width / 2, e[j].y + e[j].height / 2, 3); }
if (e[j].hp <= 0) { e[j].live = false; sc += 5 * lv * e[j].initialHp; if (e[j].hp <= 0) { e[j].live = false; sc += 3 * lv * e[j].initialHp;
combo++; comboTimer = COMBO_TIMEOUT_FRAMES; combo++; comboTimer = COMBO_TIMEOUT_FRAMES;
skills.bombEnergy += 10.0; skills.laserEnergy += 8.0; skills.rageEnergy += 5.0; skills.homingMissileEnergy += 10.0; skills.spreadShotEnergy += 10.0; skills.bombEnergy += 10.0; skills.laserEnergy += 8.0; skills.rageEnergy += 5.0; skills.homingMissileEnergy += 10.0; skills.spreadShotEnergy += 10.0;
if (skills.bombEnergy > 100.0) skills.bombEnergy = 100.0; if (skills.laserEnergy > 100.0) skills.laserEnergy = 100.0; if (skills.rageEnergy > 100.0) skills.rageEnergy = 100.0; if (skills.homingMissileEnergy > 100.0) skills.homingMissileEnergy = 100.0; if (skills.spreadShotEnergy > 100.0) skills.spreadShotEnergy = 100.0; if (skills.bombEnergy > 100.0) skills.bombEnergy = 100.0; if (skills.laserEnergy > 100.0) skills.laserEnergy = 100.0; if (skills.rageEnergy > 100.0) skills.rageEnergy = 100.0; if (skills.homingMissileEnergy > 100.0) skills.homingMissileEnergy = 100.0; if (skills.spreadShotEnergy > 100.0) skills.spreadShotEnergy = 100.0;
CreateExplosion(e[j].x + e[j].width / 2, e[j].y + e[j].height / 2); CreateExplosion(e[j].x + e[j].width / 2, e[j].y + e[j].height / 2);
if (sc >= lv * 150) { lv++; shanghai += 1; shanghai = min(lv / 2 + 1, (int)shanghai); } if (sc >= lv * 150) { lv++; shanghai += 1; shanghai = min(lv / 2 + 1, (int)shanghai); }
achievements[0].unlocked = achievements[0].checkCondition(); achievements[1].unlocked = achievements[1].checkCondition(); if (e[j].type == ENEMY_BOSS) { achievements[2].unlocked = achievements[2].checkCondition(); } } break; } } } } } achievements[0].unlocked = achievements[0].checkCondition(); achievements[1].unlocked = achievements[1].checkCondition(); if (e[j].type == ENEMY_BOSS) { achievements[2].unlocked = achievements[2].checkCondition(); } } break; } } } } }
if (!bombShockwaveActive) { for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live && (b[i].shooterType == 1 || b[i].shooterType == 2) && b[i].direction == 1) { if (Hit(p.x, p.y, 20, 30, b[i].x, b[i].y, 4, 10)) { b[i].live = false; p.hp -= 1; if (!bombShockwaveActive) { for (int i = 0; i < MAX_BULLETS; i++) { if (b[i].live && (b[i].shooterType == 1 || b[i].shooterType == 2) && b[i].direction == 1) { if (Hit(p.x, p.y, 20, 30, b[i].x, b[i].y, 4, 10)) { b[i].live = false; p.hp -= 1;
CreateBleedingParticles(p.x + 10, p.y + 15, 10); CreateBleedingParticles(p.x + 10, p.y + 15, 10);
if (screenShakeTimer <= 0) { TriggerScreenShake(5, 1); } if (screenShakeTimer <= 0) { TriggerScreenShake(5, 1); }
if (p.hp <= 0) { CreateExplosion(p.x + 10, p.y + 15); Sleep(1000); gs = OVER; gameOverTime = GetTickCount(); } } } } } if (p.hp <= 0) { CreateExplosion(p.x + 10, p.y + 15); Sleep(1000); gs = OVER; gameOverTime = GetTickCount(); } } } } }
if (!bombShockwaveActive) { for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && Hit(p.x, p.y, 20, 30, e[i].x, e[i].y, e[i].width, e[i].height)) { e[i].live = false; p.hp -= 1; if (!bombShockwaveActive) { for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && Hit(p.x, p.y, 20, 30, e[i].x, e[i].y, e[i].width, e[i].height)) { e[i].live = false; p.hp -= 1;
CreateBleedingParticles(p.x + 10, p.y + 15, 10); CreateBleedingParticles(p.x + 10, p.y + 15, 10);
if (screenShakeTimer <= 0) { TriggerScreenShake(5, 1); } if (screenShakeTimer <= 0) { TriggerScreenShake(5, 1); }
if (p.hp <= 0) { CreateExplosion(p.x + 10, p.y + 15); Sleep(1000); gs = OVER; gameOverTime = GetTickCount(); } } } } if (p.hp <= 0) { CreateExplosion(p.x + 10, p.y + 15); Sleep(1000); gs = OVER; gameOverTime = GetTickCount(); } } } }
if (rand() % 100 == 0) { for (int i = 0; i < MAX_POWERUPS; i++) { if (!pu[i].live) { pu[i].x = rand() % (W - 12) + 6; pu[i].y = -10; pu[i].live = true; pu[i].type = rand() % 3; break; } } } if (rand() % 100 == 0) { for (int i = 0; i < MAX_POWERUPS; i++) { if (!pu[i].live) { pu[i].x = rand() % (W - 12) + 6; pu[i].y = -10; pu[i].live = true; pu[i].type = rand() % 3; break; } } }
for (int i = 0; i < MAX_POWERUPS; i++) { if (pu[i].live) { pu[i].y += 3; if (pu[i].y > H + 10) pu[i].live = false; for (int i = 0; i < MAX_POWERUPS; i++) { if (pu[i].live) { pu[i].y += 3; if (pu[i].y > H + 10) pu[i].live = false;
if (Hit(p.x, p.y, 20, 30, pu[i].x - 6, pu[i].y - 6, 12, 12)) { switch (pu[i].type) { case POWERUP_ATTACK: shanghai *= 1.05; break; case POWERUP_HP: p.hp += 2; if (p.hp > p.maxHp) p.hp = p.maxHp; break; case POWERUP_BOMB: skills.bombEnergy += 30.0; if (skills.bombEnergy > 100.0) skills.bombEnergy = 100.0; break; } pu[i].live = false; } } } if (Hit(p.x, p.y, 20, 30, pu[i].x - 6, pu[i].y - 6, 12, 12)) { switch (pu[i].type) { case POWERUP_ATTACK: shanghai *= 1.05; break; case POWERUP_HP: p.hp += 2; if (p.hp > p.maxHp) p.hp = p.maxHp; break; case POWERUP_BOMB: skills.bombEnergy += 30.0; if (skills.bombEnergy > 100.0) skills.bombEnergy = 100.0; break; } pu[i].live = false; } } }
if (skills.rageActive) { skills.rageTimer--; if (skills.rageTimer <= 0) { skills.rageActive = false; shanghai -= 10.0; } } if (skills.rageActive) { skills.rageTimer--; if (skills.rageTimer <= 0) { skills.rageActive = false; shanghai -= 10.0; } }
if (gs == PLAY && !bombShockwaveActive) { if (rand() % 2 == 0) { CreateJetTrail(p.x + 5, p.y + 30, 1); } if (rand() % 2 == 0) { CreateJetTrail(p.x + 15, p.y + 30, 1); } if (gs == PLAY && !bombShockwaveActive) { if (rand() % 2 == 0) { CreateJetTrail(p.x + 5, p.y + 30, 1); } if (rand() % 2 == 0) { CreateJetTrail(p.x + 15, p.y + 30, 1); }
for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type != ENEMY_BOSS && rand() % 3 == 0) { CreateJetTrail(e[i].x + e[i].width / 4, e[i].y, 1); } if (e[i].live && e[i].type != ENEMY_BOSS && rand() % 3 == 0) { CreateJetTrail(e[i].x + 3 * e[i].width / 4, e[i].y, 1); } } } for (int i = 0; i < MAX_ENEMIES; i++) { if (e[i].live && e[i].type != ENEMY_BOSS && rand() % 3 == 0) { CreateJetTrail(e[i].x + e[i].width / 4, e[i].y, 1); } if (e[i].live && e[i].type != ENEMY_BOSS && rand() % 3 == 0) { CreateJetTrail(e[i].x + 3 * e[i].width / 4, e[i].y, 1); } } }
UpdateExplosions(); UpdateExplosions();}
int main() { initgraph(W, H); initgraph(W, H);
DWORD lastTime = GetTickCount(); while (true) { DWORD currentTime = GetTickCount(); if (currentTime - lastTime >= MS_PER_FRAME) { if (gs == START) { if (GetAsyncKeyState(VK_SPACE) & 0x8000) { gs = PLAY; InitGame(); } } else if (gs == OVER) { if (currentTime - gameOverTime >= 2000) { gs = START; } } else if (gs == PAUSE) { if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) { break; } } else { if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) { break; } } DWORD lastTime = GetTickCount(); while (true) { DWORD currentTime = GetTickCount(); if (currentTime - lastTime >= MS_PER_FRAME) { if (gs == START) { if (GetAsyncKeyState(VK_SPACE) & 0x8000) { gs = PLAY; InitGame(); } } else if (gs == OVER) { if (currentTime - gameOverTime >= 2000) { gs = START; } } else if (gs == PAUSE) { if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) { break; } } else { if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) { break; } }
switch (gs) { case START: DrawStart(); break; case PLAY: Update(); GameDraw(); break; case OVER: GameDraw(); break; case PAUSE: GameDraw(); break; } lastTime = currentTime; } Sleep(1); } closegraph(); return 0; switch (gs) { case START: DrawStart(); break; case PLAY: Update(); GameDraw(); break; case OVER: GameDraw(); break; case PAUSE: GameDraw(); break; } lastTime = currentTime; } Sleep(1); } closegraph(); return 0;}```
::::
# 游戏界面概览## 开始
## 游戏时
## BOSS
## 去世
其它功能请自行安装尝试如果有建议请在评论区给出