{"id":1067,"date":"2011-08-10T09:06:49","date_gmt":"2011-08-10T08:06:49","guid":{"rendered":"http:\/\/sahits.ch\/blog\/?p=1067"},"modified":"2011-08-10T09:06:49","modified_gmt":"2011-08-10T08:06:49","slug":"game-development-in-java","status":"publish","type":"post","link":"http:\/\/sahits.ch\/blog\/blog\/2011\/08\/10\/game-development-in-java\/","title":{"rendered":"Game development in Java"},"content":{"rendered":"<p><a href=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2011\/08\/OpenRailsScreenshot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-thumbnail wp-image-1068\" title=\"OpenRailsScreenshot\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2011\/08\/OpenRailsScreenshot-150x150.png\" alt=\"\" width=\"150\" height=\"150\" \/><\/a>Does this image seem familiar to you? If it does you are right, it is Sid Meier&#8217;s Railroad Tycoon from 1990. Or isn&#8217;t it? In fact it is not. Currently I am trying to recode this game in Java.<br \/>\n<!--more-->After reading Andrew Davisons <a href=\"http:\/\/fivedots.coe.psu.ac.th\/~ad\/jg\/\">Killer Game Programming<\/a> 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.<\/p>\n<p><a href=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2011\/08\/RenderClassDiagram1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-1074\" title=\"RenderClassDiagram\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2011\/08\/RenderClassDiagram1-150x150.png\" alt=\"\" width=\"150\" height=\"150\" \/><\/a>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,&#8230;). 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).\u00a0 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Does this image seem familiar to you? If it does you are right, it is Sid Meier&#8217;s Railroad Tycoon from 1990. Or isn&#8217;t it? In fact it is not. Currently I am trying to recode this game in Java.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[94,301,193,194,195],"class_list":["post-1067","post","type-post","status-publish","format-standard","hentry","category-java","category-programmieren","tag-game","tag-java","tag-openrails","tag-railroad-tycoon","tag-sid-meier"],"_links":{"self":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/1067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/comments?post=1067"}],"version-history":[{"count":4,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/1067\/revisions"}],"predecessor-version":[{"id":1075,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/1067\/revisions\/1075"}],"wp:attachment":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/media?parent=1067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/categories?post=1067"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/tags?post=1067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}