December 31, 2010

Hooray!

I've managed to get a colored square to appear on the screen, then make it change color by left-clicking the mouse.  Sounds pretty boring, doesn't it?

But this means that the following subsystems work:

3D rendering
Input manager
Game event handling
Basic GUI interface system

First the 3D engine and input manager (keyboard presses, mouse clicks, etc.) are loaded.  (Note:  I'm skipping many other subsystems that all come with the Java Monkey Engine [JME]--but these are the important ones).  Then the event manager is loaded and all basic game events are registered with it.  I currently have just one event for testing... :).  Next, the GUI state manager is loaded, which in turn creates the "Main Menu" state and the "Second Menu" states.  Main Menu contains a blue colored square on the screen while Second Menu contains a green square.  The Main Menu registers the action of left clicking the mouse with the input manager, then registers the GUI state manager as a listener for the click event.  The GUI state manager is told how to handle any messages coming into it and knows that the event should signal it to swap out the Main Menu for the Second Menu, thus changing the square from blue to green.

What this means is when the application is started, a black background appears with just a blue square in the lower left.  When the mouse is clicked, the "Main Menu" state sends a message to the input manager saying that a left-click occurred.  The input manager then sends a message to the game event manager, which the event manager then processes and sends to the GUI state manager.  The GUI state manager sees this message and swaps the Main Menu for the Second Menu, thus turning the blue square green.

Phew.  Sounds like a lot, but this loose coupling enables each system (input, events, GUI) to function independently and not worry about referencing and hooking into all the others.  It'll save a lot of time and effort when the game gets big and complex!

No comments:

Post a Comment