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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
#include "Voids.h"
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 720;
//Load Texture Function
SDL_Texture *loadtexture(std::string file, SDL_Renderer *renderertarget)
{
SDL_Surface *surface = IMG_Load(file.c_str());
SDL_Texture *texture = nullptr;
texture = SDL_CreateTextureFromSurface(renderertarget, surface);
SDL_FreeSurface(surface);
return texture;
}
SDL_Window *menuwindow = SDL_CreateWindow("This Is YOUR World (CLOSED ALPHA 0.2)", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
//Create Renderer
SDL_Renderer *renderer = SDL_CreateRenderer(menuwindow, -1, SDL_RENDERER_ACCELERATED);
//Load Textures
SDL_Texture *mainmenu_texture = loadtexture("images/mainmenu_texture.jpg", renderer);
SDL_Texture *gamebackground = loadtexture("images/worldbackground.jpg", renderer);
SDL_Event event;
//TTF Things
TTF_Font *buttonfont = TTF_OpenFont("fonts/font3.ttf", 20);
TTF_Font *pixelfont = TTF_OpenFont("fonts/font.ttf", 40);
TTF_Font *sharp_pixelfont_100 = TTF_OpenFont("fonts/font2.ttf", 100);
TTF_Font *sharp_pixelfont_20 = TTF_OpenFont("fonts/font2.ttf", 20);
TTF_Font *sharp_pixelfont = TTF_OpenFont("fonts/font2.ttf", 50);
TTF_Font *font = TTF_OpenFont("fonts/font3.ttf", 100);
SDL_Color black = { 0, 0, 0, 0 };
SDL_Color red = { 255, 0, 0, 255 };
//Create InfoBoxes
block northamerica_infobox(renderer, "images/infobox.png", 250, 200, 32, 32);
block southamerica_infobox(renderer, "images/infobox.png", 400, 400, 32, 32);
block africa_infobox(renderer, "images/infobox.png", 700, 300, 32, 32);
block europe_infobox(renderer, "images/infobox.png", 703, 157, 32, 32);
block asia_infobox(renderer, "images/infobox.png", 1000, 200, 32, 32);
block australia_infobox(renderer, "images/infobox.png", 1200, 450, 32, 32);
//Continent Text
block northamericatextbox(renderer, "images/northamericatext.png", 25, 550, 1000, 200);
block southamericatextbox(renderer, "images/southamericatext.png", 50, 550, 1000, 200);
block africatextbox(renderer, "images/africatext.png", 0, 550, 1000, 200);
block europetextbox(renderer, "images/europetext.png", 0, 550, 1000, 200);
block asiatextbox(renderer, "images/asiatext.png", 0, 550, 1000, 200);
block australiatextbox(renderer, "images/australiatext.png", 0, 550, 1000, 200);
block button1(renderer, "images/button.png", 465, 160, 350, 100);
block button2(renderer, "images/button.png", 465, 310, 350, 100);
block button3(renderer, "images/button.png", 465, 460, 350, 100);
block button4(renderer, "images/gotomainmenubutton.png", 0, 610, 350, 100);
//Title Text
SDL_Surface *textsurface1 = TTF_RenderText_Solid(font, "This Is YOUR World!", red);
SDL_Texture *title_text = SDL_CreateTextureFromSurface(renderer, textsurface1);
//Button 1 Text
SDL_Surface *textsurface2 = TTF_RenderText_Solid(sharp_pixelfont, "Start Game", black);
SDL_Texture *startgame_text = SDL_CreateTextureFromSurface(renderer, textsurface2);
//Button 2 Text
SDL_Surface *textsurface3 = TTF_RenderText_Solid(sharp_pixelfont, "Fullscreen", black);
SDL_Texture *options_text = SDL_CreateTextureFromSurface(renderer, textsurface3);
//Button 3 Text
SDL_Surface *textsurface4 = TTF_RenderText_Solid(sharp_pixelfont, "Quit", black);
SDL_Texture *quit_text = SDL_CreateTextureFromSurface(renderer, textsurface4);
bool fullscreen = false;
bool gamerunning = false;
bool menurunning;
void Menu()
{
//Menu Loop Initializer
menurunning = true;
SDL_QueryTexture(mainmenu_texture, NULL, NULL, NULL, NULL);
SDL_Rect title_textrect;
title_textrect.y = 30;
title_textrect.x = 200;
SDL_QueryTexture(title_text, NULL, NULL, &title_textrect.w, &title_textrect.h);
SDL_FreeSurface(textsurface1);
textsurface1 = nullptr;
SDL_Rect start_textrect;
start_textrect.y = 200;
start_textrect.x = 490;
SDL_QueryTexture(startgame_text, NULL, NULL, &start_textrect.w, &start_textrect.h);
SDL_FreeSurface(textsurface2);
textsurface2 = nullptr;
SDL_Rect options_textrect;
options_textrect.y = 350;
options_textrect.x = 486;
SDL_QueryTexture(options_text, NULL, NULL, &options_textrect.w, &options_textrect.h);
SDL_FreeSurface(textsurface3);
textsurface3 = nullptr;
SDL_Rect quit_textrect;
quit_textrect.y = 500;
quit_textrect.x = 575;
SDL_QueryTexture(quit_text, NULL, NULL, &quit_textrect.w, &quit_textrect.h);
SDL_FreeSurface(textsurface4);
textsurface4 = nullptr;
while (menurunning)
{
while (SDL_PollEvent(&event) != 0)
{
button1.fade(event);
button2.fade(event);
button3.fade(event);
button1.click(event);
button2.click(event);
button3.click(event);
if (event.type == SDL_QUIT)
menurunning = false;
}
//Button Actions
if (button3.clicked)
menurunning = false;
if (button2.clicked)
{
SDL_DestroyWindow(menuwindow);
fullscreen = true;
}
if (button1.clicked)
{
SDL_DestroyTexture(mainmenu_texture);
mainmenu_texture = nullptr;
button1.~block();
button2.~block();
button3.~block();
gamerunning = true;
menurunning = false;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, mainmenu_texture, NULL, NULL);
button1.draw(renderer);
button2.draw(renderer);
button3.draw(renderer);
SDL_RenderCopy(renderer, title_text, NULL, &title_textrect);
SDL_RenderCopy(renderer, startgame_text, NULL, &start_textrect);
SDL_RenderCopy(renderer, options_text, NULL, &options_textrect);
SDL_RenderCopy(renderer, quit_text, NULL, &quit_textrect);
SDL_RenderPresent(renderer);
}
}
void Game()
{
SDL_QueryTexture(gamebackground, NULL, NULL, NULL, NULL);
while (gamerunning)
{
while (SDL_PollEvent(&event) != 0)
{
button4.fade(event);
northamerica_infobox.fade(event);
southamerica_infobox.fade(event);
africa_infobox.fade(event);
europe_infobox.fade(event);
asia_infobox.fade(event);
australia_infobox.fade(event);
northamerica_infobox.click(event);
southamerica_infobox.click(event);
africa_infobox.click(event);
europe_infobox.click(event);
asia_infobox.click(event);
australia_infobox.click(event);
button4.click(event);
}
if (button4.clicked)
{
SDL_DestroyWindow(menuwindow);
SDL_DestroyTexture(gamebackground);
gamebackground = nullptr;
button4.~block();
northamerica_infobox.~block();
southamerica_infobox.~block();
africa_infobox.~block();
europe_infobox.~block();
asia_infobox.~block();
australia_infobox.~block();
gamerunning = false;
menurunning = true;
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, gamebackground, NULL, NULL);
//Draw Continent Names
if (northamerica_infobox.faded)
northamericatextbox.draw(renderer);
if (southamerica_infobox.faded)
southamericatextbox.draw(renderer);
if (africa_infobox.faded)
africatextbox.draw(renderer);
if (europe_infobox.faded)
europetextbox.draw(renderer);
if (asia_infobox.faded)
asiatextbox.draw(renderer);
if (australia_infobox.faded)
australiatextbox.draw(renderer);
button4.draw(renderer);
northamerica_infobox.draw(renderer);
southamerica_infobox.draw(renderer);
africa_infobox.draw(renderer);
europe_infobox.draw(renderer);
asia_infobox.draw(renderer);
australia_infobox.draw(renderer);
SDL_RenderPresent(renderer);
}
}
void Unload()
{
//Memory Management
SDL_DestroyWindow(menuwindow);
menuwindow = nullptr;
SDL_DestroyTexture(mainmenu_texture);
SDL_DestroyTexture(gamebackground);
gamebackground = nullptr;
mainmenu_texture = nullptr;
SDL_DestroyRenderer(renderer);
renderer = nullptr;
button1.~block();
button2.~block();
button3.~block();
button4.~block();
northamerica_infobox.~block();
southamerica_infobox.~block();
africa_infobox.~block();
asia_infobox.~block();
europe_infobox.~block();
australia_infobox.~block();
northamericatextbox.~block();
southamericatextbox.~block();
africatextbox.~block();
asiatextbox.~block();
europetextbox.~block();
australiatextbox.~block();
TTF_CloseFont(pixelfont);
TTF_CloseFont(sharp_pixelfont);
TTF_CloseFont(sharp_pixelfont_100);
TTF_CloseFont(sharp_pixelfont_20);
TTF_CloseFont(buttonfont);
SDL_Quit();
}
|