-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplash.c
More file actions
130 lines (101 loc) · 3.89 KB
/
splash.c
File metadata and controls
130 lines (101 loc) · 3.89 KB
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
#include "raylib.h"
#include "moduleLoop.h"
#include "raylibeditor.h"
#include "splash.h"
#include <stdlib.h>
void SplashPhase()
{
if ((* (struct SplashData *)moduleData).splashPhase == 0)
{
Image image = LoadImage("splash/raylib_logo.png");
Vector2 scaledDims;
Vector2 dims;
dims.x = image.width;
dims.y = image.height;
Vector2 curRes;
curRes.x = GetScreenWidth();
curRes.y = GetScreenHeight();
ScaleVec2(&scaledDims, &dims, &defaultRes, &curRes);
ImageResize(&image, scaledDims.x, scaledDims.y);
(* (struct SplashData *)moduleData).tex = LoadTextureFromImage(image);
UnloadImage(image);
}
else if ((* (struct SplashData *)moduleData).splashPhase == 1)
{
UnloadTexture( (* (struct SplashData *)moduleData).tex );
(* (struct SplashData *)moduleData).logo = LoadModel("splash/evitosoft.glb");
(* (struct SplashData *)moduleData).island = LoadModel("splash/island.glb");
PlayMusicStream((* (struct SplashData *)moduleData).logoMusic);
}
}
void SplashInit()
{
dt.elapsedTime = 0.0f;
struct SplashData *data = (struct SplashData *)malloc(sizeof(struct SplashData));
moduleData = data;
ModuleLoop = SplashLoop;
(*data).camera.position = (Vector3){ 0.0f, 0.0f, 10.0f };
(*data).camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
(*data).camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
(*data).camera.fovy = 45.0f;
(*data).camera.type = CAMERA_PERSPECTIVE;
(*data).logoPos = (Vector3){ 0.0f, 0.0f, 0.0f };
(*data).logoMusic = LoadMusicStream("splash/Start_Sounds_013.ogg");
SetMusicVolume((*data).logoMusic, 0.5f);
(*data).maxPhases = 2;
(*data).splashPhase = 0;
SplashPhase();
}
void SplashExit()
{
UnloadModel( (* (struct SplashData *)moduleData).logo );
UnloadModel( (* (struct SplashData *)moduleData).island );
UnloadMusicStream( (* (struct SplashData *)moduleData).logoMusic );
free( (struct SplashData *)moduleData );
moduleData = NULL;
}
void SplashLoop()
{
int screenWidth = GetScreenWidth();
int screenHeight = GetScreenHeight();
int width = (* (struct SplashData *)moduleData).tex.width;
int height = (* (struct SplashData *)moduleData).tex.height;
BeginDrawing();
if ((* (struct SplashData *)moduleData).splashPhase == 0)
{
ClearBackground(RAYWHITE);
DrawTexture( (* (struct SplashData *)moduleData).tex ,screenWidth/2 - width/2, screenHeight/2 - height/2, WHITE);
if (dt.elapsedTime >= 3.0f)
{
dt.elapsedTime = 0.0f;
(* (struct SplashData *)moduleData).splashPhase++;
SplashPhase();
}
}
else if ((* (struct SplashData *)moduleData).splashPhase == 1)
{
ClearBackground(GOLD);
UpdateCamera(&( (* (struct SplashData *)moduleData).camera ));
UpdateMusicStream( (* (struct SplashData *)moduleData).logoMusic );
BeginMode3D((* (struct SplashData *)moduleData).camera);
DrawModel((* (struct SplashData *)moduleData).logo, (* (struct SplashData *)moduleData).logoPos, 1.0f, WHITE);
DrawModel((* (struct SplashData *)moduleData).island, (* (struct SplashData *)moduleData).logoPos, 1.0f, WHITE);
EndMode3D();
float timePlayed = GetMusicTimePlayed( (* (struct SplashData *)moduleData).logoMusic );
float timeLength = GetMusicTimeLength( (* (struct SplashData *)moduleData).logoMusic );
//DrawText(TextFormat("Time played: %f Time Length: %f Division: %f", timePlayed, timeLength, timePlayed/timeLength), 190, 250, 20, BLACK);
if (timePlayed/timeLength >= 0.9f)//Should be 1.0f but that doesn't work for some reason (fps maybe?).
{
StopMusicStream( (* (struct SplashData *)moduleData).logoMusic );
dt.elapsedTime = 0.0f;
(* (struct SplashData *)moduleData).splashPhase++;
SplashPhase();
}
}
EndDrawing();
if ((* (struct SplashData *)moduleData).splashPhase >= (* (struct SplashData *)moduleData).maxPhases)
{
SplashExit();
SetModule(MENU);
}
}