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