Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: PONG Game Menu Events  (Read 3295 times)

0 Members and 2 Guests are viewing this topic.

Mansiepansie

  • Newbie
  • *
  • Posts: 13
    • View Profile
PONG Game Menu Events
« on: May 14, 2015, 08:26:38 pm »
Hello, i once again struck an issue.. however i dont understand why it does this.

I have 4 Menu options where everyone works except the one ingame.. it triggers after game is paused, i get trough the menu but when i get into the options menu in the ingame screen nothing works and brings me back to the intro screen instead of doing what i'm trying to tell the program to do, go back to the ingame menu or any menu at all, however it still goes back to the Intro screen.

Please help, thanks.

Sorry for tardiness

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: PONG Game Menu Events
« Reply #1 on: May 14, 2015, 08:28:53 pm »
Could you post your code?

Mansiepansie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: PONG Game Menu Events
« Reply #2 on: May 14, 2015, 08:36:53 pm »
// Within Game.cpp

void Game::ShowOptionMenu()
{
   OptionMenu menu;
   while (true)
   {
      _mainWindow.clear(sf::Color::Transparent);

      //Drawing filter game-background + scoreboard (left and right of menutext)
      static sf::RectangleShape filter(sf::Vector2f(SCREEN_WIDTH, SCREEN_HEIGHT));
      filter.setFillColor(sf::Color(40, 40, 40, 70));
      _gameBackground.Draw(_mainWindow);
      _gameObjectManager.DrawAll(_mainWindow);
      _mainWindow.draw(filter);
      _scoreBoard.draw(_mainWindow);

      //Showing menu
      unsigned int result = menu.show(_mainWindow);
      _mainWindow.display();

      //Handling menuEvent
      switch (result)
      {
      case OptionMenu::CHANGE_COLOUR:
         _gameState = Game::Playing;
         return;
      case OptionMenu::BACK_TO_MENU:
         _gameState = Game::Paused;
         return;
      default:
         break;
      }
   }
}

// The header

#pragma once
#include "Menu.h"
#include "SFML/Graphics.hpp"

class OptionMenu : public Menu
{
public:
   enum MenuResult { Nothing, CHANGE_COLOUR, BACK_TO_MENU };
   OptionMenu();
   ~OptionMenu();
private:
   unsigned int handleEvents(sf::RenderWindow &window);    //override

};

// The .cpp File

#include "stdafx.h"
#include "OptionMenu.h"
#include "Game.h"
#include "ServiceLocator.h"

OptionMenu::OptionMenu()
{
   sf::Font font;
   font.loadFromFile("images/FuturaLTBold.ttf");

   MenuItem ChangeColour;
   ChangeColour.action = CHANGE_COLOUR;
   ChangeColour.menuText = "Change Player Paddle";
   ChangeColour.isSelected = true;

   MenuItem backToMainMenus;
   backToMainMenus.action = BACK_TO_MENU;
   backToMainMenus.menuText = "Back to Ingame Menu";
   backToMainMenus.isSelected = false;

   _menuItems.push_back(ChangeColour);
   _menuItems.push_back(backToMainMenus);
}

OptionMenu::~OptionMenu()
{
}

unsigned int OptionMenu::handleEvents(sf::RenderWindow &renderWindow)
{
   sf::Event menuEvent;
   while (renderWindow.pollEvent(menuEvent))
   {
      if (menuEvent.type == sf::Event::KeyPressed)
      {
         switch (menuEvent.key.code)
         {
         case sf::Keyboard::Return:
            return selectedMenuItemResult();
         case sf::Keyboard::Down:
            selectNextMenuItem();
            return Nothing;
         case sf::Keyboard::Up:
            selectPreviousMenuItem();
            return Nothing;
         default:
            return Nothing;
         }
      }
      if (menuEvent.type == sf::Event::Closed)
      {
         renderWindow.close();
      }
   }
   return Nothing;
}

// Within the Game.cpp

void Game::GameLoop()
{

   sf::Event currentEvent;
   switch (_gameState)
   {
   case Game::ShowingMainMenu:
      ShowMainMenu();
      break;
   case Game::ShowingOption:
      ShowOptionz();
      break;
   case Game::Paused:
      ShowInGameMenu();
      break;
   case Game::ShowingOptionMenu:
      ShowOptionMenu();
   case Game::ShowingSplash:
      ShowSplashScreen();
      break;
   case Game::ShowingGameBackground:
      ShowGameBackground();
      break;
   case Game::Playing:
      _mainWindow.clear(sf::Color(0, 0, 0));
      _gameBackground.Draw(_mainWindow);
      _scoreBoard.draw(_mainWindow);
      _gameObjectManager.UpdateAll();
      _gameObjectManager.DrawAll(_mainWindow);
      _mainWindow.display();
   
      while (_mainWindow.pollEvent(currentEvent))
      {
         if (currentEvent.type == sf::Event::Closed)
         {
            _gameState = Game::Exiting;
         }
         if (currentEvent.type == sf::Event::KeyPressed)
         {
            if (currentEvent.key.code == sf::Keyboard::Escape)
            {
               ServiceLocator::GetAudio()->PlaySound("audio/menuEnter.wav");
               _gameState = Paused;
            }
         }
      }
      break;
   default:
      break;

   }
}

// Within Game.h

#include "PlayerPaddle.h"
#include "GameObjectManager.h"
#include "scores.h"
#include "GameBackground.h"

class Game
{

public:
   static void Start();

   const static GameObjectManager& GetGameObjectManager();
   static ScoreBoard& GetScoreBoard();
   static GameBackground& GetGameBackground();
   const static int SCREEN_WIDTH = 1024;
   const static int SCREEN_HEIGHT = 768;
private:
   static bool isExiting();
   static void resetGame();
   static void setupGameObjects();

   static void GameLoop();
   static void ShowGameBackground();
   static void ShowSplashScreen();
   static void ShowMainMenu();
   static void ShowInGameMenu();
   static void ShowOptionMenu();
   static void ShowOptionz();


   enum GameState { Uninitialised, ShowingSplash, ShowingGameBackground, Paused, Exiting, ShowingOption, ShowingOptionMenu, ShowingMainMenu, ShowingInGameMenu, Playing };
   static GameState _gameState;

   static sf::RenderWindow _mainWindow;
   static GameObjectManager _gameObjectManager;
   static ScoreBoard _scoreBoard;
   static GameBackground _gameBackground;

   static bool _multiplayer;
};
« Last Edit: May 14, 2015, 08:42:08 pm by Mansiepansie »

Mansiepansie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: PONG Game Menu Events
« Reply #3 on: May 14, 2015, 08:38:22 pm »
Everything but the
void Game::ShowOptionMenu()

trying to go back to Paused/InGameMenu when i push Back to Ingame Menu
« Last Edit: May 14, 2015, 08:43:47 pm by Mansiepansie »

Mansiepansie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: PONG Game Menu Events
« Reply #4 on: May 14, 2015, 08:44:37 pm »
Im new to programming, usually dont hang around at forums. So tell me if im posting something wrong, i have around 20+ headers, so i might not link everything correct.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: PONG Game Menu Events
« Reply #5 on: May 14, 2015, 08:49:28 pm »
Okay, you might not want to post 20 headers, just the functions where the problem is. Also, code tags are useful to make something readable.

Mansiepansie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: PONG Game Menu Events
« Reply #6 on: May 14, 2015, 09:18:36 pm »
The Code doesn't show any errors, the problem for me seems to be

   
      case OptionMenu::BACK_TO_MENU:
         _gameState = Game::Paused;
         return;
      default:
         break;

Not displaying what was intended, i want it to go back to the ingame menu wich is the Paused screen


shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: PONG Game Menu Events
« Reply #7 on: May 14, 2015, 09:24:39 pm »
try putting cout statements around the program so you can tell if it is that ShowInGameMenu() is being called but isn't working or if it isn't being called. If it is being called, can you post it. Also use code tags, which ware code and /code in square brackets. Also, default: break; is pointless.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: PONG Game Menu Events
« Reply #8 on: May 14, 2015, 09:44:15 pm »
case Game::Paused:
      ShowInGameMenu();
      break;
case Game::ShowingOptionMenu:
      ShowOptionMenu();
case Game::ShowingSplash:
      ShowSplashScreen();
      break;
 

You're missing a break statement after the call to ShowOptionMenu.

Mansiepansie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: PONG Game Menu Events
« Reply #9 on: May 14, 2015, 10:29:03 pm »
Omg geez.. thanks man.. i feel so stupid rofl!!

 

anything