aboutsummaryrefslogtreecommitdiff
path: root/games/just_do/screens/screen_logo.c
blob: 9639602dead191ec9b9f9598b2cf36a371da8604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**********************************************************************************************
*
*   raylib - Standard Game template
*
*   Logo Screen Functions Definitions (Init, Update, Draw, Unload)
*
*   Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
*   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>

//----------------------------------------------------------------------------------
// Global Variables Definition (local to this module)
//----------------------------------------------------------------------------------

// Logo screen global variables
static int framesCounter;
static int finishScreen;

const char msgLogoA[64] = "A simple and easy-to-use library";
const char msgLogoB[64] = "to learn videogames programming";

int logoPositionX;
int logoPositionY;

int raylibLettersCount = 0;

int topSideRecWidth = 16;
int leftSideRecHeight = 16;

int bottomSideRecWidth = 16;
int rightSideRecHeight = 16;

char raylib[8] = "       \0";   // raylib text array, max 8 letters

int logoScreenState = 0;        // Tracking animation states (State Machine)
bool msgLogoADone = false;
bool msgLogoBDone = false;

int lettersCounter = 0;
char msgBuffer[128] = { ' ' };

//----------------------------------------------------------------------------------
// Logo Screen Functions Definition
//----------------------------------------------------------------------------------

// Logo Screen Initialization logic
void InitLogoScreen(void)
{
    // Initialize LOGO screen variables here!
    framesCounter = 0;
    finishScreen = 0;
    
    logoPositionX = GetScreenWidth()/2 - 128;
    logoPositionY = GetScreenHeight()/2 - 128;
}

// Logo Screen Update logic
void UpdateLogoScreen(void)
{
    // Update LOGO screen
    framesCounter++;    // Count frames
    
    // Update LOGO screen variables
    if (logoScreenState == 0)                 // State 0: Small box blinking
    {
        framesCounter++;

        if (framesCounter == 120)
        {
            logoScreenState = 1;
            framesCounter = 0;      // Reset counter... will be used later...
        }
    }
    else if (logoScreenState == 1)            // State 1: Top and left bars growing
    {
        topSideRecWidth += 4;
        leftSideRecHeight += 4;

        if (topSideRecWidth == 256) logoScreenState = 2;
    }
    else if (logoScreenState == 2)            // State 2: Bottom and right bars growing
    {
        bottomSideRecWidth += 4;
        rightSideRecHeight += 4;

        if (bottomSideRecWidth == 256)
        {
            lettersCounter = 0;
            for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' ';

            logoScreenState = 3;
        }
    }
    else if (logoScreenState == 3)            // State 3: Letters appearing (one by one)
    {
        framesCounter++;

        // Every 12 frames, one more letter!
        if ((framesCounter%12) == 0) raylibLettersCount++;

        switch (raylibLettersCount)
        {
            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;
        }

        if (raylibLettersCount >= 10)
        {
            // Write raylib description messages
            if ((framesCounter%2) == 0) lettersCounter++;

            if (!msgLogoADone)
            {
                if (lettersCounter <= strlen(msgLogoA)) strncpy(msgBuffer, msgLogoA, lettersCounter);
                else
                {
                    for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' ';

                    lettersCounter = 0;
                    msgLogoADone = true;
                }
            }
            else if (!msgLogoBDone)
            {
                if (lettersCounter <= strlen(msgLogoB)) strncpy(msgBuffer, msgLogoB, lettersCounter);
                else
                {
                    msgLogoBDone = true;
                    framesCounter = 0;
                    PlaySound(levelWin);
                }
            }
        }
    }

    // Wait for 2 seconds (60 frames) before jumping to TITLE screen
    if (msgLogoBDone)
    {
        framesCounter++;
        
        if (framesCounter > 90) finishScreen = true;
    }
}

// Logo Screen Draw logic
void DrawLogoScreen(void)
{
    // Draw LOGO screen
    if (logoScreenState == 0)
    {
        if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY - 60, 16, 16, BLACK);
    }
    else if (logoScreenState == 1)
    {
        DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
        DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK);
    }
    else if (logoScreenState == 2)
    {
        DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
        DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK);

        DrawRectangle(logoPositionX + 240, logoPositionY - 60, 16, rightSideRecHeight, BLACK);
        DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK);
    }
    else if (logoScreenState == 3)
    {         
        DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
        DrawRectangle(logoPositionX, logoPositionY + 16 - 60, 16, leftSideRecHeight - 32, BLACK);

        DrawRectangle(logoPositionX + 240, logoPositionY + 16 - 60, 16, rightSideRecHeight - 32, BLACK);
        DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK);

        DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112 - 60, 224, 224, RAYWHITE);

        DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48 - 60, 50, BLACK);

        if (!msgLogoADone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY);
        else
        {
            DrawText(msgLogoA, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY);

            if (!msgLogoBDone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoB, 30)/2, logoPositionY + 280, 30, GRAY);
            else
            {
                DrawText(msgLogoB, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 280, 30, GRAY);
            }
        }
    }
}

// Logo Screen Unload logic
void UnloadLogoScreen(void)
{
    // TODO: Unload LOGO screen variables here!
}

// Logo Screen should finish?
int FinishLogoScreen(void)
{
    return finishScreen;
}