Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  In-game menu for RPG  (Read 1346 times)
0 Members and 1 Guest are viewing this topic.
Offline tacticalPotato37

Senior Newbie





« Posted 2012-07-31 00:25:59 »

I'm trying to implement a standard in-game menu/display for my RPG similar to the one in pokemon, with the option to show player stats, inventory, options etc.
I'm wondering what's the best way to integrate this into my game in terms of game state management?

Right now I'm planning to have a boolean value for each option, like showingStats and showingInventory and a unique class for each menu option, like StatsMenu and InventoryMenu. In my paintComponent method in the main game loop, it will check if a menu is showing and call the proper draw method. I feel like this approach is pretty inflexible, results in a lot of constant checking, and would require a lot of ugly nested code. For example if I have many submenus, I would need to create a separate class and hold a boolean value for each one.

Also the menu is transparent over the game, so it should be in the same JPanel. Can anyone suggest a more streamlined and extensible approach? Thanks
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #1 - Posted 2012-07-31 00:42:05 »

Well, what I did was basically your approach, but then I have subclasses for showing wordwrapped text within some certain boundaries, and they all had their own draw-method.
It takes next to no CPU to check a boolean. Alternatively you could have different states in your menus, represented by a single integer, and have some constants to identify them. That is if you know your don't have too much random stuff going on.

Take a look at what I did for mine. I did a lot of work to get there, but it ended up being very few classes for all that. Each menu (stats-panel, abilities, shop etc.) is a separate class, but all the individual text-boxes are the same three types: One wordwrapped box (each individual conversation-box and the ability-box at the top when fighting), one with the ability to choose from a list (the talk menu panel), and one where you can choose things from a list with the ability to have some things unavailable (the main menu and boxes in battle).

Showcase Video

EDIT: I wrote another guy here a long description of how I set all this up. If you want I can PM that big momma to you

- Jonas
Offline UprightPath
« Reply #2 - Posted 2012-07-31 00:54:44 »

Menus are relatively simple and for the most part relatively stateless, at least as far as these things go.

Your game's state machine would have a 'Menu' state, which would ensure that your Game's State won't change considerably (Use of items, moving of abilities, etc don't constitute a major state change in this case) while you're in a menu. From there, your Menu State would just be composed of different screens which you would display (This more like a flow chart than a true state machine).

In the Menu State all input is forwarded straight to your Menu System instead of being processed by the regular Game State Machine. This is because your Menu System will typically have a completely different event system than the regular game would, mostly corresponding to things like Select Menu Item X, Select next, Select Previous, activate menu item and back.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tacticalPotato37

Senior Newbie





« Reply #3 - Posted 2012-07-31 01:25:08 »

@Ultroman
cool game Smiley, could you please PM me the "big momma" you mentioned? looks like it could be very helpful. Any chance I could take a look at your code?

@UprightPath
I was thinking along those lines. A general Menu class would have a variable like currentScreen and would draw according to that?
Offline UprightPath
« Reply #4 - Posted 2012-07-31 01:35:42 »

Mhm. Or at least mostly.

It really ends up depending on how complicated things are going to be in your system, what sort of input you're accepting and what you library is. If it already has some sort of GUI management system for setting up focus/selected menu items and the like it becomes considerably simpler. Otherwise, you'll need to add in a bit of extra data for tracking the selected menu item and the like.

Also, depending on how complicated your menu system is going to be, you might want to actually define it as some sort of tree that allows you to backtrack through it, perhaps holding onto cursor position information. Think about like in Pokemon. When you cancel using an item that still has some uses (Like if you use one of six PP Ups) you're returned to the item select with PP Up still selected.

Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #5 - Posted 2012-07-31 01:56:21 »

@Ultroman
cool game Smiley, could you please PM me the "big momma" you mentioned? looks like it could be very helpful. Any chance I could take a look at your code?
Thanks Smiley
Well, sure. The classes are written so you can actually just pop them into your game very easily. I'll send them to you with the bits of graphics I did for them. You might want to change them, but if you change the sizes of them, there're a lot of offsets you have to change around. Luckily, if you strip anything about images, you can build your own graphics around the middle, which is just plain drawString on fillRect

- Jonas
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #6 - Posted 2012-07-31 03:01:27 »

Here's how I do it:

Menu class
1  
2  
3  
4  
5  
6  
7  
8  
9  
public class Menu {
   public void tick() {
      //empty
  }
   
   public void render() {
      //empty
  }
}


Example of how to create a new menu class, this one will be called InGameMenu
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public class InGameMenu extends Menu {
   @Override
   public void tick() {
      //update menu stuff, like what is selected and what not
  }
   
   @Override
   public void render() {
      //draw your menu
  }
}


Example of how to render and update the menu
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void tick() {
   //This represents your main updating method, called from your game loop
  if (menu != null)
      menu.tick();
   else
      game.tick();
}

public void render() {
   //This represents your main rendering method
  game.render();
   if (menu != null)
      menu.render();
}


Here's how to create a new Menu
1  
2  
3  
4  
5  
6  
7  
public void tick() {
   if (input.escape.isPressed()) {
      menu = new MainMenu();
   } else if (input.e.isPressed()) {
      menu = new InGameMenu();
   }
}


This way of doing things prevents unnecessary boolean checks and improves overall readability and functionality.

Hope this helps.

 | Nathan

Check out my website!
Offline tacticalPotato37

Senior Newbie





« Reply #7 - Posted 2012-07-31 20:58:09 »

Thanks for the help guys, I got it working for the most part. I have a MenuHandler class that holds a list of all the menus that will be used, and a stack of all the menus that are currently showing on screen (it keeps the order they were opened so when one exits it simply calls pop()). The handler opens and closes menus when the game tells it to, and when a menu is open all input data goes to the menu.

Each menu object extends an abstract Menu class which has information and behavior common to all menus. Every menu must implement a draw() and doSelection() method that each have a switch statement that tells it what to do with the currently selected option. Each menu also has child and parent fields for submenu stuff. It's just fillRect and drawString right now but it works for now Smiley
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #8 - Posted 2012-07-31 21:03:33 »

Cool Smiley

Good luck with it!

- Jonas
Offline UprightPath
« Reply #9 - Posted 2012-08-01 00:37:08 »

Whoot! Yeah, stack makes a lot more sense than a tree (At least, for how you actually store it.) Good job. :3

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (24 views)
2014-04-15 18:08:23

BurntPizza (19 views)
2014-04-15 03:46:01

UprightPath (33 views)
2014-04-14 17:39:50

UprightPath (17 views)
2014-04-14 17:35:47

Porlus (33 views)
2014-04-14 15:48:38

tom_mai78101 (59 views)
2014-04-10 04:04:31

BurntPizza (117 views)
2014-04-08 23:06:04

tom_mai78101 (217 views)
2014-04-05 13:34:39

trollwarrior1 (184 views)
2014-04-04 12:06:45

CJLetsGame (191 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!