Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (612)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
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 905 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:

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:

im = new inputManager();

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: 389
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: 389
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.

Coldstream24 (5 views)
2015-09-03 00:41:28

Andrew_3ds (22 views)
2015-09-01 19:08:10

afikri (15 views)
2015-08-31 09:30:22

afikri (23 views)
2015-08-31 09:30:07

afikri (11 views)
2015-08-31 09:27:24

afikri (15 views)
2015-08-31 09:26:40

Roquen (21 views)
2015-08-29 11:30:54

GamerC4 (33 views)
2015-08-22 20:38:50

GamerC4 (29 views)
2015-08-22 20:37:18

GamerC4 (35 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 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‑
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!