I've been working on yet another side project, which involves a very simple game platform on which I can build upon for some ideas I've had. The architecture is really simple at the moment, and I don't plan on making it much deeper than this:

  • The World contains a set of Actors.
  • Each Actor has an ordered list of Actions.
  • At each World tick, the first Action in each Actor is called; if it returns true, then that Action remains in the list; otherwise, the Action is removed from the list, and the next Action executes.
  • Each Actor can have a Renderer to display it on the screen.
  • For convenience, the rendering uses a Graphics2D instance that has been scaled and translated according to the expected window size.
  • There's also a rendering JComponent, and a work-in-progress input registration and notification system.

The power really seems to come from the world / actor / action rules. I found it trivial to construct different program states. Here's a proof of concept game that I put together. The goal is to prevent the blue squares from entering into the gray square in the middle. You use the mouse as a "repulsor" to repel the blue squares.

I'll explain some of what's going on:

  • The "click to continue" screens are one state. A mouse listener is registered as an action on the "button" actor, that simply removes itself from the action list when it's clicked. Then, the next action in the list is a "start the game over" action.
  • The "start the game" action removes all existing actors from the world, and populates it with the new items. Special care is taken to ignore the bouncing "next level" GUI component (this is done through actor properties).
  • The timer GUI is an actor that has a simple action that counts down. When the countdown action ends, it removes itself from the timer's action list, and the next action executes (start next level).
  • The bouncing "start level" actor has a series of actions: 1. accelerate/decelerate up to the middle of the screen, 2. start up the level, 3. accelerate down to the bottom of the screen AND fade out. This third action is really 2 actions combined inside another delegating action.

Pretty simple stuff, but it allows for a wide range of animation techniques and state management.



Your Option (Login or Post by anonymous)