2018-01-29 15:46:04 +03:00
|
|
|
/**********************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib - transmission mission
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
|
|
|
|
*
|
|
|
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
|
|
|
* will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose, including commercial
|
|
|
|
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
|
|
|
* wrote the original software. If you use this software in a product, an acknowledgment
|
|
|
|
* in the product documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
|
|
|
* as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "screens.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define MISSION_MAX_LENGTH 256
|
|
|
|
#define KEYWORD_MAX_LENGTH 32
|
|
|
|
#define MAX_LINE_CHAR 75
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Global Variables Definition (local to this module)
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Mission screen global variables
|
|
|
|
static int framesCounter;
|
|
|
|
static int finishScreen;
|
|
|
|
|
|
|
|
static Texture2D texBackground;
|
|
|
|
|
|
|
|
static Texture2D texBackline; //mission_backline
|
|
|
|
static Rectangle sourceRecBackLine;
|
|
|
|
static Rectangle destRecBackLine;
|
|
|
|
static float fadeBackLine;
|
|
|
|
|
|
|
|
static Vector2 numberPosition;
|
|
|
|
static Color numberColor;
|
|
|
|
|
|
|
|
//static char textMission[MISSION_MAX_LENGTH];
|
|
|
|
static Vector2 missionPosition;
|
|
|
|
static int missionSize;
|
|
|
|
static Color missionColor;
|
|
|
|
static int missionLenght;
|
|
|
|
static bool missionMaxLength;
|
|
|
|
static int missionSpeed;
|
|
|
|
|
|
|
|
//static char textKeyword[KEYWORD_MAX_LENGTH];
|
|
|
|
static Vector2 keywordPosition;
|
|
|
|
static Color keywordColor;
|
|
|
|
|
|
|
|
static int showMissionWaitFrames;
|
|
|
|
static int showNumberWaitFrames;
|
|
|
|
static int showKeywordWaitFrames;
|
|
|
|
|
|
|
|
static bool startWritting;
|
|
|
|
static bool writeMission;
|
|
|
|
static bool writeNumber;
|
|
|
|
static bool writeKeyword;
|
|
|
|
static bool writeEnd;
|
|
|
|
|
|
|
|
static bool writtingMission;
|
|
|
|
|
|
|
|
static int blinkFrames;
|
|
|
|
static bool blinkKeyWord = true;
|
|
|
|
|
|
|
|
static bool showButton = false;
|
|
|
|
|
|
|
|
static Mission *missions = NULL;
|
|
|
|
|
|
|
|
static Sound fxTransmit;
|
|
|
|
static Music musMission;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Mission Screen Functions Definition
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
static void WriteMissionText();
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
|
|
|
|
// Mission Screen Initialization logic
|
|
|
|
void InitMissionScreen(void)
|
|
|
|
{
|
|
|
|
framesCounter = 0;
|
|
|
|
finishScreen = 0;
|
2018-12-24 19:46:23 +03:00
|
|
|
|
|
|
|
fadeButton = 0.80f;
|
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
texBackground = LoadTexture("resources/textures/mission_background.png");
|
2018-12-24 19:46:23 +03:00
|
|
|
|
|
|
|
texBackline = LoadTexture("resources/textures/mission_backline.png");
|
2018-01-29 15:46:04 +03:00
|
|
|
sourceRecBackLine = (Rectangle){0,0,GetScreenWidth(), texBackline.height};
|
|
|
|
destRecBackLine = (Rectangle){0,0,sourceRecBackLine.width, sourceRecBackLine.height};
|
|
|
|
fadeBackLine = 0;
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
fxTransmit = LoadSound("resources/audio/fx_message.ogg");
|
|
|
|
musMission = LoadMusicStream("resources/audio/music_mission.ogg");
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
PlayMusicStream(musMission);
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
// Initialize missions
|
|
|
|
missions = LoadMissions("resources/missions.txt");
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
missionMaxLength = strlen(missions[currentMission].brief);
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
// Insert line breaks every MAX_LINE_CHAR
|
|
|
|
int currentLine = 1;
|
|
|
|
int i = currentLine * MAX_LINE_CHAR;
|
|
|
|
|
|
|
|
while (i < missionMaxLength)
|
|
|
|
{
|
|
|
|
if (missions[currentMission].brief[i] == ' ')
|
|
|
|
{
|
|
|
|
missions[currentMission].brief[i] = '\n';
|
|
|
|
currentLine++;
|
|
|
|
i = currentLine*MAX_LINE_CHAR;
|
|
|
|
}
|
|
|
|
else i++;
|
2018-12-24 19:46:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
missionSize = 30;
|
2018-01-29 15:46:04 +03:00
|
|
|
missionLenght = 0;
|
|
|
|
missionSpeed = 1;
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
numberColor = RAYWHITE;
|
|
|
|
missionColor = LIGHTGRAY;
|
|
|
|
keywordColor = (Color){198, 49, 60, 255}; //RED
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
numberPosition = (Vector2){150, 185};
|
|
|
|
missionPosition = (Vector2){numberPosition.x, numberPosition.y + 60};
|
|
|
|
keywordPosition = (Vector2){missionPosition.x, missionPosition.y + MeasureTextEx(fontMission, missions[currentMission].brief, missionSize, 0).y + 60};
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
startWritting = false;
|
|
|
|
writeNumber = false;
|
|
|
|
writeMission = false;
|
|
|
|
writeKeyword = false;
|
|
|
|
writeEnd = false;
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
writtingMission = false;
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
showNumberWaitFrames = 30;
|
2018-12-24 19:46:23 +03:00
|
|
|
showMissionWaitFrames = 60;
|
|
|
|
showKeywordWaitFrames = 60;
|
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
blinkKeyWord = true;
|
|
|
|
blinkFrames = 15;
|
2018-12-24 19:46:23 +03:00
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
PlaySound(fxTransmit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mission Screen Update logic
|
|
|
|
void UpdateMissionScreen(void)
|
|
|
|
{
|
|
|
|
UpdateMusicStream(musMission);
|
2018-12-24 19:46:23 +03:00
|
|
|
|
|
|
|
if (!writeEnd) WriteMissionText();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
framesCounter++;
|
|
|
|
|
|
|
|
if ((framesCounter%blinkFrames) == 0)
|
|
|
|
{
|
|
|
|
framesCounter = 0;
|
|
|
|
blinkKeyWord = !blinkKeyWord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:46:04 +03:00
|
|
|
if (showButton)
|
|
|
|
{
|
2018-12-24 19:46:23 +03:00
|
|
|
if (IsKeyPressed(KEY_ENTER) || IsButtonPressed())
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
2018-12-24 19:46:23 +03:00
|
|
|
if (!writeEnd)
|
|
|
|
{
|
|
|
|
writeEnd = true;
|
|
|
|
writeKeyword = true;
|
|
|
|
writeNumber = true;
|
|
|
|
missionLenght = missionMaxLength;
|
|
|
|
}
|
2018-01-29 15:46:04 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
finishScreen = true;
|
|
|
|
showButton = false;
|
|
|
|
}
|
2018-12-24 19:46:23 +03:00
|
|
|
}
|
2018-01-29 15:46:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mission Screen Draw logic
|
|
|
|
void DrawMissionScreen(void)
|
|
|
|
{
|
2018-12-24 19:46:23 +03:00
|
|
|
// Draw MISSION screen here!
|
2018-01-29 15:46:04 +03:00
|
|
|
DrawTexture(texBackground, 0,0, WHITE);
|
|
|
|
DrawTexturePro(texBackline, sourceRecBackLine, destRecBackLine, (Vector2){0,0},0, Fade(WHITE, fadeBackLine));
|
2018-12-24 19:46:23 +03:00
|
|
|
|
|
|
|
if (writeNumber) DrawTextEx(fontMission, FormatText("Filtración #%02i ", currentMission + 1), numberPosition, missionSize + 10, 0, numberColor);
|
2018-01-29 15:46:04 +03:00
|
|
|
DrawTextEx(fontMission, SubText(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor);
|
2018-12-24 19:46:23 +03:00
|
|
|
if (writeKeyword && blinkKeyWord) DrawTextEx(fontMission, FormatText("Keyword: %s", missions[currentMission].key), keywordPosition, missionSize + 10, 0, keywordColor);
|
|
|
|
|
|
|
|
if (showButton)
|
|
|
|
{
|
2018-01-29 15:46:04 +03:00
|
|
|
if (!writeEnd) DrawButton("saltar");
|
|
|
|
else DrawButton("codificar");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mission Screen Unload logic
|
|
|
|
void UnloadMissionScreen(void)
|
|
|
|
{
|
2018-12-24 19:46:23 +03:00
|
|
|
// Unload MISSION screen variables here!
|
|
|
|
UnloadTexture(texBackground);
|
2018-01-29 15:46:04 +03:00
|
|
|
UnloadTexture(texBackline);
|
|
|
|
UnloadSound(fxTransmit);
|
|
|
|
UnloadMusicStream(musMission);
|
|
|
|
free(missions);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mission Screen should finish?
|
|
|
|
int FinishMissionScreen(void)
|
|
|
|
{
|
|
|
|
return finishScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WriteMissionText()
|
|
|
|
{
|
2018-12-24 19:46:23 +03:00
|
|
|
if (!startWritting)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter++;
|
2018-12-24 19:46:23 +03:00
|
|
|
if (framesCounter % 60 == 0)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter = 0;
|
|
|
|
startWritting = true;
|
|
|
|
}
|
2018-12-24 19:46:23 +03:00
|
|
|
}
|
|
|
|
else if (!writeNumber)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter++;
|
|
|
|
fadeBackLine += 0.020f;
|
2018-12-24 19:46:23 +03:00
|
|
|
if (framesCounter % showNumberWaitFrames == 0)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter = 0;
|
|
|
|
writeNumber = true;
|
|
|
|
showButton = true;
|
|
|
|
}
|
|
|
|
}
|
2018-12-24 19:46:23 +03:00
|
|
|
else if (!writeMission)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter ++;
|
2018-12-24 19:46:23 +03:00
|
|
|
if (framesCounter % showMissionWaitFrames == 0)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter = 0;
|
|
|
|
writeMission = true;
|
|
|
|
writtingMission = true;
|
|
|
|
}
|
|
|
|
}
|
2018-12-24 19:46:23 +03:00
|
|
|
else if (writeMission && writtingMission)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter++;
|
2018-12-24 19:46:23 +03:00
|
|
|
if (framesCounter % missionSpeed == 0)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter = 0;
|
2018-12-24 19:46:23 +03:00
|
|
|
missionLenght++;
|
|
|
|
|
|
|
|
if (missionLenght == missionMaxLength)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
writtingMission = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-24 19:46:23 +03:00
|
|
|
else if (!writeKeyword)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter++;
|
2018-12-24 19:46:23 +03:00
|
|
|
if (framesCounter % showKeywordWaitFrames == 0)
|
2018-01-29 15:46:04 +03:00
|
|
|
{
|
|
|
|
framesCounter = 0;
|
|
|
|
writeKeyword = true;
|
|
|
|
writeEnd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|