Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
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  
  A question about structure.  (Read 744 times)
0 Members and 1 Guest are viewing this topic.
Offline Regenuluz
« Posted 2012-01-19 11:32:23 »

So, I've started working on my own little 2d rpg game, but I have a few questions.

Obviously the game will have several different screens. A menu when you start the game, where you can choose a new game, load, exit, that kind of stuff. Some of those choices will lead to other menus etc.

There's also the game screen, after you start a new game/load a game. In this screen there'll be several small menus, like character pane etc.

The way I'm doing it right now is having a Screen interface which all the other screens will be extending, so that I can do something like:

1  
Screen screen = new mainMenu(this); // "this" being a reference to the game itself, so that the screens can call stuff like "game.setScreen(some_new_screen);"


Also for the mouse/keyboard input I'm doing this:

1  
2  
3  
im = new inputManager();
im.delegateInputTo(screen);
this.addKeyListener(im);


This way the menu screens will know if the up/down/whatever-key was pressed and act accordingly.

Is this the "right" way to do it? Also, the screens aren't really the ones to control anything, are they? I mean, they're just graphical things that should get painted.

So where would I have the input to actually move the protagonist around?
Offline aazimon
« Reply #1 - Posted 2012-01-19 19:30:49 »

The answer to this various from person to person.
    (In a rough sort of way), I think it would be best to have the menu item listen for the key event. Then the menu item would trigger other events. This would work for the protagonist (Sprite or Entity). The protagonist object will tell the screen (map) that it has moved. The screen would just draw the elements, the elements would tell the screen where it is.
   Does that make it clearer?
Offline Regenuluz
« Reply #2 - Posted 2012-01-19 21:05:56 »

Hmm, yeah. I think so. I'll give it a swirl and see if it works out. Thanks! Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-01-19 21:31:58 »

It is normal java convention to have all classes start with an upper case letter, so it is best to have MainMenu and InputManager.

What you're doing is a basic State engine. Yes, the "Screen"/"State" controls all logic (ticks/updates) and rendering. The way you have things setup is perfectly fine, in fact it's the way I recommend to everyone Smiley

Offline Regenuluz
« Reply #4 - Posted 2012-01-19 22:44:46 »

Heh, I'll go rename the classes. ^_^

So the screens should handle logic as well as rendering? How about entities, like the protagonist? They aren't really screens but objects. So should I just keep a "list" of them somewhere and have them painted when needed, or? Smiley
Offline ra4king

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-01-19 22:48:24 »

Game is a container of Screens. Screens are containers of Entities. The Screen should manage a list of entities and make them interact but Entities should be a separate "Entity" class Smiley

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.

Grunnt (15 views)
2014-09-23 14:38:19

radar3301 (14 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (75 views)
2014-09-10 13:57:51

TehJavaDev (105 views)
2014-09-10 06:39:09
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!