⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intermission.cpp

📁 打飞机的过关游戏(linux)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "intermission.h"

/*
Drives the cursor. Is used by some other screens too
*/
void doCursor()
{
	getPlayerInput();

	Math::limitInt(&engine.cursor_x, 50, 728);
	Math::limitInt(&engine.cursor_y, 50, 528);
	graphics.blit(graphics.shape[0], engine.cursor_x, engine.cursor_y);
}

/*
Sets the player's current status information lines. These are the lines
that are scrolled up the screen when the player clicks on Current Status
These are set only once.
*/
void setStatusLines()
{
	char string[50];

	sprintf(string, "System : %s", systemNames[currentGame.system]);

	graphics.textSurface(0, string, 0, 0, FONT_WHITE);

	signed char total = 0;
	signed char completed = 0;
	
	for (int i = 0 ; i < 10 ; i++)
	{
		if (systemPlanet[i].missionNumber > -1)
		{
			switch(systemPlanet[i].missionCompleted)
   		{
				case 0:
					total++;
					break;
				case 1:
					total++;
					completed++;
					break;
			}
		}
	}

	for (int i = 0 ; i < 30 ; i++)
		graphics.textSurface(i, "", 0, 0, FONT_WHITE);

	sprintf(string, "Missions Completed : %d/%d", completed, total);
	graphics.textSurface(1, string, 0, 0, FONT_WHITE);

	sprintf(string, "Shots Fired : %d", currentGame.shots);
	graphics.textSurface(2, string, 0, 0, FONT_WHITE);

	sprintf(string, "Hits Scored : %d", currentGame.hits);
	graphics.textSurface(3, string, 0, 0, FONT_WHITE);

	sprintf(string, "Accuracy : %d%%", currentGame.accuracy);
	graphics.textSurface(4, string, 0, 0, FONT_WHITE);

	sprintf(string, "Enemies Killed by Others : %d", currentGame.totalOtherKills);
	graphics.textSurface(5, string, 0, 0, FONT_WHITE);

	sprintf(string, "Total Cash Earned : %d", currentGame.cashEarned);
	graphics.textSurface(6, string, 0, 0, FONT_WHITE);

	graphics.textSurface(7, "*** Chris ***", 0, 0, FONT_WHITE);

	sprintf(string, "Enemies Killed : %d", currentGame.totalKills);
	graphics.textSurface(8, string, 0, 0, FONT_WHITE);

	sprintf(string, "Shield Restores Picked Up : %d", currentGame.shieldPickups);
	graphics.textSurface(9, string, 0, 0, FONT_WHITE);

	sprintf(string, "Plasma Cells Picked Up : %d", currentGame.cellPickups);
	graphics.textSurface(10, string, 0, 0, FONT_WHITE);

	sprintf(string, "Rockets Picked Up : %d", currentGame.rocketPickups);
	graphics.textSurface(11, string, 0, 0, FONT_WHITE);

	sprintf(string, "Powerups Picked Up : %d", currentGame.rocketPickups);
	graphics.textSurface(12, string, 0, 0, FONT_WHITE);

	sprintf(string, "Mines Destroyed : %d", currentGame.minesKilled);
	graphics.textSurface(13, string, 0, 0, FONT_WHITE);

	sprintf(string, "Slaves Rescued : %d", currentGame.slavesRescued);
	graphics.textSurface(14, string, 0, 0, FONT_WHITE);

	sprintf(string, "Cargo Picked Up : %d", currentGame.cargoPickups);
	graphics.textSurface(15, string, 0, 0, FONT_WHITE);

	if (currentGame.hasWingMate1)
	{
		graphics.textSurface(16, "*** Phoebe ***", 0, 0, FONT_WHITE);

		sprintf(string, "Enemies Killed : %d", currentGame.wingMate1Kills);
		graphics.textSurface(17, string, 0, 0, FONT_WHITE);

		sprintf(string, "Ejections : %d", currentGame.wingMate1Ejects);
		graphics.textSurface(18, string, 0, 0, FONT_WHITE);
	}

	if (currentGame.hasWingMate2)
	{
		graphics.textSurface(19, "*** Ursula ***", 0, 0, FONT_WHITE);

		sprintf(string, "Enemies Killed : %d", currentGame.wingMate2Kills);
		graphics.textSurface(20, string, 0, 0, FONT_WHITE);

		sprintf(string, "Ejections : %d", currentGame.wingMate2Ejects);
		graphics.textSurface(21, string, 0, 0, FONT_WHITE);
	}

	signed char percentage = 0;
	if ((currentGame.secondaryMissions > 0) && (currentGame.secondaryMissionsCompleted > 0))
		percentage = (currentGame.secondaryMissionsCompleted / currentGame.secondaryMissions) * 100;
	sprintf(string, "Seconday Missions Completed : %d / %d (%d%%)", currentGame.secondaryMissionsCompleted, currentGame.secondaryMissions, percentage);
	graphics.textSurface(24, string, 0, 0, FONT_WHITE);

	int timeTaken = currentGame.timeTaken;

	signed char clock = 0;
	while (timeTaken > 3599)
	{
		clock++;
		timeTaken -= 3600;
	}

	sprintf(string, "Total Time : %.2d", clock);

	clock = 0;
	while (timeTaken > 59)
	{
		clock++;
		timeTaken -= 60;
	}

	sprintf(string, "%s:%.2d:%.2d", string, clock, timeTaken);
	graphics.textSurface(26, string, -1, 0, FONT_WHITE);
	graphics.textSurface(27, "Current Status", -1, 0, FONT_WHITE);

	graphics.textShape[0].y = 400;
	graphics.textShape[0].x = 150;

	for (int i = 1 ; i < 25 ; i++)
	{
		graphics.textShape[i].y = graphics.textShape[i - 1].y + 20;
		if ((i == 7) || (i == 16) || (i == 19))
			graphics.textShape[i].y += 25;

		graphics.textShape[i].x = 150;
	}

	graphics.textShape[26].y = 404;
	graphics.textShape[27].y = 83;
}

/*
Sets the names and stats of the planets within the current system.
This will later be placed into a data file.
*/
void setSystemPlanets()
{
	FILE *fp;

	char string[100];
	strcpy(string, "");

	switch (currentGame.system)
	{
		case 0:
			strcpy(string, "data/planets_spirit.dat");
			break;
		case 1:
			strcpy(string, "data/planets_eyananth.dat");
			break;
		case 2:
			strcpy(string, "data/planets_mordor.dat");
			break;
		case 3:
			strcpy(string, "data/planets_sol.dat");
			break;
	}

	#if USEPACK
	int dataLocation = locateDataInPak(string, 1);
	fp = fopen(PACKLOCATION, "rb");
	fseek(fp, dataLocation, SEEK_SET);
	#else
	fp = fopen(string, "rb");
	#endif

	int distance;
	char name[50];
	int image;

	for (int i = 0 ; i < 10 ; i++)
	{
		fscanf(fp, "%d %s %d", &distance, name, &image);

		systemPlanet[i].y = distance;
		strcpy(systemPlanet[i].name, name);
		systemPlanet[i].image = graphics.shape[image];
	}

 	int messageMission;
	int messageSlot;
	char face[50];
	char from[100];
	char subject[100];

	for (int i = 0 ; i < 10 ; i++)
	{
		fscanf(fp, "%d %d %s%*c", &messageMission, &messageSlot, face);
		fscanf(fp, "%[^\n]%*c", from);
		fscanf(fp, "%[^\n]%*c", subject);

		systemPlanet[i].messageMission = messageMission;
		systemPlanet[i].messageSlot = messageSlot;
		systemPlanet[i].faceImage = getFace(face);

		strcpy(systemPlanet[i].from, from);
		strcpy(systemPlanet[i].subject, subject);
	}

	fclose(fp);
}

/*
Spins the planets around the sun, spaced according to their Y value
as defined in setSystemPlanets(). Moving the cursor over the planet
will show their name and their current status
*/
signed char showSystem(float x, float y)
{
	SDL_Rect r;
	signed char planet = 0;
	int planetSpace = systemPlanet[planet].y;
	signed char rtn = 0;

	// Blit the sun
	graphics.blit(graphics.shape[30], 370, 220);

	for (int i = 50 ; i < 300 ; i+= planetSpace)
	{
		x *= 0.75;
		y *= 0.75;

		graphics.circle(400, 250, i, graphics.screen, graphics.darkGrey);

		r.x = int(400 + (sin(x) * i));
		r.y = int(250 + (cos(y) * i));
		r.w = 10;
		r.h = 10;

		r.x -= (systemPlanet[planet].image->w / 2);
		r.y -= (systemPlanet[planet].image->h / 2);
		graphics.blit(systemPlanet[planet].image, r.x, r.y);

		if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, r.x, r.y, systemPlanet[planet].image->w, systemPlanet[planet].image->h))
		{
			graphics.drawString(systemPlanet[planet].name, -1, 545, FONT_WHITE);
			if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
			{
				if (currentGame.system == 0)
				{
					currentGame.stationedPlanet = planet;
					currentGame.destinationPlanet = planet;
					currentGame.area = systemPlanet[currentGame.stationedPlanet].missionNumber;
					strcpy(currentGame.stationedName, systemPlanet[currentGame.stationedPlanet].name);
				}
				else
				{
					currentGame.destinationPlanet = planet;
					strcpy(currentGame.destinationName, systemPlanet[currentGame.destinationPlanet].name);
				}

				rtn = 1;
				engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
			}
		}

		planet++;
		if (systemPlanet[planet].y == -1)
			break;
		planetSpace = systemPlanet[planet].y;
	}

	return rtn;
}

/*
Scrolls the player's current information up the screen. When
the specified status line reaches a certain Y value, the entire
list is reset and the information lines begin again from the bottom
(in other words, they loop around).
*/
void showStatus(SDL_Surface *infoSurface)
{
	graphics.blit(infoSurface, 100, 80);

	for (int i = 0 ; i < 22 ; i++)
	{
		graphics.textShape[i].y -= 0.25;
		if ((graphics.textShape[i].y > 80) && (graphics.textShape[i].y < 400))
			graphics.blitText(i);
	}

	if (graphics.textShape[21].y < 65)
	{
		graphics.textShape[0].y = 400;

		for (int i = 1 ; i < 25 ; i++)
		{
			graphics.textShape[i].y = graphics.textShape[i - 1].y + 20;
			if ((i == 7) || (i == 16) || (i == 19))
				graphics.textShape[i].y += 25;
		}
	}

	graphics.blevelRect(100, 80, 600, 20, 0x00, 0x00, 0x99);

	graphics.blevelRect(100, 400, 600, 20, 0x00, 0x00, 0x99);

	graphics.blitText(26);
	graphics.blitText(27);
}

void createOptions(SDL_Surface *optionsSurface)
{
	SDL_FillRect(optionsSurface, NULL, graphics.black);

	graphics.blevelRect(optionsSurface, 0, 0, optionsSurface->w - 2, optionsSurface->h - 2, 0x00, 0x00, 0x44);

	graphics.drawString("++ OPTIONS ++", 105, 8, FONT_WHITE, optionsSurface);

	graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 250, 45, 50, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 20, 45, 150, 22, 0x00, 0x00, 0x00);
	if (currentGame.useSound)
		graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0xff, 0x00, 0x00);
	else
		graphics.blevelRect(optionsSurface, 250, 45, 50, 22, 0xff, 0x00, 0x00);
	graphics.drawString("ON", 207, 50, FONT_WHITE, optionsSurface);
	graphics.drawString("OFF", 263, 50, FONT_WHITE, optionsSurface);
	graphics.drawString("SOUND", 30, 50, FONT_WHITE, optionsSurface);

	graphics.blevelRect(optionsSurface, 190, 95, 50, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 250, 95, 50, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 20, 95, 150, 22, 0x00, 0x00, 0x00);
	if (currentGame.useMusic)
		graphics.blevelRect(optionsSurface, 190, 95, 50, 22, 0xff, 0x00, 0x00);
	else
		graphics.blevelRect(optionsSurface, 250, 95, 50, 22, 0xff, 0x00, 0x00);
	graphics.drawString("ON", 207, 100, FONT_WHITE, optionsSurface);
	graphics.drawString("OFF", 263, 100, FONT_WHITE, optionsSurface);
	graphics.drawString("MUSIC", 30, 100, FONT_WHITE, optionsSurface);

 	graphics.blevelRect(optionsSurface, 190, 145, 50, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 250, 145, 50, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 20, 145, 150, 22, 0x00, 0x00, 0x00);
	if (currentGame.fullScreen)
		graphics.blevelRect(optionsSurface, 190, 145, 50, 22, 0xff, 0x00, 0x00);
	else
		graphics.blevelRect(optionsSurface, 250, 145, 50, 22, 0xff, 0x00, 0x00);
	graphics.drawString("ON", 207, 150, FONT_WHITE, optionsSurface);
	graphics.drawString("OFF", 263, 150, FONT_WHITE, optionsSurface);
	graphics.drawString("FULLSCREEN", 30, 150, FONT_WHITE, optionsSurface);

	graphics.blevelRect(optionsSurface, 20, 195, 150, 22, 0x00, 0x00, 0x00);
	graphics.blevelRect(optionsSurface, 190, 195, 110, 22, 0x00, 0x00, 0x00);
	if (currentGame.autoSaveSlot == -1)
	{
		graphics.drawString("NONE", 225, 200, FONT_WHITE, optionsSurface);
	}
	else
	{
		char string[] = "Slot %d";
		sprintf(string, "Slot %d", currentGame.autoSaveSlot + 1);
		graphics.blevelRect(optionsSurface, 190, 195, 110, 22, 0xff, 0x00, 0x00);
		graphics.drawString(string, 225, 200, FONT_WHITE, optionsSurface);
	}
	graphics.drawString("AUTOSAVE SLOT", 30, 200, FONT_WHITE, optionsSurface);
}

void showOptions(SDL_Surface *optionsSurface)
{
	if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
	{
		if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 172, 45, 22))
			currentGame.useSound = 1;

		if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 172, 45, 22))
			currentGame.useSound = 0;


		if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 222, 45, 22))
		{
			currentGame.useMusic = 1;
			if (engine.useAudio)
			{
				if (Mix_PausedMusic() == 1)
					Mix_ResumeMusic();
				else
					Mix_PlayMusic(engine.music, -1);
			}
		}

		if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 222, 45, 22))
		{
			currentGame.useMusic = 0;
			if (engine.useAudio)
				Mix_PauseMusic();
		}

		if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 272, 45, 22))
		{
			if (!currentGame.fullScreen)
			{
				#if LINUX
				SDL_WM_ToggleFullScreen(graphics.screen);
				#else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -