So, I'm trying to draw a menu screen. Here's the header file and the main.cpp:
#include <SFML/Graphics.hpp>
//declarations
#define MENU 1
#define GAME 2
#define END 3
int game_state = MENU;
sf::RenderWindow App(sf::VideoMode::GetMode(1), "SFML Window");
// GRAPHICS
int load_graphics_menu(void)
{
//menu background
sf::Image menu_background;
if (!menu_background.LoadFromFile("data/art/menu/menu_background.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_background;
spt_menu_background.SetImage(menu_background);
//menu play button
sf::Image menu_playbutton;
if (!menu_playbutton.LoadFromFile("data/art/menu/menu_playbutton.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_playbutton;
spt_menu_playbutton.SetImage(menu_playbutton);
spt_menu_playbutton.SetPosition(475.f, 235.f);
//menu play button highlighted
sf::Image menu_playbutton_hl;
if (!menu_playbutton_hl.LoadFromFile("data/art/menu/menu_playbutton_hl.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_playbutton_hl;
spt_menu_playbutton_hl.SetImage(menu_playbutton_hl);
spt_menu_playbutton_hl.SetPosition(475.f, 235.f);
//menu instruction button
sf::Image menu_instructionbutton;
if (!menu_instructionbutton.LoadFromFile("data/art/menu/menu_instructionbutton.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_instructionbutton;
spt_menu_instructionbutton.SetImage(menu_instructionbutton);
spt_menu_instructionbutton.SetPosition(426.f, 324.f);
//menu instruction button highlighted
sf::Image menu_instructionbutton_hl;
if (!menu_instructionbutton_hl.LoadFromFile("data/art/menu/menu_instructionbutton_hl.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_instructionbutton_hl;
spt_menu_instructionbutton_hl.SetImage(menu_instructionbutton_hl);
spt_menu_instructionbutton_hl.SetPosition(426.f, 324.f);
//menu exit button
sf::Image menu_exitbutton;
if (!menu_exitbutton.LoadFromFile("data/art/menu/menu_exitbutton.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_exitbutton;
spt_menu_exitbutton.SetImage(menu_exitbutton);
spt_menu_exitbutton.SetPosition(12.f, 580.f);
//menu exit button highlighted
sf::Image menu_exitbutton_hl;
if (!menu_exitbutton_hl.LoadFromFile("data/art/menu/menu_exitbutton_hl.bmp"))
{
MessageBox(NULL,
"Fail to load image from file",
"Error",
NULL);
return -1;
} //Load image
sf::Sprite spt_menu_exitbutton_hl;
spt_menu_exitbutton_hl.SetImage(menu_exitbutton_hl);
spt_menu_exitbutton_hl.SetPosition(12.f, 580.f);
return 0;
}
//INPUT
int process_input_menu(void)
{
sf::Event Event;
while (App.GetEvent(Event))
{
// Window closed
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key pressed
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
}
main.cpp
#include "UltrapingMenu.h"
int main()
{
sf::RenderWindow App(sf::VideoMode::GetMode(1), "SFML Window");
App.Create(sf::VideoMode(1024, 768, 32), "Ultraping", sf::Style::Fullscreen); //Windows creation...somehow, (1) works, (0) doesn't
load_graphics_menu();
while (App.IsOpened() && game_state == MENU)
{
process_input_menu();
App.Clear();
App.Draw(spt_menu_background);
App.Draw(spt_menu_playbutton);
App.Draw(spt_menu_instructionbutton);
App.Draw(spt_menu_exitbutton);
App.Display();
}
return 0;
}
and here's the errors
Compiling...
main.cpp
.\main.cpp(17) : error C2065: 'spt_menu_background' : undeclared identifier
.\main.cpp(18) : error C2065: 'spt_menu_playbutton' : undeclared identifier
.\main.cpp(19) : error C2065: 'spt_menu_instructionbutton' : undeclared identifier
.\main.cpp(20) : error C2065: 'spt_menu_exitbutton' : undeclared identifier
it doesn't make any sense since I obviously declared these in my load_graphics_menu section...why do I keep getting this error?
Also, does anyone have any tips on optimizing my code? It's a bit cumbersome right now and I'm not sure how to do some things. for example, if I wanted to draw a seperate image the the mouse is hovering over the play button, how should I do that? I don't want to use pages of if and thens.