📄 shop.cpp
字号:
shopItems[8].price = 250; strcpy(shopItems[8].name, "Plasma compressor"); strcpy(shopItems[8].description, "Increases plasma ammo capacity"); shopItems[8].image = 17; shopItems[9].price = 250; strcpy(shopItems[9].name, "Rocket Pod"); strcpy(shopItems[9].description, "Allows for an additional 5 rockets to be carried"); shopItems[9].image = 18; /* ---------- Weaponary --------------- */ shopItems[10].price = 2000; strcpy(shopItems[10].name, "Dual Rocket Launcher"); strcpy(shopItems[10].description, "Allows for two rockets to be fired at once"); shopItems[10].image = 19; shopItems[11].price = 2500; strcpy(shopItems[11].name, "Micro Rocket Launcher"); strcpy(shopItems[11].description, "Launches several less powerful rockets at once"); shopItems[11].image = 20; shopItems[12].price = 5000; strcpy(shopItems[12].name, "Laser Cannon"); strcpy(shopItems[12].description, "Laser Cannon"); shopItems[12].image = 21; shopItems[13].price = 7500; strcpy(shopItems[13].name, "Homing Missile Launcher"); strcpy(shopItems[13].description, "Fires homing missile"); shopItems[13].image = 22; shopItems[14].price = 10000; strcpy(shopItems[14].name, "Charge Cannon"); strcpy(shopItems[14].description, "A charge up cannon"); shopItems[14].image = 23; shopItems[15].price = 20000; strcpy(shopItems[15].name, "Dual Homing Missile Launcher"); strcpy(shopItems[15].description, "Fires two homing missiles"); shopItems[15].image = 24; shopItems[16].price = 25000; strcpy(shopItems[16].name, "Homing Micro Missile Launcher"); strcpy(shopItems[16].description, "Fires several small homing missiles"); shopItems[16].image = 25; for (int i = 0 ; i < 3 ; i++) { shopItems[i].x = 100 + (i * 50); shopItems[i].y = 200; } shopItems[3].x = 350; shopItems[3].y = 200; shopItems[4].x = 400; shopItems[4].y = 200; for (int i = 0 ; i < 3 ; i++) { shopItems[i + 5].x = 100 + (i * 50); shopItems[i + 5].y = 260; } for (int i = 0 ; i < 2 ; i++) { shopItems[i + 8].x = 450 + (i * 50); shopItems[i + 8].y = 200; } for (int i = 0 ; i < 8 ; i++) { shopItems[i + 10].x = 350 + (i * 50); shopItems[i + 10].y = 260; } shopSelectedItem = -1; player.image[0] = graphics.shape[0]; player.x = 380; player.y = 95; saveShop(); drawShop();}#endifvoid buy(int i){ if ((currentGame.cash < shopItems[i].price) && (!engine.cheatCash)) { shopSelectedItem = -2; drawShop(); return; } switch(i) { case 0: if (currentGame.maxPlasmaOutput == 5) {shopSelectedItem = -3; return;} currentGame.maxPlasmaOutput++; break; case 1: if (currentGame.maxPlasmaDamage == 5) {shopSelectedItem = -3; return;} currentGame.maxPlasmaDamage++; break; case 2: if (currentGame.maxPlasmaRate == 7) {shopSelectedItem = -3; return;} currentGame.maxPlasmaRate -= 2; break; case 3: if (player.ammo[0] == currentGame.maxPlasmaAmmo) {shopSelectedItem = -4; return;} Math::limitChar(&(player.ammo[0] += 10), 0, currentGame.maxPlasmaAmmo); break; case 4: if ((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER)) {shopSelectedItem = -7; return;} if (player.ammo[1] == currentGame.maxRocketAmmo) {shopSelectedItem = -4; return;} if ((player.weaponType[1] == W_HOMING_MISSILE) && (player.ammo[1] == 20)) {shopSelectedItem = -9; return;} if ((player.weaponType[1] == W_DOUBLE_HOMING_MISSILES) && (player.ammo[1] == 10)) {shopSelectedItem = -9; return;} if ((player.weaponType[1] == W_MICRO_HOMING_MISSILES) && (player.ammo[1] == 10)) {shopSelectedItem = -9; return;} player.ammo[1]++; break; case 5: if (weapon[0].ammo[0] == 3) {shopSelectedItem = -3; return;} weapon[0].ammo[0]++; if (currentGame.maxPlasmaOutput < weapon[0].ammo[0]) currentGame.maxPlasmaOutput = weapon[0].ammo[0]; break; case 6: if (weapon[0].damage == 3) {shopSelectedItem = -3; return;} weapon[0].damage++; if (currentGame.maxPlasmaDamage < weapon[0].damage) currentGame.maxPlasmaDamage = weapon[0].damage; break; case 7: if (weapon[0].reload[0] == 11) {shopSelectedItem = -3; return;} weapon[0].reload[0] -= 2; if (currentGame.maxPlasmaRate > weapon[0].reload[0]) currentGame.maxPlasmaRate = weapon[0].reload[0]; break; case 8: if (currentGame.maxPlasmaAmmo == 250) {shopSelectedItem = -3; return;} Math::limitChar(&(currentGame.maxPlasmaAmmo += 10), 0, 250); break; case 9: if ((player.weaponType[1] == W_CHARGER) || (player.weaponType[1] == W_LASER)) {shopSelectedItem = -7; return;} if (currentGame.maxRocketAmmo == 50) {shopSelectedItem = -3; return;} currentGame.maxRocketAmmo += 5; break; case 10: if (player.weaponType[1] == W_DOUBLE_ROCKETS) {shopSelectedItem = -8; return;} player.weaponType[1] = W_DOUBLE_ROCKETS; shopSelectedItem = -1; break; case 11: if (player.weaponType[1] == W_MICRO_ROCKETS) {shopSelectedItem = -8; return;} player.weaponType[1] = W_MICRO_ROCKETS; shopSelectedItem = -1; break; case 12: if (player.weaponType[1] == W_LASER) {shopSelectedItem = -8; return;} player.weaponType[1] = W_LASER; player.ammo[1] = 0; shopSelectedItem = -1; break; case 13: if (player.weaponType[1] == W_HOMING_MISSILE) {shopSelectedItem = -8; return;} player.weaponType[1] = W_HOMING_MISSILE; Math::limitChar(&player.ammo[1], 0, 20); shopSelectedItem = -1; break; case 14: if (player.weaponType[1] == W_CHARGER) {shopSelectedItem = -8; return;} player.weaponType[1] = W_CHARGER; player.ammo[1] = 0; shopSelectedItem = -1; break; case 15: if (player.weaponType[1] == W_DOUBLE_HOMING_MISSILES) {shopSelectedItem = -8; return;} player.weaponType[1] = W_DOUBLE_HOMING_MISSILES; Math::limitChar(&player.ammo[1], 0, 10); shopSelectedItem = -1; break; case 16: if (player.weaponType[1] == W_MICRO_HOMING_MISSILES) {shopSelectedItem = -8; return;} player.weaponType[1] = W_MICRO_HOMING_MISSILES; Math::limitChar(&player.ammo[1], 0, 10); shopSelectedItem = -1; break; } if (!engine.cheatCash) currentGame.cash -= shopItems[i].price;}void sell(int i){ switch (i) { case 0: if (currentGame.maxPlasmaOutput == 2) {shopSelectedItem = -5; return;} currentGame.maxPlasmaOutput--; break; case 1: if (currentGame.maxPlasmaDamage == 2) {shopSelectedItem = -5; return;} currentGame.maxPlasmaDamage--; break; case 2: if (currentGame.maxPlasmaRate == 13) {shopSelectedItem = -5; return;} currentGame.maxPlasmaRate += 2; break; case 3: if (player.ammo[0] == 0) {shopSelectedItem = -6; return;} if (player.ammo[0] > 9) Math::limitChar(&(player.ammo[0] -= 10), 0, currentGame.maxPlasmaAmmo); else player.ammo[0] = 0; break; case 4: if (player.ammo[1] == 0) {shopSelectedItem = -6; return;} player.ammo[1]--; break; case 5: if (weapon[0].ammo[0] == 1) {shopSelectedItem = -5; return;} weapon[0].ammo[0]--; break; case 6: if (weapon[0].damage == 1) {shopSelectedItem = -5; return;} weapon[0].damage--; break; case 7: if (weapon[0].reload[0] == 15) {shopSelectedItem = -5; return;} weapon[0].reload[0] += 2; break; case 8: if (currentGame.maxPlasmaAmmo == 100) {shopSelectedItem = -1; return;} currentGame.maxPlasmaAmmo -= 10; Math::limitChar(&player.ammo[0], 0, currentGame.maxPlasmaAmmo); break; case 9: if (currentGame.maxRocketAmmo == 0) {shopSelectedItem = -1; return;} currentGame.maxRocketAmmo -= 5; Math::limitChar(&player.ammo[1], 0, currentGame.maxRocketAmmo); break; case 10: if (player.weaponType[1] != W_DOUBLE_ROCKETS) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; shopSelectedItem = -1; break; case 11: if (player.weaponType[1] != W_MICRO_ROCKETS) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; shopSelectedItem = -1; break; case 12: if (player.weaponType[1] != W_LASER) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; player.ammo[1] = 0; shopSelectedItem = -1; break; case 13: if (player.weaponType[1] != W_HOMING_MISSILE) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; shopSelectedItem = -1; break; case 14: if (player.weaponType[1] != W_CHARGER) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; player.ammo[1] = 0; shopSelectedItem = -1; break; case 15: if (player.weaponType[1] != W_DOUBLE_HOMING_MISSILES) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; shopSelectedItem = -1; break; case 16: if (player.weaponType[1] != W_MICRO_HOMING_MISSILES) {shopSelectedItem = -1; return;} player.weaponType[1] = W_NONE; shopSelectedItem = -1; break; } currentGame.cash += (shopItems[i].price / 2);}void showShop(){ graphics.blit(graphics.shopSurface[0], 20, 395); graphics.blit(graphics.shopSurface[1], 275, 395); graphics.blit(graphics.shopSurface[2], 530, 395); graphics.blit(graphics.shopSurface[3], 100, 180); graphics.blit(graphics.shopSurface[4], 100, 50); graphics.blit(graphics.shopSurface[5], 100, 320); if (shopSelectedItem > -1) { graphics.blit(graphics.shape[27], 60, 350); graphics.blit(graphics.shape[28], 710, 350); } graphics.blit(graphics.shape[29], (int)player.x, (int)player.y); signed char icons = MAX_SHOPITEMS; if (currentGame.system == 0) icons = 11; else if (currentGame.system == 1) icons = 13; else if (currentGame.system == 2) icons = 15; if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL])) { for (int i = 0 ; i < icons ; i++) { if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, shopItems[i].x, shopItems[i].y, 32, 25)) { shopSelectedItem = i; engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0; drawShop(); } } if (shopSelectedItem > -1) { if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 60, 350, 24, 16)) { buy(shopSelectedItem); engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0; drawShop(); } if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 700, 350, 24, 16)) { sell(shopSelectedItem); engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0; drawShop(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -