#include <SFML/Audio.h>
#include <SFML/Graphics.h>
#include <SFML/Config.h>
#include <SFML/Network/IPAddress.h>
#include <SFML/Network/SocketStatus.h>
#include <SFML/Network/Types.h>
int main()
{
char Running = 1; // Hold boolean that says if we need to process a close
int BackgroundRed = 55, BackgroundGreen = 238, BackgroundBlue = 0, mnMnuLoc = 1, gameState = 1; // Set initial color values, will likely be tiled image in future
sfWindowSettings Settings = {32, 8, 2}; // Window settings
sfVideoMode Mode = {800, 600, 32}; // Set render area and color depth
// Prepare the SFML packages
sfRenderWindow* App;
sfImage* mnuLoadImage;
sfSprite* mnuLoadSprite;
sfFont* mnuFont;
sfString* mnuText1;
sfString* mnuText2;
sfString* mnuText3;
sfString* mnuText4;
sfMusic* mnuMusic;
sfEvent Event;
// Create the main window
App = sfRenderWindow_Create(Mode, "Fast Track Racers", sfResize | sfClose, Settings);
sfWindow_UseVerticalSync(App, 1);
// Load and play the menu music
mnuMusic = sfMusic_CreateFromFile("Audio/Menu.ogg");
sfMusic_SetLoop(mnuMusic, sfTrue);
sfMusic_Play(mnuMusic);
// Load a sprite to display
mnuLoadImage = sfImage_CreateFromFile("Images/menu_Car.jpg");
mnuLoadSprite = sfSprite_Create();
sfSprite_SetImage(mnuLoadSprite, mnuLoadImage);
sfSprite_SetPosition(mnuLoadSprite, 60, 100);
// Load Main Menu Text
mnuFont = sfFont_CreateFromFile("Fonts/arial.ttf", 50, NULL);
mnuText1 = sfString_Create();
mnuText2 = sfString_Create();
mnuText3 = sfString_Create();
mnuText4 = sfString_Create();
sfString_SetPosition(mnuText1, 100, 100);
sfString_SetPosition(mnuText2, 100, 150);
sfString_SetPosition(mnuText3, 100, 200);
sfString_SetPosition(mnuText4, 100, 250);
sfString_SetText(mnuText1, "Single Player");
sfString_SetText(mnuText2, "Multiplayer");
sfString_SetText(mnuText3, "Options");
sfString_SetText(mnuText4, "Exit");
sfString_SetFont(mnuText1, mnuFont);
sfString_SetFont(mnuText2, mnuFont);
sfString_SetFont(mnuText3, mnuFont);
sfString_SetFont(mnuText4, mnuFont);
sfString_SetSize(mnuText1, 32);
sfString_SetSize(mnuText2, 32);
sfString_SetSize(mnuText3, 32);
sfString_SetSize(mnuText4, 32);
// Start the game loop
while (sfRenderWindow_IsOpened(App))
{
// Process events
while (sfRenderWindow_GetEvent(App, &Event))
{
switch(gameState)
{
case(0):
Running = 0;
break;
case(1): // Main menu
if (Event.Type == sfEvtKeyPressed)
{
if(Event.Key.Code == sfKeyReturn && mnMnuLoc == 4)
gameState = 0;
if (Event.Key.Code == sfKeyUp)
mnMnuLoc--;
if (Event.Key.Code == sfKeyDown)
mnMnuLoc++;
if (Event.Key.Code == sfKeyEscape)
sfRenderWindow_Close(App);
}
}
}
// Clear the screen
sfRenderWindow_Clear(App, sfColor_FromRGB(BackgroundRed,BackgroundGreen,BackgroundBlue));
switch(gameState)
{
case(0): // End the game
sfRenderWindow_Close(App);
break;
case(1): // Main menu
// Draw mnuString
sfRenderWindow_DrawString(App, mnuText1);
sfRenderWindow_DrawString(App, mnuText2);
sfRenderWindow_DrawString(App, mnuText3);
sfRenderWindow_DrawString(App, mnuText4);
// Main Menu Handling
if(mnMnuLoc<1)
mnMnuLoc = 4;
if(mnMnuLoc>4)
mnMnuLoc = 1;
switch(mnMnuLoc)
{
case(1):
sfSprite_SetPosition(mnuLoadSprite, 60, 100);
break;
case(2):
sfSprite_SetPosition(mnuLoadSprite, 60, 150);
break;
case(3):
sfSprite_SetPosition(mnuLoadSprite, 60, 200);
break;
case(4):
sfSprite_SetPosition(mnuLoadSprite, 60, 250);
break;
}
// Draw the sprite
sfRenderWindow_DrawSprite(App, mnuLoadSprite);
break;
}
// Update the window
sfRenderWindow_Display(App);
}
sfMusic_Destroy(mnuMusic);
sfString_Destroy(mnuText1);
sfString_Destroy(mnuText2);
sfString_Destroy(mnuText3);
sfString_Destroy(mnuText4);
sfFont_Destroy(mnuFont);
sfFont_Destroy(mnuFont);
sfFont_Destroy(mnuFont);
sfFont_Destroy(mnuFont);
sfSprite_Destroy(mnuLoadSprite);
sfImage_Destroy(mnuLoadImage);
sfRenderWindow_Destroy(App);
return EXIT_SUCCESS;
}
can anyone explain why the text freezes the program on exit?