• Advertisement
Sign in to follow this  

Creating a menu

This topic is 1905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been learning some programming and after a couple of months of C++ and SFML I have been able to create simple games such as pong or an animated man moving around the screen.

I have been trying to implement a game menu to my Pong game, and as I found no tutorials or help, I proceeded myself. My code was:

[source lang="cpp"]
if (!inMenu)
while (inMenu)
//Drawng my menu background

//Getting mouse co-ordinates
float mouseX = Screen.GetInput().GetMouseX();
float mouseY = Screen.GetInput().GetMouseY();

//Check if mouse is on button x-coordinates and clicked
if(mouseX <= 210 &&
mouseX >= 38 &&
//Check if its on Y co-ordinates
if(mouseY <= 470 && mouseY >= 420)
//exit inMenu loop and go to !inMenu one
inMenu = false;
This is just the heart of my menu code. It is inside a while !Quit loop and inside my main function. When I run this the game stays open for about 5 secs, the button doesnt work and then the game crashes. If i take out the menu it works fine, so the rest of the code is OK.

Please, if you are going to say that I need more time with C++, don't. I'm clever enough and I can manage. I just need help to asimilate new concepts. I would like for someone to help me find the problem with this code and if possible to give me a tutorial on game Menus.

P.S: I also have a game of a man moving around the screen and I would like to make enemies and shooting. I have an animation class and a person calss to controll them, but I'm not clear on how to make different enemies or on how to make SHOOTING (most important thing I want to learn) As I said, I'm working from documentation and don't really know how to do this.

*Attached are all of the files for my PONG! game, if anyone would want to take a look.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement