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
|
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Title Screen Functions Definitions (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-2020 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"
//----------------------------------------------------------------------------------
// Global Variables Definition (local to this module)
//----------------------------------------------------------------------------------
// Title screen global variables
static int framesCounter = 0;
static int finishScreen = 0;
static Texture2D texTitle = { 0 };
static Texture2D texLogo = { 0 };
static int titlePositionY = 0;
static int titleCounter = 0;
//----------------------------------------------------------------------------------
// Title Screen Functions Definition
//----------------------------------------------------------------------------------
// Title Screen Initialization logic
void InitTitleScreen(void)
{
framesCounter = 0;
finishScreen = 0;
texTitle = LoadTexture("resources/title.png");
texLogo = LoadTexture("resources/raylib_logo.png");
player = GenerateCharacter();
titlePositionY = -200;
}
// Title Screen Update logic
void UpdateTitleScreen(void)
{
framesCounter++;
if (framesCounter > 5)
{
int partToChange = GetRandomValue(0, 4);
if (partToChange == 0)
{
player.head = GetRandomValue(0, texHead.width/BASE_HEAD_WIDTH - 1);
player.colHead = headColors[GetRandomValue(0, 5)];
}
else if (partToChange == 1) player.eyes = GetRandomValue(0, texEyes.width/BASE_EYES_WIDTH - 1);
else if (partToChange == 2) player.nose = GetRandomValue(0, texNose.width/BASE_NOSE_WIDTH - 1);
else if (partToChange == 3) player.mouth = GetRandomValue(0, texMouth.width/BASE_MOUTH_WIDTH - 1);
else if (partToChange == 4)
{
player.hair = GetRandomValue(0, texHair.width/BASE_HAIR_WIDTH - 1);
player.colHair = hairColors[GetRandomValue(0, 9)];
}
framesCounter = 0;
}
titlePositionY += 3;
if (titlePositionY > 40) titlePositionY = 40;
titleCounter++;
if (IsKeyPressed(KEY_ENTER)) finishScreen = 1;
}
// Title Screen Draw logic
void DrawTitleScreen(void)
{
DrawTexture(background, 0, 0, GetColor(0xf6aa60ff));
// Draw face, parts keep changing ranomly
DrawCharacter(player, (Vector2){ GetScreenWidth()/2 - 125, 80 });
// Draw face rectangles
//DrawRectangleRec((Rectangle){ GetScreenWidth()/2 - BASE_EYES_WIDTH/2, 270, BASE_EYES_WIDTH, texEyes.height }, Fade(GREEN, 0.3f));
//DrawRectangleRec((Rectangle){ GetScreenWidth()/2 - BASE_NOSE_WIDTH/2, 355, BASE_NOSE_WIDTH, texNose.height }, Fade(SKYBLUE, 0.3f));
//DrawRectangleRec((Rectangle){ GetScreenWidth()/2 - BASE_MOUTH_WIDTH/2, 450, BASE_MOUTH_WIDTH, texMouth.height }, Fade(RED, 0.3f));
DrawTexture(texTitle, GetScreenWidth()/2 - texTitle.width/2, titlePositionY, WHITE);
if (titleCounter > 180)
{
if (GuiButton((Rectangle){ GetScreenWidth()/2 - 440/2, 580, 440, 80 }, "START DATE!", -1)) finishScreen = 1; // GAMEPLAY
}
DrawText("powered by", 20, GetScreenHeight() - texLogo.height - 35, 10, BLACK);
DrawTexture(texLogo, 20, GetScreenHeight() - texLogo.height - 20, WHITE);
}
// Title Screen Unload logic
void UnloadTitleScreen(void)
{
UnloadTexture(texTitle);
UnloadTexture(texLogo);
}
// Title Screen should finish?
int FinishTitleScreen(void)
{
return finishScreen;
}
|