forked from mswlandi/megamania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.c
146 lines (121 loc) · 5.65 KB
/
layout.c
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
#define WIDTH 800
#define HEIGHT 600
#include "layout.h"
void Layout_Highscores(sfRenderWindow* window, sfSprite* background)
{
int i; // Count
int flagButton = 0;
FILE *highscores;
sfText* scoreSign;
sfText* scoreText1;
sfText* scoreText2;
sfText* scoreText3;
sfText* scoreText4;
sfText* scoreText5;
char strings[5][50];
char positions[5][10];
sfEvent event;
TYPE_BUTTON backButton;
for(i = 0; i < 5; i++)
{
itoa(i+1, positions[i], 10);
strcat(positions[i], " - ");
}
highscores = fopen("highscores.txt", "r");
if(!highscores)
printf("Open highscores.txt error!\n");
else
{
// Setting back's button
backButton = Utility_CreateButton("B A C K", 40, (sfVector2f){WIDTH - 120, 500}, (sfVector2f){200, 100}, sfColor_fromRGB(18, 16, 18));
// S C O R E
scoreSign = Text_Create("H I G H S C O R E", "Quantify Bold v2.6.ttf", 40, sfColor_fromRGB(255, 255, 255), (sfVector2f){WIDTH/2, HEIGHT/6});
// Highscores
for(i = 0; i < 5; i++)
{
fscanf(highscores, "%s", strings[i]);
strcat(positions[i], strings[i]);
}
scoreText1 = Text_Create(positions[0], "Quantify Bold v2.6.ttf", 30, sfColor_fromRGB(255, 255, 255), (sfVector2f){WIDTH/2, HEIGHT/3});
scoreText2 = Text_Create(positions[1], "Quantify Bold v2.6.ttf", 30, sfColor_fromRGB(255, 255, 255), (sfVector2f){WIDTH/2, HEIGHT/3 + 50});
scoreText3 = Text_Create(positions[2], "Quantify Bold v2.6.ttf", 30, sfColor_fromRGB(255, 255, 255), (sfVector2f){WIDTH/2, HEIGHT/3 + 100});
scoreText4 = Text_Create(positions[3], "Quantify Bold v2.6.ttf", 30, sfColor_fromRGB(255, 255, 255), (sfVector2f){WIDTH/2, HEIGHT/3 + 150});
scoreText5 = Text_Create(positions[4], "Quantify Bold v2.6.ttf", 30, sfColor_fromRGB(255, 255, 255), (sfVector2f){WIDTH/2, HEIGHT/3 + 200});
fclose(highscores);
// Displaying the window
do
{
/// Code to close the window
while(sfRenderWindow_pollEvent(window, &event))
{
// Close window : exit
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
/// Code to check if mouse is on the button
flagButton = Utility_isOnButton(&backButton, window);
/// Drawing
sfRenderWindow_clear(window, sfColor_fromRGB(0,0,0));
// Background
sfRenderWindow_drawSprite(window, background, NULL);
// S C O R E
sfRenderWindow_drawText(window, scoreSign, NULL);
// Highscores
sfRenderWindow_drawText(window, scoreText1, NULL);
sfRenderWindow_drawText(window, scoreText2, NULL);
sfRenderWindow_drawText(window, scoreText3, NULL);
sfRenderWindow_drawText(window, scoreText4, NULL);
sfRenderWindow_drawText(window, scoreText5, NULL);
// Back button
sfRenderWindow_drawRectangleShape(window, backButton.base, NULL);
sfRenderWindow_drawText(window, backButton.text, NULL);
sfRenderWindow_display(window);
}while(!flagButton);
}
}
void Layout_Credits(sfRenderWindow* window, sfSprite* background)
{
sfEvent event;
TYPE_BUTTON backButton;
int flagButton = 0; // If it's 0, you didn't click on the button. Else, you did.
sfText* creators; // It talks about who creates this game
sfText* spritesPack; // Where we pick these sprites
sfText* why; // Why we did it
/// Setting texts
// Set creators
creators = Text_Create("C R E A T O R S: \nMarcos Samuel Landi\nHenry Bernardo K. de Avila.", "Quantify Bold v2.6.ttf",
20, sfColor_fromRGB(255,255,255), (sfVector2f){WIDTH*3/8, 200});
// Set spritesPack
spritesPack = Text_Create("S P R I T E ' S P A C K :\n Space Shooter (Redux, plus fonts and sounds)\nby Kenney Vleugels (www.kenney.nl).", "Quantify Bold v2.6.ttf",
20, sfColor_fromRGB(255,255,255), (sfVector2f){WIDTH/2, 300});
// Set why
why = Text_Create("W H Y H A V E Y O U D O N E T H I S ?\n Well, this game is the final project of\n Programming and Algorythms, a subject in UFRGS.", "Quantify Bold v2.6.ttf",
20, sfColor_fromRGB(255,255,255), (sfVector2f){WIDTH/2, 400});
// Setting back's button
backButton = Utility_CreateButton("B A C K", 40, (sfVector2f){WIDTH - 200, 100}, (sfVector2f){200, 100}, sfColor_fromRGB(18, 16, 18));
do
{
/// Code to close the window
while(sfRenderWindow_pollEvent(window, &event))
{
// Close window : exit
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
flagButton = Utility_isOnButton(&backButton, window);
/// Drawing on the screen
sfRenderWindow_clear(window, sfColor_fromRGB(0,0,0));
// Background
sfRenderWindow_drawSprite(window, background, NULL);
// BackButton
sfRenderWindow_drawRectangleShape(window, backButton.base, NULL);
sfRenderWindow_drawText(window, backButton.text, NULL);
// Why
sfRenderWindow_drawText(window, why, NULL);
// Sprites pack
sfRenderWindow_drawText(window, spritesPack, NULL);
// Creators
sfRenderWindow_drawText(window, creators, NULL);
sfRenderWindow_display(window);
}while(!flagButton);
}