Review games

This commit is contained in:
Ray
2019-05-21 22:36:52 +02:00
parent b1806f6600
commit 477f05db13
10 changed files with 224 additions and 89 deletions

View File

@ -222,7 +222,7 @@ static char *StringReplace(char *orig, char *rep, char *with)
// Count the number of replacements needed
ins = orig;
for (count = 0; tmp = strstr(ins, rep); ++count)
for (count = 0; (tmp = strstr(ins, rep)); ++count)
{
ins = tmp + len_rep;
}

View File

@ -26,19 +26,32 @@
#include "raylib.h"
#include "screens.h"
#define LOGO_RECS_SIDE 16
//----------------------------------------------------------------------------------
// Global Variables Definition (local to this module)
//----------------------------------------------------------------------------------
// Logo screen global variables
static int framesCounter;
static int finishScreen;
static int framesCounter = 0;
static int finishScreen = 0;
static Texture2D logoCW;
static int logoPositionX = 0;
static int logoPositionY = 0;
static float fadeValue;
static int showLogoFrames;
static bool fadeOut;
static int lettersCount = 0;
static int topSideRecWidth = 0;
static int leftSideRecHeight = 0;
static int bottomSideRecWidth = 0;
static int rightSideRecHeight = 0;
static char raylib[8] = { 0 }; // raylib text array, max 8 letters
static int state = 0; // Tracking animation states (State Machine)
static float alpha = 1.0f; // Useful for fading
static Texture2D texLogoCW = { 0 }; // Cinamon Works texture
//----------------------------------------------------------------------------------
// Logo Screen Functions Definition
@ -47,53 +60,183 @@ static bool fadeOut;
// Logo Screen Initialization logic
void InitLogoScreen(void)
{
framesCounter = 0;
// Initialize LOGO screen variables here!
finishScreen = 0;
framesCounter = 0;
lettersCount = 0;
logoCW = LoadTexture("resources/textures/cw_logo.png");
logoPositionX = GetScreenWidth()/2 - 128;
logoPositionY = GetScreenHeight()/2 - 128;
showLogoFrames = 60;
fadeValue = 0;
topSideRecWidth = LOGO_RECS_SIDE;
leftSideRecHeight = LOGO_RECS_SIDE;
bottomSideRecWidth = LOGO_RECS_SIDE;
rightSideRecHeight = LOGO_RECS_SIDE;
fadeOut = false;
for (int i = 0; i < 8; i++) raylib[i] = '\0';
state = 0;
alpha = 1.0f;
texLogoCW = LoadTexture("resources/textures/cw_logo.png");
}
// Logo Screen Update logic
void UpdateLogoScreen(void)
{
if (!fadeOut)
{
fadeValue += 0.02f;
if (fadeValue > 1.01f)
// Update LOGO screen variables here!
if (state == 0) // State 0: Small box blinking
{
framesCounter++;
if (framesCounter == 80)
{
fadeValue = 1.0f;
framesCounter++;
if ((framesCounter%showLogoFrames) == 0)
state = 1;
framesCounter = 0; // Reset counter... will be used later...
}
}
else if (state == 1) // State 1: Top and left bars growing
{
topSideRecWidth += 8;
leftSideRecHeight += 8;
if (topSideRecWidth == 256) state = 2;
}
else if (state == 2) // State 2: Bottom and right bars growing
{
bottomSideRecWidth += 8;
rightSideRecHeight += 8;
if (bottomSideRecWidth == 256) state = 3;
}
else if (state == 3) // State 3: Letters appearing (one by one)
{
framesCounter++;
if (framesCounter/10) // Every 12 frames, one more letter!
{
lettersCount++;
framesCounter = 0;
}
switch (lettersCount)
{
case 1: raylib[0] = 'r'; break;
case 2: raylib[1] = 'a'; break;
case 3: raylib[2] = 'y'; break;
case 4: raylib[3] = 'l'; break;
case 5: raylib[4] = 'i'; break;
case 6: raylib[5] = 'b'; break;
default: break;
}
// When all letters have appeared...
if (lettersCount >= 10)
{
state = 4;
framesCounter = 0;
}
}
else if (state == 4)
{
framesCounter++;
if (framesCounter > 100)
{
alpha -= 0.02f;
if (alpha <= 0.0f)
{
fadeOut = true;
finishScreen = true;
}
}
}
if (IsKeyPressed(KEY_ENTER)) finishScreen = true;
alpha = 0.0f;
framesCounter = 0;
state = 5;
}
}
}
else if (state == 5)
{
alpha += 0.02f;
if (alpha >= 1.0f) alpha = 1.0f;
framesCounter++;
if (framesCounter > 200)
{
framesCounter = 0;
state = 6;
}
}
else if (state == 6)
{
alpha -= 0.02f;
if (alpha >= 1.0f) alpha = 1.0f;
framesCounter++;
if (framesCounter > 100)
{
framesCounter = 0;
finishScreen = 1;
}
}
}
// Logo Screen Draw logic
void DrawLogoScreen(void)
{
DrawTexture(logoCW, GetScreenWidth()/2 - logoCW.width/2, GetScreenHeight()/2 - logoCW.height/2, Fade(WHITE, fadeValue));
if (state == 0)
{
if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
}
else if (state == 1)
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
}
else if (state == 2)
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
}
else if (state == 3)
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
if (framesCounter > 20) DrawText("powered by", logoPositionX, logoPositionY - 27, 20, Fade(DARKGRAY, alpha));
}
else if ((state == 5) || (state == 6)) DrawTexture(texLogoCW, GetScreenWidth()/2 - texLogoCW.width/2, GetScreenHeight()/2 - texLogoCW.height/2, Fade(WHITE, alpha));
}
// Logo Screen Unload logic
void UnloadLogoScreen(void)
{
UnloadTexture(logoCW);
// Unload LOGO screen variables here!
UnloadTexture(texLogoCW);
}
// Logo Screen should finish?
int FinishLogoScreen(void)
{
return finishScreen;
}
}

View File

@ -1,13 +1,14 @@
/*******************************************************************************************
*
* raylib - transmission mission
* TRANSMISSION MISSION [GLOBAL GAME JAM 2018]
*
* Code and transmit the right message
* Code the different filtration messages to be send to newspaper
* to avoid being understood in case of interception.
*
* This game has been created using raylib (www.raylib.com)
* This game has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
* Copyright (c) 2018 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@ -53,13 +54,9 @@ static void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
int main(void)
{
// Initialization
// Initialization (Note windowTitle is unused on Android)
//---------------------------------------------------------
#ifndef PLATFORM_ANDROID
SetConfigFlags(FLAG_SHOW_LOGO); // | FLAG_FULLSCREEN_MODE);
#endif
// Note windowTitle is unused on Android
InitWindow(screenWidth, screenHeight, "raylib game - transmission mission");
InitWindow(screenWidth, screenHeight, "transmission mission [GGJ18]");
// Global data loading (assets that must be available in all screens, i.e. fonts)
InitAudioDevice();