Exemple #1
0
bool RunGame(const CampaignOptions *co, struct MissionOptions *m, Map *map)
{
	// Clear the background
	DrawRectangle(
		&gGraphicsDevice, Vec2iZero(), gGraphicsDevice.cachedConfig.Res,
		colorBlack, 0);
	SDL_UpdateTexture(
		gGraphicsDevice.bkg, NULL, gGraphicsDevice.buf,
		gGraphicsDevice.cachedConfig.Res.x * sizeof(Uint32));

	MapLoad(map, m, co);

	// Seed random if PVP mode (otherwise players will always spawn in same
	// position)
	if (IsPVP(co->Entry.Mode))
	{
		srand((unsigned int)time(NULL));
	}

	if (!co->IsClient)
	{
		MapLoadDynamic(map, m, &co->Setting.characters);

		// For PVP modes, mark all map as explored
		if (IsPVP(co->Entry.Mode))
		{
			MapMarkAllAsVisited(map);
		}

		// Reset players for the mission
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			// Only reset for local players; for remote ones wait for the
			// client ready message
			if (!p->IsLocal) continue;
			GameEvent e = GameEventNew(GAME_EVENT_PLAYER_DATA);
			e.u.PlayerData = PlayerDataMissionReset(p);
			GameEventsEnqueue(&gGameEvents, e);
		CA_FOREACH_END()
		// Process the events to force add the players
		HandleGameEvents(&gGameEvents, NULL, NULL, NULL);

		// Note: place players first,
		// as bad guys are placed away from players
		Vec2i firstPos = Vec2iZero();
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			if (!p->Ready) continue;
			firstPos = PlacePlayer(&gMap, p, firstPos, true);
		CA_FOREACH_END()
		if (!IsPVP(co->Entry.Mode))
		{
			InitializeBadGuys();
			CreateEnemies();
		}
	}
Exemple #2
0
void GrafxMakeBackground(
	GraphicsDevice *device, DrawBuffer *buffer,
	CampaignOptions *co, struct MissionOptions *mo, Map *map, HSV tint,
	int isEditor, int buildTables, Vec2i pos, GrafxDrawExtra *extra)
{
	CampaignAndMissionSetup(buildTables, co, mo);
	MapLoad(&gMap, mo, &co->Setting.characters);
	InitializeBadGuys();
	CreateEnemies();
	MapMarkAllAsVisited(map);
	if (isEditor)
	{
		MapShowExitArea(map);
	}

	GrafxDrawBackground(device, buffer, tint, pos, extra);
}
Exemple #3
0
void GrafxMakeBackground(
	GraphicsDevice *device, DrawBuffer *buffer,
	CampaignOptions *co, struct MissionOptions *mo, Map *map, HSV tint,
	const bool isEditor, struct vec2 pos, GrafxDrawExtra *extra)
{
	CampaignAndMissionSetup(co, mo);
	GameEventsInit(&gGameEvents);
	MapBuild(map, mo->missionData, co);
	InitializeBadGuys();
	CreateEnemies();
	MapMarkAllAsVisited(map);
	if (isEditor)
	{
		MapShowExitArea(map, map->ExitStart, map->ExitEnd);
	}
	else
	{
		pos = Vec2CenterOfTile(svec2i_scale_divide(map->Size, 2));
	}
	// Process the events that place dynamic objects
	HandleGameEvents(&gGameEvents, NULL, NULL, NULL);
	GrafxDrawBackground(device, buffer, tint, pos, extra);
	GameEventsTerminate(&gGameEvents);
}
Exemple #4
0
int main( int argc, char* argv[] )
{	

	Initialise(iScreenWidth, iScreenHeight, false, "Space Invaders");
    
	SetBackgroundColour(SColour(0x00, 0x00, 0x00, 0xFF));

	//player settings
	player.SetSize(64.0f, 32.0f);
	player.iSpriteID = CreateSprite("./images/cannon.png", player.fWidth, player.fHeight, true);
	player.SetMovementExtremes(0.0f, iScreenWidth);
	player.SetMovementKeys(65, 68);
	player.x = iScreenWidth * 0.5f;
	player.y = 88.0f;

	//create Marquee sprite
	iArcadeMarquee = CreateSprite("./images/Space-Invaders-Marquee.png", iScreenWidth, iScreenHeight, true);

	//enemy creation
	CreateEnemies();
	enemyDirection = eRIGHT;
	nextDirection = eRIGHT;

	//font setting
	AddFont(pInvadersFont);

	//game state declaration
	GAMESTATES eCurrentState = eMAIN_MENU;

    //Game Loop
    do
    {
		float fDeltaT = GetDeltaTime();

		switch (eCurrentState) {
		case eMAIN_MENU:

			UpdateMainMenu();

			//input
			if (IsKeyDown(257) && !IsKeyDown(256)) {
				eCurrentState = eGAMEPLAY;
				ResetEnemies();
			}

			break;

		case eGAMEPLAY:

			UpdateGameState(fDeltaT);

			//ChangeState
			if (IsKeyDown(256)) {
				eCurrentState = eMAIN_MENU;
			}

			break;

		default:
			break;
		}

		//clear screen
		ClearScreen();


    } while(!FrameworkUpdate());

	Shutdown();

    return 0;
}
Exemple #5
0
static void Campaign(GraphicsDevice *graphics, CampaignOptions *co)
{
	if (IsPasswordAllowed(co->Entry.Mode))
	{
		MissionSave m;
		AutosaveLoadMission(
			&gAutosave, &m, co->Entry.Path, co->Entry.BuiltinIndex);
		co->MissionIndex = EnterPassword(graphics, &m);
	}
	else
	{
		co->MissionIndex = 0;
	}

	bool run = false;
	bool gameOver = true;
	do
	{
		CampaignAndMissionSetup(1, co, &gMission);

		if (IsGameOptionsNeeded(gCampaign.Entry.Mode))
		{
			debug(D_NORMAL, ">> Game options\n");
			if (!GameOptions(gCampaign.Entry.Mode))
			{
				run = false;
				goto bail;
			}
			gCampaign.OptionsSet = true;
		}

		// Mission briefing
		if (IsMissionBriefingNeeded(co->Entry.Mode))
		{
			if (!ScreenMissionBriefing(&gMission))
			{
				run = false;
				goto bail;
			}
		}

		// Equip guns
		if (!PlayerEquip())
		{
			run = false;
			goto bail;
		}

		// Initialise before waiting for game start;
		// server will send us messages
		GameEventsInit(&gGameEvents);

		if (gCampaign.IsClient)
		{
			if (!ScreenWaitForGameStart())
			{
				run = false;
				goto bail;
			}
		}

		MapLoad(&gMap, &gMission, co);

		// Seed random if PVP mode (otherwise players will always spawn in same
		// position)
		if (IsPVP(co->Entry.Mode))
		{
			srand((unsigned int)time(NULL));
		}

		if (!gCampaign.IsClient)
		{
			MapLoadDynamic(&gMap, &gMission, &co->Setting.characters);
			// Note: place players first,
			// as bad guys are placed away from players
			StartPlayers(ModeMaxHealth(co->Entry.Mode), co->MissionIndex);
			AddAndPlacePlayers();
			if (!IsPVP(co->Entry.Mode))
			{
				InitializeBadGuys();
				CreateEnemies();
			}
		}
		MusicPlayGame(
			&gSoundDevice, gCampaign.Entry.Path, gMission.missionData->Song);
		run = RunGame(&gMission, &gMap);
		// Don't quit if all players died, that's normal for PVP modes
		if (IsPVP(co->Entry.Mode) && GetNumPlayers(true, false, false) == 0)
		{
			run = true;
		}
		GameEventsTerminate(&gGameEvents);

		const int survivingPlayers = GetNumPlayers(true, false, false);
		// In co-op (non-PVP) modes, at least one player must survive
		if (!IsPVP(co->Entry.Mode))
		{
			gameOver = survivingPlayers == 0 ||
				co->MissionIndex == (int)gCampaign.Setting.Missions.size - 1;
		}

		int maxScore = 0;
		for (int i = 0; i < (int)gPlayerDatas.size; i++)
		{
			PlayerData *p = CArrayGet(&gPlayerDatas, i);
			p->survived = IsPlayerAlive(p);
			if (IsPlayerAlive(p))
			{
				TActor *player = CArrayGet(&gActors, p->Id);
				p->hp = player->health;
				p->RoundsWon++;
				maxScore = MAX(maxScore, p->RoundsWon);
			}
		}
		if (IsPVP(co->Entry.Mode))
		{
			gameOver = maxScore == ModeMaxRoundsWon(co->Entry.Mode);
			CASSERT(maxScore <= ModeMaxRoundsWon(co->Entry.Mode),
				"score exceeds max rounds won");
		}

		MissionEnd();
		MusicPlayMenu(&gSoundDevice);

		if (run)
		{
			switch (co->Entry.Mode)
			{
			case GAME_MODE_DOGFIGHT:
				ScreenDogfightScores();
				break;
			case GAME_MODE_DEATHMATCH:
				ScreenDeathmatchFinalScores();
				break;
			default:
				ScreenMissionSummary(&gCampaign, &gMission);
				// Note: must use cached value because players get cleaned up
				// in CleanupMission()
				if (gameOver && survivingPlayers > 0)
				{
					ScreenVictory(&gCampaign);
				}
				break;
			}
		}

		// Check if any scores exceeded high scores, if we're not a PVP mode
		if (!IsPVP(co->Entry.Mode))
		{
			bool allTime = false;
			bool todays = false;
			for (int i = 0; i < (int)gPlayerDatas.size; i++)
			{
				PlayerData *p = CArrayGet(&gPlayerDatas, i);
				if (((run && !p->survived) || gameOver) && p->IsLocal)
				{
					EnterHighScore(p);
					allTime |= p->allTime >= 0;
					todays |= p->today >= 0;
				}

				if (!p->survived)
				{
					p->totalScore = 0;
					p->missions = 0;
				}
				else
				{
					p->missions++;
				}
				p->lastMission = co->MissionIndex;
			}
			if (allTime)
			{
				DisplayAllTimeHighScores(graphics);
			}
			if (todays)
			{
				DisplayTodaysHighScores(graphics);
			}
		}
		if (!HasRounds(co->Entry.Mode))
		{
			co->MissionIndex++;
		}

	bail:
		// Need to terminate the mission later as it is used in calculating scores
		MissionOptionsTerminate(&gMission);
	} while (run && !gameOver);

	// Final screen
	if (run)
	{
		switch (co->Entry.Mode)
		{
		case GAME_MODE_DOGFIGHT:
			ScreenDogfightFinalScores();
			break;
		default:
			// no end screen
			break;
		}
	}
}
Exemple #6
0
//---------------------------------------------------------------------------- 
// Nome: ChangeState(CLevel::GameState NewState)
// Desc: Muda o estado da máquina de estados da CLevel
// Pams: novo estado
//---------------------------------------------------------------------------- 
void CLevel::ChangeState(CLevel::GameState NewState)
{
	//somente muda o estado se o novo for diferente do atual
	if(State != NewState)
	{
		switch(NewState)
		{
			case GS_GAME:
			{
				if(State == GS_MENU)
				{
					if(!Menu.bInGame)
					{
						Menu.bInGame = true; //indica para o menu que o jogo está rodando
						CreateItems();		//cria os itens
						CreateEnemies();	//cria os inimigos
						CreatePlayer();		//cria o jogador						
						if(p_SprSwitch)
						{
							//ajusta animação da alavanca da fase para 0 (levantada)
							p_SprSwitch->SetCurrentAnimation(0);
						}
						//faz aparecer layer de interface (com pontos e vidas)
						p_LayInterface->bVisible = true;
					}					
					//esconde menu
					Menu.Show(false);

					State = NewState; //estado atual recebe novo estado
					break;
				}
				if(State == GS_PAUSE)
				{
					//17.5.3. Esconder mensagem de pausa
					p_MsgPaused->bVisible = false;

					State = NewState; //estado atual recebe novo estado
					break;
				}
				break;
			}
			case GS_PAUSE:
			{
				if(State == GS_GAME)
				{
					//17.5.3. Exibir mensagem de pausa
					if(p_MsgPaused)
					{
						p_MsgPaused->bVisible = true;
					}

					State = NewState; //estado atual recebe novo estado
					break;
				}
				break;
			}
			case GS_MENU:
			{
				if(State == GS_GAME)
				{	
					Menu.bInGame = true; //mostrará botão "Continuar"
					Menu.Show(true); //mostra o menu principal
					State = NewState; //estado atual recebe novo estado
					break;
				}
				if((State == GS_CONGRATULATIONS)||(State == GS_GAMEOVER))
				{
					if(p_MsgCongrats)
					{
						//esconde mensagem de congratulação
						p_MsgCongrats->bVisible = false;
					}
					if(p_MsgGameOver)
					{
						//esconde mensagem de game over
						p_MsgGameOver->bVisible = false;
					}
					ReleaseCharacters();	//desalocando os inimigos
					ReleaseItems();				//desalocando os itens
					Menu.bInGame = false; //mostrará botão "Novo Jogo"
					Menu.Show(true);			//mostra o menu principal
					Scroll(CNGLVector(0,0)); //desloca a as layers para o início da fase
					
					State = NewState; //estado atual recebe novo estado
					break;
				}
				break;
			}
			case GS_GAMEOVER:
			{
				if(State == GS_GAME)
				{
					if(p_MsgGameOver)
					{
						//mostra mensagem de game over
						p_MsgGameOver->bVisible = true;
					}
					State = NewState; //estado atual recebe novo estado
					break;
				}
				break;
			}
			case GS_CONGRATULATIONS:
			{
				if(State == GS_GAME)
				{
					//21.1.4.
					//1. mostrar mensagem de congratulação

					//2. reproduz o som de congratulação

					//3. troca a animação do jogador para a 2


					State = NewState; //estado atual recebe novo estado
					break;
				}
				break;
			}
		}
	}
}