Some code tweaks

This commit is contained in:
raysan5 2018-12-24 17:46:23 +01:00
parent 7fb2459916
commit 1982eabe6e
4 changed files with 177 additions and 193 deletions

View file

@ -35,13 +35,13 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition (local to this module) // Global Variables Definition (local to this module)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static char *codingWords[MAX_CODING_WORDS] = { static char *codingWords[MAX_CODING_WORDS] = {
"pollo\0", "pollo\0",
"conejo\0", "conejo\0",
"huevo\0", "huevo\0",
"nido\0", "nido\0",
"aire\0", "aire\0",
"armario\0", "armario\0",
"agujero\0", "agujero\0",
"platano\0", "platano\0",
"pastel\0", "pastel\0",
@ -82,21 +82,21 @@ void InitEndingScreen(void)
{ {
framesCounter = 0; framesCounter = 0;
finishScreen = 0; finishScreen = 0;
rotation = 0.1f; rotation = 0.1f;
scale = 0.05f; scale = 0.05f;
state = 0; state = 0;
texBackground = LoadTexture("resources/textures/ending_background.png"); texBackground = LoadTexture("resources/textures/ending_background.png");
texVignette = LoadTexture("resources/textures/message_vignette.png"); texVignette = LoadTexture("resources/textures/message_vignette.png");
fxNews = LoadSound("resources/audio/fx_batman.ogg"); fxNews = LoadSound("resources/audio/fx_batman.ogg");
missions = LoadMissions("resources/missions.txt"); missions = LoadMissions("resources/missions.txt");
int wordsCount = missions[currentMission].wordsCount; int wordsCount = missions[currentMission].wordsCount;
strcpy(headline, missions[currentMission].msg); // Base headline strcpy(headline, missions[currentMission].msg); // Base headline
int len = strlen(headline); int len = strlen(headline);
// Remove @ from headline // Remove @ from headline
// TODO: Also remove additional spaces // TODO: Also remove additional spaces
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
@ -110,7 +110,7 @@ void InitEndingScreen(void)
{ {
// WARNING: It fails if the last sentence word has a '.' after space // WARNING: It fails if the last sentence word has a '.' after space
char *title = StringReplace(headline, messageWords[i].text, codingWords[messageWords[i].id]); char *title = StringReplace(headline, messageWords[i].text, codingWords[messageWords[i].id]);
if (title != NULL) if (title != NULL)
{ {
strcpy(headline, title); // Base headline updated strcpy(headline, title); // Base headline updated
@ -118,14 +118,14 @@ void InitEndingScreen(void)
} }
} }
} }
TraceLog(LOG_WARNING, "Titular: %s", headline); TraceLog(LOG_WARNING, "Titular: %s", headline);
// Generate newspaper with title and subtitle // Generate newspaper with title and subtitle
Image imNewspaper = LoadImage("resources/textures/ending_newspaper.png"); Image imNewspaper = LoadImage("resources/textures/ending_newspaper.png");
fontNews = LoadFontEx("resources/fonts/Lora-Bold.ttf", 32, 250, 0); fontNews = LoadFontEx("resources/fonts/Lora-Bold.ttf", 32, 250, 0);
ImageDrawTextEx(&imNewspaper, (Vector2){ 50, 220 }, fontNews, headline, fontNews.baseSize, 0, DARKGRAY); ImageDrawTextEx(&imNewspaper, (Vector2){ 50, 220 }, fontNews, headline, fontNews.baseSize, 0, DARKGRAY);
texNewspaper = LoadTextureFromImage(imNewspaper); texNewspaper = LoadTextureFromImage(imNewspaper);
//UnloadFont(fontNews); //UnloadFont(fontNews);
UnloadImage(imNewspaper); UnloadImage(imNewspaper);
@ -135,25 +135,25 @@ void InitEndingScreen(void)
void UpdateEndingScreen(void) void UpdateEndingScreen(void)
{ {
framesCounter++; framesCounter++;
if (framesCounter == 10) PlaySound(fxNews); if (framesCounter == 10) PlaySound(fxNews);
if (state == 0) if (state == 0)
{ {
rotation += 18.0f; rotation += 18.0f;
scale += 0.0096f; scale += 0.0096f;
if (scale >= 1.0f) if (scale >= 1.0f)
{ {
scale = 1.0f; scale = 1.0f;
state = 1; state = 1;
} }
} }
if ((state == 1) && (IsKeyPressed(KEY_ENTER) || IsButtonPressed())) if ((state == 1) && (IsKeyPressed(KEY_ENTER) || IsButtonPressed()))
{ {
currentMission++; currentMission++;
if (currentMission >= totalMissions) finishScreen = 2; if (currentMission >= totalMissions) finishScreen = 2;
else finishScreen = 1; else finishScreen = 1;
} }
@ -163,16 +163,16 @@ void UpdateEndingScreen(void)
void DrawEndingScreen(void) void DrawEndingScreen(void)
{ {
DrawTexture(texBackground, 0, 0, WHITE); DrawTexture(texBackground, 0, 0, WHITE);
DrawTexturePro(texNewspaper, (Rectangle){ 0, 0, texNewspaper.width, texNewspaper.height }, DrawTexturePro(texNewspaper, (Rectangle){ 0, 0, texNewspaper.width, texNewspaper.height },
(Rectangle){ GetScreenWidth()/2, GetScreenHeight()/2, texNewspaper.width*scale, texNewspaper.height*scale }, (Rectangle){ GetScreenWidth()/2, GetScreenHeight()/2, texNewspaper.width*scale, texNewspaper.height*scale },
(Vector2){ (float)texNewspaper.width*scale/2, (float)texNewspaper.height*scale/2 }, rotation, WHITE); (Vector2){ (float)texNewspaper.width*scale/2, (float)texNewspaper.height*scale/2 }, rotation, WHITE);
DrawTextureEx(texVignette, (Vector2){ 0, 0 }, 0.0f, 2.0f, WHITE); DrawTextureEx(texVignette, (Vector2){ 0, 0 }, 0.0f, 2.0f, WHITE);
// Draw debug information // Draw debug information
DrawTextEx(fontNews, headline, (Vector2){ 10, 10 }, fontNews.baseSize, 0, RAYWHITE); DrawTextEx(fontNews, headline, (Vector2){ 10, 10 }, fontNews.baseSize, 0, RAYWHITE);
for (int i = 0; i < missions[currentMission].wordsCount; i++) for (int i = 0; i < missions[currentMission].wordsCount; i++)
{ {
DrawText(codingWords[messageWords[i].id], 10, 60 + 30*i, 20, (messageWords[i].id == missions[currentMission].sols[i]) ? GREEN : RED); DrawText(codingWords[messageWords[i].id], 10, 60 + 30*i, 20, (messageWords[i].id == missions[currentMission].sols[i]) ? GREEN : RED);
@ -187,9 +187,9 @@ void UnloadEndingScreen(void)
UnloadTexture(texBackground); UnloadTexture(texBackground);
UnloadTexture(texNewspaper); UnloadTexture(texNewspaper);
UnloadTexture(texVignette); UnloadTexture(texVignette);
UnloadSound(fxNews); UnloadSound(fxNews);
free(missions); free(missions);
} }
// Ending Screen should finish? // Ending Screen should finish?
@ -213,16 +213,16 @@ static char *StringReplace(char *orig, char *rep, char *with)
// Sanity checks and initialization // Sanity checks and initialization
if (!orig || !rep) return NULL; if (!orig || !rep) return NULL;
len_rep = strlen(rep); len_rep = strlen(rep);
if (len_rep == 0) return NULL; // Empty rep causes infinite loop during count if (len_rep == 0) return NULL; // Empty rep causes infinite loop during count
if (!with) with = ""; // Replace with nothing if not provided if (!with) with = ""; // Replace with nothing if not provided
len_with = strlen(with); len_with = strlen(with);
// Count the number of replacements needed // Count the number of replacements needed
ins = orig; ins = orig;
for (count = 0; tmp = strstr(ins, rep); ++count) for (count = 0; tmp = strstr(ins, rep); ++count)
{ {
ins = tmp + len_rep; ins = tmp + len_rep;
} }
@ -235,7 +235,7 @@ static char *StringReplace(char *orig, char *rep, char *with)
// tmp points to the end of the result string // tmp points to the end of the result string
// ins points to the next occurrence of rep in orig // ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep" // orig points to the remainder of orig after "end of rep"
while (count--) while (count--)
{ {
ins = strstr(orig, rep); ins = strstr(orig, rep);
len_front = ins - orig; len_front = ins - orig;
@ -243,8 +243,8 @@ static char *StringReplace(char *orig, char *rep, char *with)
tmp = strcpy(tmp, with) + len_with; tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep" orig += len_front + len_rep; // move to next "end of rep"
} }
strcpy(tmp, orig); strcpy(tmp, orig);
return result; return result;
} }

View file

@ -35,9 +35,9 @@
#define MAX_LINE_CHAR 30 #define MAX_LINE_CHAR 30
/* /*
// NOTE: Coding words are generic and the same words // NOTE: Coding words are generic and the same words
// are used for all missions, // are used for all missions,
typedef enum CodingWords { typedef enum CodingWords {
POLLO = 0, POLLO = 0,
CONEJO, CONEJO,
HUEVO, HUEVO,
@ -50,13 +50,13 @@ typedef enum CodingWords {
} CodingWords; } CodingWords;
*/ */
static char *codingWords[MAX_CODING_WORDS] = { static char *codingWords[MAX_CODING_WORDS] = {
"pollo\0", "pollo\0",
"conejo\0", "conejo\0",
"huevo\0", "huevo\0",
"nido\0", "nido\0",
"aire\0", "aire\0",
"armario\0", "armario\0",
"agujero\0", "agujero\0",
"platano\0", "platano\0",
"pastel\0", "pastel\0",
@ -125,19 +125,19 @@ void InitGameplayScreen(void)
{ {
framesCounter = 0; framesCounter = 0;
finishScreen = 0; finishScreen = 0;
fontMessage = LoadFontEx("resources/fonts/traveling_typewriter.ttf", 30, 250, 0); fontMessage = LoadFontEx("resources/fonts/traveling_typewriter.ttf", 30, 250, 0);
texBackground = LoadTexture("resources/textures/message_background.png"); texBackground = LoadTexture("resources/textures/message_background.png");
texVignette = LoadTexture("resources/textures/message_vignette.png"); texVignette = LoadTexture("resources/textures/message_vignette.png");
fxGrab = LoadSound("resources/audio/fx_grab.ogg"); fxGrab = LoadSound("resources/audio/fx_grab.ogg");
fxPlace = LoadSound("resources/audio/fx_place.ogg"); fxPlace = LoadSound("resources/audio/fx_place.ogg");
fxLeave = LoadSound("resources/audio/fx_leave.ogg"); fxLeave = LoadSound("resources/audio/fx_leave.ogg");
musSpy = LoadMusicStream("resources/audio/s_p_y.xm"); musSpy = LoadMusicStream("resources/audio/s_p_y.xm");
PlayMusicStream(musSpy); PlayMusicStream(musSpy);
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
#define WORD_ATLAS_FROM_FILE #define WORD_ATLAS_FROM_FILE
#endif #endif
@ -147,20 +147,20 @@ void InitGameplayScreen(void)
// Generate coding words atlas directly from text // Generate coding words atlas directly from text
Image imWordsBase = LoadImage("resources/textures/words_base.png"); Image imWordsBase = LoadImage("resources/textures/words_base.png");
Image imWords = GenImageColor(imWordsBase.width, imWordsBase.height*MAX_CODING_WORDS, WHITE); Image imWords = GenImageColor(imWordsBase.width, imWordsBase.height*MAX_CODING_WORDS, WHITE);
for (int i = 0; i < MAX_CODING_WORDS; i++) for (int i = 0; i < MAX_CODING_WORDS; i++)
{ {
ImageDraw(&imWords, imWordsBase, ImageDraw(&imWords, imWordsBase,
(Rectangle){ 0, 0, imWordsBase.width, imWordsBase.height }, (Rectangle){ 0, 0, imWordsBase.width, imWordsBase.height },
(Rectangle){ 0, imWordsBase.height*i, imWordsBase.width, imWordsBase.height }); (Rectangle){ 0, imWordsBase.height*i, imWordsBase.width, imWordsBase.height });
ImageDrawTextEx(&imWords,(Vector2){ imWordsBase.width/2 - MeasureTextEx(fontMessage, codingWords[i], ImageDrawTextEx(&imWords,(Vector2){ imWordsBase.width/2 - MeasureTextEx(fontMessage, codingWords[i],
fontMessage.baseSize, 0).x/2, imWordsBase.height*i }, fontMessage, codingWords[i], fontMessage.baseSize, 0).x/2, imWordsBase.height*i }, fontMessage, codingWords[i],
fontMessage.baseSize, 0, BLACK); fontMessage.baseSize, 0, BLACK);
} }
texWordsAtlas = LoadTextureFromImage(imWords); texWordsAtlas = LoadTextureFromImage(imWords);
UnloadImage(imWordsBase); UnloadImage(imWordsBase);
UnloadImage(imWords); UnloadImage(imWords);
#endif #endif
@ -183,13 +183,13 @@ void InitGameplayScreen(void)
words[i].iniRec = words[i].rec; words[i].iniRec = words[i].rec;
words[i].hover = false; // Mouse hover detected words[i].hover = false; // Mouse hover detected
words[i].picked = false; // Mouse picked words[i].picked = false; // Mouse picked
//words[i].text = ''; //codingWords[i]; // Fill text if required... //words[i].text = ''; //codingWords[i]; // Fill text if required...
} }
// Analize missions[currentMission].msg string for words! // Analize missions[currentMission].msg string for words!
int msgLen = strlen(missions[currentMission].msg); int msgLen = strlen(missions[currentMission].msg);
// Add '/' each MAX_LINE_CHAR chars // Add '/' each MAX_LINE_CHAR chars
int currentLine = 1; int currentLine = 1;
int i = currentLine * MAX_LINE_CHAR; int i = currentLine * MAX_LINE_CHAR;
@ -203,39 +203,35 @@ void InitGameplayScreen(void)
i = currentLine*MAX_LINE_CHAR; i = currentLine*MAX_LINE_CHAR;
} }
else i++; else i++;
} }
int currentWord = 0; int currentWord = 0;
int offsetX = 0; int offsetX = 0;
int offsetY = 0; int offsetY = 0;
bool foundWord = false; bool foundWord = false;
int wordInitPosX = 0; int wordInitPosX = 0;
int wordInitPosY = 0; int wordInitPosY = 0;
// TODO: messageWords should be reseted every mission
//memcpy(messageWords, 0, sizeof(Word)*MAX_MISSION_WORDS);
for (int i = 0; i < msgLen; i++) for (int i = 0; i < msgLen; i++)
{ {
char c = missions[currentMission].msg[i]; char c = missions[currentMission].msg[i];
if (foundWord && (c == ' ' || c == '.')) if (foundWord && (c == ' ' || c == '.'))
{ {
foundWord = false; foundWord = false;
messageWords[currentWord - 1].rec.width = (int)MeasureTextEx(fontMessage, SubText(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), 30, 0).x; messageWords[currentWord - 1].rec.width = (int)MeasureTextEx(fontMessage, SubText(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), 30, 0).x;
messageWords[currentWord - 1].rec.height = fontMessage.baseSize; messageWords[currentWord - 1].rec.height = fontMessage.baseSize;
//TODO: Guardar en message
strncpy(messageWords[currentWord - 1].text, SubText(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), i - wordInitPosX); strncpy(messageWords[currentWord - 1].text, SubText(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), i - wordInitPosX);
} }
if (c == '@') // One word to change if (c == '@') // One word to change
{ {
foundWord = true; foundWord = true;
missions[currentMission].msg[i] = ' '; missions[currentMission].msg[i] = ' ';
offsetX = (int)MeasureTextEx(fontMessage, SubText(missions[currentMission].msg, wordInitPosY, (i + 1) - wordInitPosY), 30, 0).x; offsetX = (int)MeasureTextEx(fontMessage, SubText(missions[currentMission].msg, wordInitPosY, (i + 1) - wordInitPosY), 30, 0).x;
messageWords[currentWord].rec.x = offsetX; messageWords[currentWord].rec.x = offsetX;
messageWords[currentWord].rec.y = offsetY; messageWords[currentWord].rec.y = offsetY;
@ -254,16 +250,16 @@ void InitGameplayScreen(void)
for (int i = 0; i < missions[currentMission].wordsCount; i++) for (int i = 0; i < missions[currentMission].wordsCount; i++)
{ {
messageWords[i].id = -1; // Not required for message words, id is the array position messageWords[i].id = -1; // Not required for message words, id is the array position
// Recalculate words rectangles considering text offset on screen // Recalculate words rectangles considering text offset on screen
messageWords[i].rec.x += msgOffset.x; messageWords[i].rec.x += msgOffset.x;
messageWords[i].rec.y += msgOffset.y; messageWords[i].rec.y += msgOffset.y;
// Recalculate words rectangle considering new width height // Recalculate words rectangle considering new width height
messageWords[i].rec.x -= (texWordsAtlas.width - messageWords[i].rec.width)/2; messageWords[i].rec.x -= (texWordsAtlas.width - messageWords[i].rec.width)/2;
messageWords[i].rec.y -= ((texWordsAtlas.height / MAX_CODING_WORDS) - messageWords[i].rec.height)/2; messageWords[i].rec.y -= ((texWordsAtlas.height / MAX_CODING_WORDS) - messageWords[i].rec.height)/2;
//Recalculate width height //Recalculate width height
messageWords[i].rec.width = texWordsAtlas.width; messageWords[i].rec.width = texWordsAtlas.width;
messageWords[i].rec.height = texWordsAtlas.height / MAX_CODING_WORDS; messageWords[i].rec.height = texWordsAtlas.height / MAX_CODING_WORDS;
@ -276,13 +272,13 @@ void InitGameplayScreen(void)
void UpdateGameplayScreen(void) void UpdateGameplayScreen(void)
{ {
UpdateMusicStream(musSpy); UpdateMusicStream(musSpy);
for (int i = 0; i < MAX_CODING_WORDS; i++) for (int i = 0; i < MAX_CODING_WORDS; i++)
{ {
if (CheckCollisionPointRec(GetMousePosition(), words[i].rec)) if (CheckCollisionPointRec(GetMousePosition(), words[i].rec))
{ {
words[i].hover = true; words[i].hover = true;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{ {
words[i].picked = true; words[i].picked = true;
@ -290,41 +286,41 @@ void UpdateGameplayScreen(void)
} }
} }
else words[i].hover = false; else words[i].hover = false;
if (words[i].picked) if (words[i].picked)
{ {
for (int j = 0; j < missions[currentMission].wordsCount; j++) for (int j = 0; j < missions[currentMission].wordsCount; j++)
{ {
if (CheckCollisionPointRec(GetMousePosition(), messageWords[j].rec)) messageWords[j].hover = true; if (CheckCollisionPointRec(GetMousePosition(), messageWords[j].rec)) messageWords[j].hover = true;
else messageWords[j].hover = false; else messageWords[j].hover = false;
} }
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
{ {
words[i].picked = false; words[i].picked = false;
for (int j = 0; j < missions[currentMission].wordsCount; j++) for (int j = 0; j < missions[currentMission].wordsCount; j++)
{ {
messageWords[j].hover = false; messageWords[j].hover = false;
if (CheckCollisionPointRec(GetMousePosition(), messageWords[j].rec)) if (CheckCollisionPointRec(GetMousePosition(), messageWords[j].rec))
{ {
PlaySound(fxPlace); PlaySound(fxPlace);
words[i].rec.x = messageWords[j].rec.x; words[i].rec.x = messageWords[j].rec.x;
words[i].rec.y = messageWords[j].rec.y; words[i].rec.y = messageWords[j].rec.y;
if (messageWords[j].id != -1) if (messageWords[j].id != -1)
{ {
int id = messageWords[j].id; int id = messageWords[j].id;
words[id].rec = words[id].iniRec; words[id].rec = words[id].iniRec;
} }
messageWords[j].id = i; messageWords[j].id = i;
for (int k = 0; k < missions[currentMission].wordsCount; k++) for (int k = 0; k < missions[currentMission].wordsCount; k++)
{ {
if (j != k && messageWords[j].id == messageWords[k].id) if (j != k && messageWords[j].id == messageWords[k].id)
{ {
messageWords[k].id = -1; messageWords[k].id = -1;
break; break;
@ -332,60 +328,53 @@ void UpdateGameplayScreen(void)
} }
break; break;
} }
else else
{ {
PlaySound(fxLeave); PlaySound(fxLeave);
words[i].rec = words[i].iniRec; words[i].rec = words[i].iniRec;
if (i == messageWords[j].id) messageWords[j].id = -1; if (i == messageWords[j].id) messageWords[j].id = -1;
} }
} }
} }
} }
// TODO: Move word picked with mouse // Move word picked with mouse
if (words[i].picked) if (words[i].picked)
{ {
words[i].rec.x = GetMouseX() - words[i].rec.width/2; words[i].rec.x = GetMouseX() - words[i].rec.width/2;
words[i].rec.y = GetMouseY() - words[i].rec.height/2; words[i].rec.y = GetMouseY() - words[i].rec.height/2;
// TODO: Check if label is placed in some mission word position
//if (CheckCollisionRecs(words[i].rec))
}
else
{
//if (words[i].id != -1)
} }
} }
canSend = true; canSend = true;
for(int j = 0; j < missions[currentMission].wordsCount; j++) for (int j = 0; j < missions[currentMission].wordsCount; j++)
{ {
if(messageWords[j].id == -1) if (messageWords[j].id == -1)
{ {
canSend = false; canSend = false;
break; break;
} }
} }
if (canSend && (IsKeyPressed(KEY_ENTER) || IsButtonPressed())) if (canSend && (IsKeyPressed(KEY_ENTER) || IsButtonPressed()))
{ {
finishScreen = true; finishScreen = true;
} }
} }
// Gameplay Screen Draw logic // Gameplay Screen Draw logic
void DrawGameplayScreen(void) void DrawGameplayScreen(void)
{ {
DrawTexture(texBackground, 0, 0, WHITE); DrawTexture(texBackground, 0, 0, WHITE);
DrawTextEx(fontMessage, missions[currentMission].msg, msgOffset, fontMessage.baseSize, 0, BLACK); DrawTextEx(fontMessage, missions[currentMission].msg, msgOffset, fontMessage.baseSize, 0, BLACK);
for (int i = 0; i < missions[currentMission].wordsCount; i++) for (int i = 0; i < missions[currentMission].wordsCount; i++)
{ {
Rectangle recLines = messageWords[i].rec; Rectangle recLines = messageWords[i].rec;
DrawRectangleLines(recLines.x, recLines.y, recLines.width, recLines.height, Fade(RED, 0.35f)); DrawRectangleLines(recLines.x, recLines.y, recLines.width, recLines.height, Fade(RED, 0.35f));
if(messageWords[i].hover) DrawRectangleRec(messageWords[i].rec, Fade(RED, 0.30f)); if (messageWords[i].hover) DrawRectangleRec(messageWords[i].rec, Fade(RED, 0.30f));
DrawText(FormatText("%i", messageWords[i].id), i*25, 0, 30, RED); DrawText(FormatText("%i", messageWords[i].id), i*25, 0, 30, RED);
} }
for (int i = 0; i < MAX_CODING_WORDS; i++) for (int i = 0; i < MAX_CODING_WORDS; i++)
@ -394,9 +383,9 @@ void DrawGameplayScreen(void)
else if (words[i].hover) DrawTextureRec(texWordsAtlas, (Rectangle){ 0, i*35, 140, 35 }, (Vector2){ words[i].rec.x, words[i].rec.y }, RED); else if (words[i].hover) DrawTextureRec(texWordsAtlas, (Rectangle){ 0, i*35, 140, 35 }, (Vector2){ words[i].rec.x, words[i].rec.y }, RED);
else DrawTextureRec(texWordsAtlas, (Rectangle){ 0, i*35, 140, 35 }, (Vector2){ words[i].rec.x, words[i].rec.y }, WHITE); else DrawTextureRec(texWordsAtlas, (Rectangle){ 0, i*35, 140, 35 }, (Vector2){ words[i].rec.x, words[i].rec.y }, WHITE);
} }
DrawTexturePro(texVignette, (Rectangle){0,0,texVignette.width, texVignette.height}, (Rectangle){0,0,GetScreenWidth(), GetScreenHeight()}, (Vector2){0,0}, 0, WHITE); DrawTexturePro(texVignette, (Rectangle){0,0,texVignette.width, texVignette.height}, (Rectangle){0,0,GetScreenWidth(), GetScreenHeight()}, (Vector2){0,0}, 0, WHITE);
if (canSend) DrawButton("enviar"); if (canSend) DrawButton("enviar");
} }
@ -406,13 +395,13 @@ void UnloadGameplayScreen(void)
UnloadTexture(texBackground); UnloadTexture(texBackground);
UnloadTexture(texVignette); UnloadTexture(texVignette);
UnloadTexture(texWordsAtlas); UnloadTexture(texWordsAtlas);
UnloadSound(fxGrab); UnloadSound(fxGrab);
UnloadSound(fxLeave); UnloadSound(fxLeave);
UnloadSound(fxPlace); UnloadSound(fxPlace);
UnloadMusicStream(musSpy); UnloadMusicStream(musSpy);
free(missions); free(missions);
} }

View file

@ -61,15 +61,15 @@ void InitLogoScreen(void)
// Logo Screen Update logic // Logo Screen Update logic
void UpdateLogoScreen(void) void UpdateLogoScreen(void)
{ {
if(!fadeOut) if (!fadeOut)
{ {
fadeValue += 0.02f; fadeValue += 0.02f;
if(fadeValue > 1.01f) if (fadeValue > 1.01f)
{ {
fadeValue = 1.0f; fadeValue = 1.0f;
framesCounter++; framesCounter++;
if(framesCounter % showLogoFrames == 0) if ((framesCounter%showLogoFrames) == 0)
{ {
fadeOut = true; fadeOut = true;
finishScreen = true; finishScreen = true;
@ -77,10 +77,7 @@ void UpdateLogoScreen(void)
} }
} }
if(IsKeyPressed(KEY_ENTER)) if (IsKeyPressed(KEY_ENTER)) finishScreen = true;
{
finishScreen = true;
}
} }
// Logo Screen Draw logic // Logo Screen Draw logic

View file

@ -88,34 +88,33 @@ static Music musMission;
// Mission Screen Functions Definition // Mission Screen Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static void WriteMissionText(); static void WriteMissionText();
static void EndWritting();
static void BlinkKeyword();
// Mission Screen Initialization logic // Mission Screen Initialization logic
void InitMissionScreen(void) void InitMissionScreen(void)
{ {
framesCounter = 0; framesCounter = 0;
finishScreen = 0; finishScreen = 0;
fadeButton = 0.80f; fadeButton = 0.80f;
texBackground = LoadTexture("resources/textures/mission_background.png"); texBackground = LoadTexture("resources/textures/mission_background.png");
texBackline = LoadTexture("resources/textures/mission_backline.png"); texBackline = LoadTexture("resources/textures/mission_backline.png");
sourceRecBackLine = (Rectangle){0,0,GetScreenWidth(), texBackline.height}; sourceRecBackLine = (Rectangle){0,0,GetScreenWidth(), texBackline.height};
destRecBackLine = (Rectangle){0,0,sourceRecBackLine.width, sourceRecBackLine.height}; destRecBackLine = (Rectangle){0,0,sourceRecBackLine.width, sourceRecBackLine.height};
fadeBackLine = 0; fadeBackLine = 0;
fxTransmit = LoadSound("resources/audio/fx_message.ogg"); fxTransmit = LoadSound("resources/audio/fx_message.ogg");
musMission = LoadMusicStream("resources/audio/music_mission.ogg"); musMission = LoadMusicStream("resources/audio/music_mission.ogg");
PlayMusicStream(musMission); PlayMusicStream(musMission);
// Initialize missions // Initialize missions
missions = LoadMissions("resources/missions.txt"); missions = LoadMissions("resources/missions.txt");
missionMaxLength = strlen(missions[currentMission].brief); missionMaxLength = strlen(missions[currentMission].brief);
// Insert line breaks every MAX_LINE_CHAR // Insert line breaks every MAX_LINE_CHAR
int currentLine = 1; int currentLine = 1;
int i = currentLine * MAX_LINE_CHAR; int i = currentLine * MAX_LINE_CHAR;
@ -129,35 +128,35 @@ void InitMissionScreen(void)
i = currentLine*MAX_LINE_CHAR; i = currentLine*MAX_LINE_CHAR;
} }
else i++; else i++;
} }
missionSize = 30; missionSize = 30;
missionLenght = 0; missionLenght = 0;
missionSpeed = 1; missionSpeed = 1;
numberColor = RAYWHITE; numberColor = RAYWHITE;
missionColor = LIGHTGRAY; missionColor = LIGHTGRAY;
keywordColor = (Color){198, 49, 60, 255}; //RED keywordColor = (Color){198, 49, 60, 255}; //RED
numberPosition = (Vector2){150, 185}; numberPosition = (Vector2){150, 185};
missionPosition = (Vector2){numberPosition.x, numberPosition.y + 60}; missionPosition = (Vector2){numberPosition.x, numberPosition.y + 60};
keywordPosition = (Vector2){missionPosition.x, missionPosition.y + MeasureTextEx(fontMission, missions[currentMission].brief, missionSize, 0).y + 60}; keywordPosition = (Vector2){missionPosition.x, missionPosition.y + MeasureTextEx(fontMission, missions[currentMission].brief, missionSize, 0).y + 60};
startWritting = false; startWritting = false;
writeNumber = false; writeNumber = false;
writeMission = false; writeMission = false;
writeKeyword = false; writeKeyword = false;
writeEnd = false; writeEnd = false;
writtingMission = false; writtingMission = false;
showNumberWaitFrames = 30; showNumberWaitFrames = 30;
showMissionWaitFrames = 60; showMissionWaitFrames = 60;
showKeywordWaitFrames = 60; showKeywordWaitFrames = 60;
blinkKeyWord = true; blinkKeyWord = true;
blinkFrames = 15; blinkFrames = 15;
PlaySound(fxTransmit); PlaySound(fxTransmit);
} }
@ -165,37 +164,52 @@ void InitMissionScreen(void)
void UpdateMissionScreen(void) void UpdateMissionScreen(void)
{ {
UpdateMusicStream(musMission); UpdateMusicStream(musMission);
if (!writeEnd) WriteMissionText(); if (!writeEnd) WriteMissionText();
else BlinkKeyword(); else
{
framesCounter++;
if ((framesCounter%blinkFrames) == 0)
{
framesCounter = 0;
blinkKeyWord = !blinkKeyWord;
}
}
if (showButton) if (showButton)
{ {
if (IsKeyPressed(KEY_ENTER) || IsButtonPressed()) if (IsKeyPressed(KEY_ENTER) || IsButtonPressed())
{ {
if (!writeEnd) EndWritting(); if (!writeEnd)
{
writeEnd = true;
writeKeyword = true;
writeNumber = true;
missionLenght = missionMaxLength;
}
else else
{ {
finishScreen = true; finishScreen = true;
showButton = false; showButton = false;
} }
} }
} }
} }
// Mission Screen Draw logic // Mission Screen Draw logic
void DrawMissionScreen(void) void DrawMissionScreen(void)
{ {
// TODO: Draw MISSION screen here! // Draw MISSION screen here!
DrawTexture(texBackground, 0,0, WHITE); DrawTexture(texBackground, 0,0, WHITE);
DrawTexturePro(texBackline, sourceRecBackLine, destRecBackLine, (Vector2){0,0},0, Fade(WHITE, fadeBackLine)); DrawTexturePro(texBackline, sourceRecBackLine, destRecBackLine, (Vector2){0,0},0, Fade(WHITE, fadeBackLine));
if (writeNumber) DrawTextEx(fontMission, FormatText("Filtración #%02i ", currentMission + 1), numberPosition, missionSize + 10, 0, numberColor); if (writeNumber) DrawTextEx(fontMission, FormatText("Filtración #%02i ", currentMission + 1), numberPosition, missionSize + 10, 0, numberColor);
DrawTextEx(fontMission, SubText(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor); DrawTextEx(fontMission, SubText(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor);
if (writeKeyword && blinkKeyWord) DrawTextEx(fontMission, FormatText("Keyword: %s", missions[currentMission].key), keywordPosition, missionSize + 10, 0, keywordColor); if (writeKeyword && blinkKeyWord) DrawTextEx(fontMission, FormatText("Keyword: %s", missions[currentMission].key), keywordPosition, missionSize + 10, 0, keywordColor);
if (showButton) if (showButton)
{ {
if (!writeEnd) DrawButton("saltar"); if (!writeEnd) DrawButton("saltar");
else DrawButton("codificar"); else DrawButton("codificar");
} }
@ -204,8 +218,8 @@ void DrawMissionScreen(void)
// Mission Screen Unload logic // Mission Screen Unload logic
void UnloadMissionScreen(void) void UnloadMissionScreen(void)
{ {
// TODO: Unload MISSION screen variables here! // Unload MISSION screen variables here!
UnloadTexture(texBackground); UnloadTexture(texBackground);
UnloadTexture(texBackline); UnloadTexture(texBackline);
UnloadSound(fxTransmit); UnloadSound(fxTransmit);
UnloadMusicStream(musMission); UnloadMusicStream(musMission);
@ -220,74 +234,58 @@ int FinishMissionScreen(void)
static void WriteMissionText() static void WriteMissionText()
{ {
if(!startWritting) if (!startWritting)
{ {
framesCounter++; framesCounter++;
if(framesCounter % 60 == 0) if (framesCounter % 60 == 0)
{ {
framesCounter = 0; framesCounter = 0;
startWritting = true; startWritting = true;
} }
} }
else if(!writeNumber) else if (!writeNumber)
{ {
framesCounter++; framesCounter++;
fadeBackLine += 0.020f; fadeBackLine += 0.020f;
if(framesCounter % showNumberWaitFrames == 0) if (framesCounter % showNumberWaitFrames == 0)
{ {
framesCounter = 0; framesCounter = 0;
writeNumber = true; writeNumber = true;
showButton = true; showButton = true;
} }
} }
else if(!writeMission) else if (!writeMission)
{ {
framesCounter ++; framesCounter ++;
if(framesCounter % showMissionWaitFrames == 0) if (framesCounter % showMissionWaitFrames == 0)
{ {
framesCounter = 0; framesCounter = 0;
writeMission = true; writeMission = true;
writtingMission = true; writtingMission = true;
} }
} }
else if(writeMission && writtingMission) else if (writeMission && writtingMission)
{ {
framesCounter++; framesCounter++;
if(framesCounter % missionSpeed == 0) if (framesCounter % missionSpeed == 0)
{ {
framesCounter = 0; framesCounter = 0;
missionLenght++; missionLenght++;
if(missionLenght == missionMaxLength) if (missionLenght == missionMaxLength)
{ {
writtingMission = false; writtingMission = false;
} }
} }
} }
else if(!writeKeyword) else if (!writeKeyword)
{ {
framesCounter++; framesCounter++;
if(framesCounter % showKeywordWaitFrames == 0) if (framesCounter % showKeywordWaitFrames == 0)
{ {
framesCounter = 0; framesCounter = 0;
writeKeyword = true; writeKeyword = true;
writeEnd = true; writeEnd = true;
} }
}
}
static void EndWritting()
{
writeEnd = true;
writeKeyword = true;
writeNumber = true;
missionLenght = missionMaxLength;
}
static void BlinkKeyword()
{
framesCounter++;
if(framesCounter % blinkFrames == 0)
{
framesCounter = 0;
blinkKeyWord = !blinkKeyWord;
} }
} }