Game development in Java

Does this image seem familiar to you? If it does you are right, it is Sid Meier’s Railroad Tycoon from 1990. Or isn’t it? In fact it is not. Currently I am trying to recode this game in Java.
After reading Andrew Davisons Killer Game Programming I feel well enough equipped to realize such a simple 2D game. I finally worked out a setup that combines the OO principle with classic game programming. In games everything is event driven, this may be user events like clicking somewhere or generated events like a clock tick. This basically allows separation of display and game logic through event messaging. The main problem here is that most events do update the visual representation.

The class diagram shows the essential parts. The base is a JFrame with the game render loop implemented as a Runnable and kicked as its own thread (in startGame()). The calcSizes calculates the actual space that can be used for drawing. The actual drawing is done in an off screen image that is swaped in printScreen(). The different test methods handle user related events. gameUpdate() drives the game related events (like clock tick, random events,…). The gameRender puts the off screen image together by calling its children (views). A view represents the whole rendereable space. There may be several views, but only one is active (enabled) at the time (and thusly rendered).  Each view may consist of different parts that represent different controls in the view. Each such part handles its rendering itself and is called from the view.

2 Gedanken zu „Game development in Java“

  1. An interesting observation that I was not aware of is that with this set up all your rendering takes place in the RenderablePart implementing classes. Putting rendering the the Renderable implementation will have no effect. This is probably caused by the effect that BaseView is a subclass of JPanel, which is a swing component that is not added to the frame, so drawing on this level is ignored.
    However if your setup is simple enough so that you only have one view/part you can add the part directly to the frame since RenderablePart is a sub interface of Renderable.
    The renderable code is available under the Apache License 2.0 in the OpenPatrician project in the form of two Maven projects. You can check out the code through svn:
    svn co https://openpatrician.svn.sourceforge.net/svnroot/openpatrician/trunk/GameEvent GameEvent
    svn co https://openpatrician.svn.sourceforge.net/svnroot/openpatrician/trunk/Rendering Rendering

Schreibe einen Kommentar