<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;C0AGQHkzeCp7ImA9WhRUFUU.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435</id><updated>2012-01-26T07:42:01.780-05:00</updated><category term="z-ordering" /><category term="jar file" /><category term="JEditorPane" /><category term="game development process" /><category term="Expression Blend" /><category term="poll" /><category term="updates" /><category term="applet" /><category term="high CPU usage" /><category term="timestep" /><category term="threading" /><category term="Code Completition" /><category term="Rendering" /><category term="bufferedimage" /><category term="Indie" /><category term="Effects" /><category term="Graphics" /><category term="3D engines" /><category term="3D programming" /><category term="Primitives" /><category term="resources" /><category term="Drawing" /><category term="Double Buffering" /><category term="New Design" /><category term="mechanics" /><category term="BufferStrategy" /><category term="SwingUtilities" /><category term="game development concepts" /><category term="prototypes" /><category term="Independent" /><category term="GL_ONE_MINUS_SRC_ALPHA" /><category term="Ogre4j" /><category term="2D Level" /><category term="game reward systems" /><category term="1000 games" /><category term="Images" /><category term="organize imports" /><category term="Silverlight Example" /><category term="Game Creator" /><category term="Design" /><category term="JFrame" /><category term="platformer" /><category term="color filtering" /><category term="Game Development" /><category term="importers" /><category term="Fullscreen" /><category term="game design" /><category term="Frames" /><category term="traffic report" /><category term="Expression" /><category term="java image loading" /><category term="Sound" /><category term="texture mapping" /><category term="GL_BLEND" /><category term="Eclipse" /><category term="Intellisense" /><category term="loading from a jar" /><category term="Tiles" /><category term="Dwarf Fortress" /><category term="character" /><category term="Python" /><category term="exporters" /><category term="Microsoft" /><category term="pyOgre" /><category term="document navigation" /><category term="jogl texture transparency" /><category term="status" /><category term="movement" /><category term="collision" /><category term="Game Engine Design" /><category term="demo" /><category term="Keyboard" /><category term="png" /><category term="XNA" /><category term="Tutorials" /><category term="MOGRE" /><category term="particles" /><category term="Timed Rendering" /><category term="Image Loading" /><category term="Opinion" /><category term="texture binding" /><category term="State Machine" /><category term="Audio" /><category term="SDL" /><category term="Source Browsing" /><category term="Levels" /><category term="Miscellaneous" /><category term="RenderingHints" /><category term="Animations" /><category term="Side Projects" /><category term="sprites" /><category term="acheivements" /><category term="comments" /><category term="Flickering" /><category term="Game Maker" /><category term="math" /><category term="jogl textures" /><category term="Minecraft" /><category term="jump mechanic" /><category term="Dialog" /><category term="gamasutra" /><category term="3D games" /><category term="faster rendering" /><category term="Game Context" /><category term="Centering" /><category term="Canvas" /><category term="Visual Studios" /><category term="Infinite world" /><category term="java rendering performance" /><category term="layering" /><category term="Ruby" /><category term="adsense" /><category term="coffee" /><category term="skeletal animation system" /><category term="DirectX" /><category term="fx" /><category term="Tips and Tricks" /><category term="Silverlight" /><category term="game ideas" /><category term="making games" /><category term="Download" /><category term="Image" /><category term="Image Manager" /><category term="Scrolling" /><category term="thanksgiving" /><category term="Thoughts" /><category term="how to" /><category term="projects" /><category term="Level Editor" /><category term="Display" /><category term="jar" /><category term="troubleshooting" /><category term="test" /><category term="responses" /><category term="Games" /><category term="Map Generation" /><category term="ScreenModes" /><category term="collision detection" /><category term="character movement" /><category term="tile sheets" /><category term="performance" /><category term="neat features" /><category term="jME" /><category term="Ideas" /><category term="game making" /><category term="timing" /><category term="News" /><category term="OpenGL" /><category term="image manipulation" /><category term="advice" /><category term="Game Engine" /><category term="Anti-Aliasing" /><category term="Input" /><category term="Screen" /><category term="models" /><category term="max" /><category term="opengl-es" /><category term="Maps" /><category term="android" /><category term="Games Industry" /><category term="transparency" /><category term="mouse movement" /><category term="Graphics2D" /><category term="game logic" /><category term="HTML" /><category term="Notes" /><category term="Java Monkey Engine" /><category term="game mechanics" /><category term="CSharp" /><category term="screenshot" /><category term="Room Escape Example" /><category term="plugins" /><category term="3d modeler" /><category term="3dsmax" /><category term="Silverlight Games" /><category term="file formats" /><category term="Room Escape" /><category term="2D tile map" /><category term="State" /><category term="XNA content pipeline" /><category term="debugging" /><category term="java images" /><category term="Programming" /><category term="Python Ogre" /><category term="C++" /><category term="Jitter" /><category term="General" /><category term="Blender" /><category term="java transparency" /><category term="Resource Manager" /><category term="jogl" /><category term="first android app" /><category term="auto format" /><category term="jmonkeyengine" /><category term="vector" /><category term="Animation" /><category term="Design Patterns" /><category term="game movement" /><category term="alpha function" /><category term="turkey" /><category term="fbx" /><category term="platform" /><category term=".x" /><category term="personal" /><category term="summoning" /><category term="Music" /><category term="grid indexing" /><category term="multiple layers multi-layers" /><category term="Java" /><category term="Ogre3D" /><category term="Heightmap" /><category term="Snippet" /><category term="AudioClip" /><category term="how to make games" /><category term="texture" /><category term="Tearing" /><category term="Display Modes" /><category term="adsense revenue" /><category term="Perlin Noise" /><category term="Window" /><category term="Game Programming" /><category term="Ogrerb" /><category term="alpha blending" /><category term="Angular movement" /><category term="progress" /><category term="jumping" /><title>Game Programming Snippets</title><subtitle type="html">Place to find helpful snippets of code to use in making your own games.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://gpsnippets.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://gpsnippets.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>68</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/GameProgrammingSnippets" /><feedburner:info uri="gameprogrammingsnippets" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CkQHRX45fip7ImA9WhRVE0U.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-5468809107399141665</id><published>2012-01-12T09:58:00.004-05:00</published><updated>2012-01-12T09:58:54.026-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-12T09:58:54.026-05:00</app:edited><title>The Good and the Bad</title><content type="html">So it's been a stressful week. I just lost my job recently which is bad news for me and good news for you. It means I have all the free time I want to create new posts and work on making games. Though I don't earn any money on this blog or on android so it's hard to say whether it's worth the time to invest in it. But don't worry I plan to devout time to creating posts and making games. So wish me luck, hope I find a job soon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-5468809107399141665?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/u2pODXZ-nDRqKRAOeTMdjO_8zr0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u2pODXZ-nDRqKRAOeTMdjO_8zr0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/u2pODXZ-nDRqKRAOeTMdjO_8zr0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u2pODXZ-nDRqKRAOeTMdjO_8zr0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/e9eyZ24GaHI" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2012/01/good-and-bad.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5468809107399141665?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5468809107399141665?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/e9eyZ24GaHI/good-and-bad.html" title="The Good and the Bad" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2012/01/good-and-bad.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEAGRHw8fyp7ImA9WhRWGEU.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-7263471175692136598</id><published>2012-01-05T08:18:00.004-05:00</published><updated>2012-01-06T16:52:05.277-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-06T16:52:05.277-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="game ideas" /><category scheme="http://www.blogger.com/atom/ns#" term="Game Development" /><category scheme="http://www.blogger.com/atom/ns#" term="game reward systems" /><category scheme="http://www.blogger.com/atom/ns#" term="game mechanics" /><category scheme="http://www.blogger.com/atom/ns#" term="game development process" /><category scheme="http://www.blogger.com/atom/ns#" term="game design" /><title>Game Goals</title><content type="html">&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt;
I've been working on some games of my own lately and I've fallen into the trap of "never-completing" a game. This is a bad position to be in, one that I have struggled with for years and I think it's intrinsic to game designers who want to make really good games. At the end of the day one finished polished product is thousands of times more valuable than having hundreds of unfinished products. Even if those products made it really far it isn't worth anything if it isn't finished.&lt;br /&gt;
&lt;br /&gt;
Now we have to ask ourselves what is a finished game? I have seen a number of quotes that read something like this, "A game is finished when there is nothing left to remove". I want to say I fully understand this, however I am stuck with a mindset where I won't add anything to a game if it isn't going to be a part of the finished product. It seems like games are better suited to be developed by adding lots of features and then just weed out the unfinished or incongruous features polish whats left and then you have a game.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Goal Line&lt;/b&gt;&lt;br /&gt;
I think one of the key things that I am doing wrong is probably a very important one. When I design a game I start from a blank slate which is good it allows pretty much anything that I am feeling or desire to enter into my game world. But then when I think about a game design I think in what seems to be a backwards sort of approach which is design a neat mechanic or think about an existing mechanic and design the game around that. I can tell you now this doesn't work.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The better approach is to come up with the goal(s) or challenge(s) the player has to overcome. This brings into play a major focus element for development and one of the most important aspects of any game.&lt;/b&gt; Whether the player actively asks themselves what goal they are trying to reach or not it's a fundamental aspect of game playing. This isn't saying anything about how to make great or even just good games. This is something I've struggled with when trying to make games.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Common Hinderances&lt;/b&gt;&lt;br /&gt;
I have found that I get too focused on how to reward the player in fun ways whether it be through feedback mechanisms that are very gratifying. Also whether or not a particular feature is frustrating. Both of these focuses are to be left for polish, and are secondary to coming up with a compelling goal or challenge. I believe that those two things the rewards and removing frustrations to be key elements of making "fun" games. Though if you don't have an major overall goal their just neat interaction systems without any real focus for the player and not very compelling.&lt;br /&gt;
&lt;br /&gt;
As an aside an idea for a game is not even remotely close or good enough to make a game because when you go to test your idea most of the time you run into problems which you hadn't anticipated. This becomes easier over time after you've implemented your ideas. And I suppose your games will become tweaked and integrated versions of the mechanics you have experience developing.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Where to go from here?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Start with coming up with a major goal or challenge that the player must overcome and then add the fun bits such as new tools to help complete the challenge or reach the goal. Throwing in unique things to try and keep the player from their goal. Add in the little rewards like picking up items and such. Also a little note about the little things, particle effects or other types of graphical goodies are also rewarding to the player especially if their appealing to the eye. Some satisfaction is gained when a player receives "cool" feedback. Explosions are always a plus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-7263471175692136598?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mMaNFPWGzvtF28yZFETdd0p64IE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mMaNFPWGzvtF28yZFETdd0p64IE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mMaNFPWGzvtF28yZFETdd0p64IE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mMaNFPWGzvtF28yZFETdd0p64IE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/lBand0fX3Xs" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2012/01/game-goals.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/7263471175692136598?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/7263471175692136598?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/lBand0fX3Xs/game-goals.html" title="Game Goals" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2012/01/game-goals.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkQAQ3wycSp7ImA9WhRQGUg.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-5255975705849493246</id><published>2011-12-15T06:58:00.001-05:00</published><updated>2011-12-15T06:59:02.299-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-15T06:59:02.299-05:00</app:edited><title>Combat System Update</title><content type="html">I've got a basic combat system implementation it just needs some cleaning up. I haven't really had much time with the Christmas shopping and work getting in the way. I am planning on getting back to it and finishing it up. &amp;nbsp;Hopefully you'll be able to&amp;nbsp;gleam something useful from it.&lt;br /&gt;
&lt;br /&gt;
I would like to apologize for the lack of updating. I am still dealing with the programmers version of writers block and the feeling of being overwhelmed with ideas. Probably due to not having large time blocks to dedicate to game making.&lt;br /&gt;
&lt;br /&gt;
Happy Holidays everyone!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-5255975705849493246?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BVlebnPwNmJ9qvaStcONWHsSIz0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BVlebnPwNmJ9qvaStcONWHsSIz0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BVlebnPwNmJ9qvaStcONWHsSIz0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BVlebnPwNmJ9qvaStcONWHsSIz0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/2LzXPsXdJl8" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/12/combat-system-update.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5255975705849493246?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5255975705849493246?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/2LzXPsXdJl8/combat-system-update.html" title="Combat System Update" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/12/combat-system-update.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YHSH85fSp7ImA9WhRRGEs.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-4487034247667357215</id><published>2011-12-02T16:28:00.001-05:00</published><updated>2011-12-02T17:32:19.125-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-02T17:32:19.125-05:00</app:edited><title>Days off</title><content type="html">Having a 3 day weekend for me is like Christmas morning. It's a good chance to get coding work done and more snippets on here. Unfortunately the job comes first these days so progress is of course slow which makes any time I can get really precious. Though side-tracking really takes its toll as well. Today was a very good day of sidetracking looking at the &lt;a href="http://www.ludumdare.com/"&gt;Ludum Dare&lt;/a&gt;&amp;nbsp;competition, very cool. Thinking about entering, I otherwise I would just use that weekend for projects. It would be a very good thing for me and force me to finish a project and work out some issues with how quickly I move through projects, content, and polish.&lt;br /&gt;
&lt;br /&gt;
So taking a look at some of the games on there actually provided some fruitful results, plus it is always motivating to me to see other peoples finished projects. I am only just beginning to push myself to complete games and make fun mechanics. So lots to do and look forward to.&lt;br /&gt;
&lt;br /&gt;
So something that might interest you game developers out there, if you already know him he's got some good videos and details into games development. &lt;a href="http://chevyray.com/"&gt;Chevy Ray&lt;/a&gt;&amp;nbsp;the videos I found interesting are &lt;a href="http://vimeo.com/28597695"&gt;here&lt;/a&gt;. One of the things I found most interesting is his use of colliders plus I was&amp;nbsp;genuinely impressed with the attention to detail and how smooth the implementation appeared.&amp;nbsp;Very good job and highly recommend watching the videos and checking out his development progress. It's a good example of making and using tools to save time and energy in content making.&lt;br /&gt;
&lt;br /&gt;
Additionally a couple days ago I happen to take a look at &lt;a href="http://www.cokeandcode.com/index.html"&gt;Coke and Code&lt;/a&gt;&amp;nbsp;the Slick engine was interesting. So check it out I gave it a quick try and it has enough value in it to make some decent games plus the support for webstart and applets made it appealing to me. Still looking for suggestions on the combat system if anyone feels so inclined to share, also interested in anybody's personal projects. &lt;i&gt;Give yourself a little free advertising I'd be willing to put a link up to your project&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Cheers and happy holidays to all.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Links: Added Chevy's site, and Coke and Code to links.&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-4487034247667357215?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/J1y83w9KzW_VLQTlshe8Eu_ny9Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/J1y83w9KzW_VLQTlshe8Eu_ny9Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/J1y83w9KzW_VLQTlshe8Eu_ny9Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/J1y83w9KzW_VLQTlshe8Eu_ny9Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/2uaEGNkxpv0" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/12/days-off.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/4487034247667357215?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/4487034247667357215?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/2uaEGNkxpv0/days-off.html" title="Days off" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/12/days-off.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMHSH49cSp7ImA9WhRRFkg.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-2027490283835505097</id><published>2011-11-29T21:34:00.001-05:00</published><updated>2011-11-30T08:07:19.069-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-30T08:07:19.069-05:00</app:edited><title>Green Algae: Updates &amp; Combat System</title><content type="html">&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-1TwVP_mRgDs/TtYlB7Ols4I/AAAAAAAAANA/6gda6K6yQYc/s1600/greenalgae11-30-2011-2.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="150" src="http://2.bp.blogspot.com/-1TwVP_mRgDs/TtYlB7Ols4I/AAAAAAAAANA/6gda6K6yQYc/s200/greenalgae11-30-2011-2.jpg" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Health bar, obelisk,&lt;br /&gt;
summoning effect and monsters&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style="text-align: justify;"&gt;
Here are some recent screenshots of the Green Algae project. Progress so far is minimal as I was discovering how to use GLES20 for Android. Added a green health bar and summoning of enemies from the obelisks with a basic scaling circle for a summon effect so far. It's rudimentary but at least it is something. I used the same placeholder image for both the enemies and for the player avatar. So the avatar in the image is the one directly below the obelisk or the messed up wooden thing sticking out of the ground. I refined the map generation algorithm a little and put in sandy beach like outlines. Still have way too many trees there.&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Accelerated Image Problem&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
I also fixed an issue with images not being accelerated, the problem being unknown but found when I got incredible choppy and low framerates after putting in the &lt;a href="http://gpsnippets.blogspot.com/2007/08/toggle-fullscreen-mode.html"&gt;fullscreen switch&lt;/a&gt;. You can test if an image is accelerated like this
&lt;/div&gt;
&lt;pre class="brush: java"&gt;GraphicsConfiguration gc = GraphicsEnvironment
 .getLocalGraphicsEnvironment()
 .getDefaultScreenDevice()
 .getDefaultConfiguration();
boolean isAcclerated = 
 image.getCapabilities(gc).isAccelerated();
&lt;/pre&gt;
&lt;div style="text-align: justify;"&gt;
In order to get the images accelerated I simply switched them to being &lt;a href="http://docs.oracle.com/javase/6/docs/api/java/awt/image/VolatileImage.html"&gt;VolatileImage&lt;/a&gt;s which did the trick but then it broke the fullscreen switching so I need to reload them when the switching to fullscreen exclusive mode, or use the fullscreen window and just scale everything to match the size without changing resolution.&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Map Generation Changes&lt;/b&gt;&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-sW7Ss7Ia9Io/TtYlFHVoBBI/AAAAAAAAANI/ww0AjMj4vrs/s1600/greenalgae11-30-2011.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="150" src="http://2.bp.blogspot.com/-sW7Ss7Ia9Io/TtYlFHVoBBI/AAAAAAAAANI/ww0AjMj4vrs/s200/greenalgae11-30-2011.jpg" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Map generation actively changes &lt;br /&gt;as the map is being generated&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style="text-align: justify;"&gt;
Here is another screenshot, its the map generation preview which helped me debug a few oddities with the sand outlining piece and parameters. I have a bunch of primitive looking slide-bars that act as controls for how many islands and how large, long, and how much they vary when built. You can see my attempt at grass here and making it repeat well. Also my first attempt at an actual standing tree to align with the top-down style graphics, it needs work and a leafy version.&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Combat System Snippet Work&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
So, after fiddling a little bit with trying to make the summoned monsters fight back I found that I am indeed in need of a combat system. So I started thinking about the design of it and what I wanted it to be able to handle. I have a few basic classes and interfaces put into a separate project so I can share it with all of you as a snippet. Currently the idea is to use the &lt;a href="http://www.dofactory.com/Patterns/PatternMediator.aspx"&gt;mediator design pattern&lt;/a&gt; having a CombatSystem class as the mediator to handle things like who swung first and what not, handle multiple Combatants (which are the Colleagues in the pattern). Asses damage and timing between attacks it seems like it will be a good way of handling combat and could potentially be used in a lot of different games. So hopefully have that working in a couple of days if I get time to work on it. Or it may have to wait till the weekend, my day job does get busy sometimes.&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;b&gt;Other ideas&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
&lt;i&gt;If anyone would like to share what types of systems they've used in the past for combat, I am sure people would find it very helpful. Thanks for reading, and if you have any suggestions for snippets or need help figuring out something that I may know how to do don't hesitate to ask in a comment.&lt;/i&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-2027490283835505097?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zGqBTbHYEpcZ1V79Jop8Y7bSbhg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zGqBTbHYEpcZ1V79Jop8Y7bSbhg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zGqBTbHYEpcZ1V79Jop8Y7bSbhg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zGqBTbHYEpcZ1V79Jop8Y7bSbhg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/LC3AjafGukM" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/11/green-algae-updates-combat-system.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/2027490283835505097?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/2027490283835505097?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/LC3AjafGukM/green-algae-updates-combat-system.html" title="Green Algae: Updates &amp; Combat System" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-1TwVP_mRgDs/TtYlB7Ols4I/AAAAAAAAANA/6gda6K6yQYc/s72-c/greenalgae11-30-2011-2.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/11/green-algae-updates-combat-system.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AERXc6cSp7ImA9WhRREEg.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-1115232518558656100</id><published>2011-11-22T13:39:00.001-05:00</published><updated>2011-11-23T07:35:04.919-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-23T07:35:04.919-05:00</app:edited><title>A weekend with Android GLES20</title><content type="html">So I spent most of the weekend porting my android game code from GL10 to GLES20 it's quite the endeavor especially if you've never worked with opengl shaders or matrices. Moving away from the matrix stack was about the hardest part. The shaders were easy to get a handle on all except for the texture passing bit since you don't actually bind the texture to a specific sampler it's done indirectly through the use of numbered textures and order of sampler definitions in the fragment shader.&lt;br /&gt;
&lt;br /&gt;
I've worked with shaders before in a similar way with XNA so some of the concepts were familiar to me. The new part for me was getting a basic post-processing bloom shader to work. I got it now but apparently there are some techniques I have to research before I use it efficiently. But about the one thing that opengl offers that Java2D is without is additive blending which is extremely useful for a lot of great effects, of course you can create your own custom composite in Java for doing additive blending though performance might be an issue there.&lt;br /&gt;
&lt;br /&gt;
But some of the things I learned in getting this to work are as follows,&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;One you need to setIdentity before filling in the transforms&lt;/li&gt;
&lt;li&gt;You can use the Matrix.translateM, Matrix.rotateM, and Matrix.scaleM in sequence&lt;/li&gt;
&lt;li&gt;If you want to translate for example from the last position in the matrix you need to multiply the matrix by the new translation matrix (problems with order of operations)&lt;/li&gt;
&lt;li&gt;A problem I am still having is that of textures still appearing mirror or flipped and other such non-sense due to orientation issues.&lt;/li&gt;
&lt;li&gt;Oh and you have to manage your own matrix stack, if you want to change coordinate systems to use local coordinates for a particular object.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
I'll post examples and more details after the holidays.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Aside from that just getting ready for Turkey Day. Hope everyone has a good and thankful Thanksgiving!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-1115232518558656100?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MG_NAIqj4Ml1MgWsizVGPR-OY7w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MG_NAIqj4Ml1MgWsizVGPR-OY7w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MG_NAIqj4Ml1MgWsizVGPR-OY7w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MG_NAIqj4Ml1MgWsizVGPR-OY7w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/pcfuAYNTj5M" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/11/weekend-with-android-gles20.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1115232518558656100?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1115232518558656100?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/pcfuAYNTj5M/weekend-with-android-gles20.html" title="A weekend with Android GLES20" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/11/weekend-with-android-gles20.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEBQ3g6eCp7ImA9WhRSFE4.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-6736208756302038993</id><published>2011-11-16T04:00:00.000-05:00</published><updated>2011-11-16T04:10:52.610-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-16T04:10:52.610-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="projects" /><category scheme="http://www.blogger.com/atom/ns#" term="Games" /><category scheme="http://www.blogger.com/atom/ns#" term="progress" /><category scheme="http://www.blogger.com/atom/ns#" term="Tiles" /><category scheme="http://www.blogger.com/atom/ns#" term="2D tile map" /><title>Green Algae Project</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-qwoKJ7U7XbU/TouuwnIIaDI/AAAAAAAAAMw/4bdbPkqS9mQ/s1600/Image4.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="150" src="http://2.bp.blogspot.com/-qwoKJ7U7XbU/TouuwnIIaDI/AAAAAAAAAMw/4bdbPkqS9mQ/s200/Image4.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
Yeah weird name I know. But it's good to have a non-restrictive name for a project that doesn't really make you think of anything specific. It helps you move in different directions without thinking about the title of the game. Although I have a work-in-progress game title, but I don't know if it will fit the game exactly after I change the game a bit.&lt;/div&gt;
&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
So yes the game! The initial idea was centered around building bridges out to sea. Though one just can't build bridges for the hell of it &lt;i&gt;(or can one, I wonder, hmmm)&lt;/i&gt;&amp;nbsp;Any way it was decided that they cannot but the reason for building the bridges is indeed an odd one to be sure. And the reason would be, of course, sea monster hunting. Yeah well sea monsters are kind of cool. Think giant sun fish, man size and above, that can walk on land and rip your precious bridges and you to shreds.&lt;/div&gt;
&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
You don't just build bridges, oh no, there's more to build like buildings a bunch of them. You can build well you can build yourself a hut to place your rare fish trophies in collect them all and get to the bottom of this nasty fish evil that's plaguing the island inhabitants. Oh yeah did I mention that there are islands yeah lots of them or as many as you like. The random map generation was of course on of the first things I got working. It's not bad, and by not bad I mean I wouldn't release a game with it but if it came down to it. It wouldn't be horrible.&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-QIibqgoKDwI/Touw4wVHLjI/AAAAAAAAAM0/CohzFEZ0ua4/s1600/Image1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-QIibqgoKDwI/Touw4wVHLjI/AAAAAAAAAM0/CohzFEZ0ua4/s320/Image1.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
Currently only three types of tiles, you get sand, and um water, and of course grass. The terrain generation is random and controlled by a few parameters at the moment island count, size, length, and a extra variance value I used to vary some of the random chances and things. I will make an additional post about the generation method later so you can see one way of doing it.&lt;/div&gt;
&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
So the project I figured is for my own personal enjoyment so it's more like a test bed I can work with to implement gameplay mechanics and test out effects and other things. So in order to get working on the combat system I thought I'd add in the ability to summon monsters. You place a wooden obelisk yeah weird but anyway this is of course after chopping down the tree and dragging the fallen log to where you want it. Then you start summon after a little while monsters will appear for you to fight. And right now it's pretty much you just go up to them attack them then they die, you get experience which you can't see atm, that's easily shown take me like 5 minutes.&lt;/div&gt;
&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;
So yeah that's The Green Algae project. A nice test project that could potentially have some interesting gameplay. Those green things are trees by the way. And that would be a boring old wood pile and a test avatar sprite placing wood in the pile.&lt;/div&gt;
&lt;br /&gt;
So hang on to the edge of your seats for some spectacular updates.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-6736208756302038993?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-Oi5tbzJK7f4L6FF-NpGgHJA1Jc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Oi5tbzJK7f4L6FF-NpGgHJA1Jc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-Oi5tbzJK7f4L6FF-NpGgHJA1Jc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Oi5tbzJK7f4L6FF-NpGgHJA1Jc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/oUIyJqKFqiI" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/11/green-algae-project.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6736208756302038993?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6736208756302038993?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/oUIyJqKFqiI/green-algae-project.html" title="Green Algae Project" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-qwoKJ7U7XbU/TouuwnIIaDI/AAAAAAAAAMw/4bdbPkqS9mQ/s72-c/Image4.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/11/green-algae-project.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QAQHc9fSp7ImA9WhRSFE0.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-5186845504160211606</id><published>2011-11-02T07:22:00.001-04:00</published><updated>2011-11-15T20:02:21.965-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-15T20:02:21.965-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="movement" /><category scheme="http://www.blogger.com/atom/ns#" term="mouse movement" /><category scheme="http://www.blogger.com/atom/ns#" term="character movement" /><category scheme="http://www.blogger.com/atom/ns#" term="game movement" /><title>Mouse Movement by Dragging</title><content type="html">So I forgot to post this one type of movement piece. It's pretty simple if you know how to do the math which I will show you. Like the other snippets it's not entirely polished so there is definitely improvements that can be made to the movement style. This snippet will do a simple move towards the cursor when the mouse is dragged.&lt;br /&gt;
&lt;br /&gt;
Other ways to do mouse movement is point-and-click movement. Point-and-click movement usually works along side a good pathfinding algorithm using either tiles or nodes. So here's the meat of this snippet.
&lt;br /&gt;
&lt;pre class="brush: java"&gt;  // only move if the user is dragging the mouse and we aren't already
  // at the mouse position
  if (dragging &amp;amp;&amp;amp; !isMouseOverBlock()) {
   // the amount to move the character in x and y directions
   double dx = 0.0d;
   double dy = 0.0d;

   // relative mouse position from the character
   double relativeMouseX = mouseX - basicBlock.x;
   double relativeMouseY = mouseY - basicBlock.y;

   // determine the angle the mouse is from the current position
   double angle = Math.atan2(relativeMouseY, relativeMouseX);

   // now determine based on the angle what direction to move in
   dx = Math.cos(angle);
   dy = Math.sin(angle);

   /*
    * move the block by multiplying the amount of time in seconds that
    * has passed since the last update by the speed constant and by the
    * change in x or y directions which will either will result in += 0
    * or dt * speed negative or positive.
    */
   basicBlock.x += dt * speed * dx;
   basicBlock.y += dt * speed * dy;   
  }&lt;/pre&gt;
So one of the tricks here is knowing how to use the &lt;b&gt;atan2 &lt;/b&gt;method. It gives you the angle for the Cartesian points x,y passed to the function using the &lt;b&gt;arctan &lt;/b&gt;trig function. Once we have the angle it's a simple matter to move in that direction based on speed and time. You can think of the &lt;b&gt;dx &lt;/b&gt;and &lt;b&gt;dy &lt;/b&gt;as percentages of the speed to apply and the dt as the amount of time applied.&lt;br /&gt;
&lt;br /&gt;
Some ehancements that could be made to this snippet are things like using acceleration instead of pure speed. You could use this snippet to experiment with different styles of mouse movement such as the point and click and other variations as per your gameplay.
&lt;br /&gt;
&lt;br /&gt;
There is also a little bug I noticed in this example, sometimes when moving the block if it is over the mouse cursor it will sometimes jump quickly back and forth around the cursor. I tried to fix it by using the isMouseOverBlock but it wasn't 100% successful. If you figure it out please let me know.
&lt;br /&gt;
Here's the full snippet:
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://sites.google.com/site/morbidmorvick/MouseDragMovement.java?attredirects=0&amp;amp;d=1"&gt;MouseDragMovement.java&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-5186845504160211606?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ueUOHF-H-JJVE1CmGvpR49PBiow/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ueUOHF-H-JJVE1CmGvpR49PBiow/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ueUOHF-H-JJVE1CmGvpR49PBiow/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ueUOHF-H-JJVE1CmGvpR49PBiow/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/r6IUYidFkps" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/11/mouse-movement-by-dragging.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5186845504160211606?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5186845504160211606?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/r6IUYidFkps/mouse-movement-by-dragging.html" title="Mouse Movement by Dragging" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/11/mouse-movement-by-dragging.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUCSHo5cCp7ImA9WhdaF0s.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-1511163489733956112</id><published>2011-10-27T20:04:00.001-04:00</published><updated>2011-10-27T20:04:29.428-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-27T20:04:29.428-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="projects" /><category scheme="http://www.blogger.com/atom/ns#" term="progress" /><category scheme="http://www.blogger.com/atom/ns#" term="summoning" /><category scheme="http://www.blogger.com/atom/ns#" term="Game Development" /><category scheme="http://www.blogger.com/atom/ns#" term="game mechanics" /><title>Busy busy</title><content type="html">&lt;div&gt;&lt;p&gt;It's been an extremely busy work... month for me. It sucks too since I have wanted to work on a game I've been building in Java. I promise to bring you up to speed soon with development progress and screenshots. And I hope to provide some insight into the process and code that you might find interesting.&lt;/p&gt;
&lt;p&gt;Monster summoning&lt;br&gt;
So I haven't had the time to create any new snippets for your game development needs. But to give you a glimpse into the mechanic I want to implement. It's a summoning circle, the requirements are going to be that you are near a summoning pillar or I guess an obelisk would be a more fitting name for the object. &lt;/p&gt;
&lt;p&gt;So you can build one out of wood for now and place it where you want. Depending on where you place it and your summoning skill different quantities and kinds of enemies will be drawn toward it. &lt;/p&gt;
&lt;p&gt;It's basically developed out of a necessity to develop and test a combat system for the game including the experience and rewards of combat. It opens up a whole range of interesting dynamics to the gameplay. For instance I could have the summoned monsters drop rare items our give the player unique skills he can use elsewhere in the game. Or eventually recruit the summoned monsters instead of just fighting them.&lt;/p&gt;
&lt;p&gt;These would be just some of the ideas I have been toying with when I get a few precious moments to think.&lt;/p&gt;
&lt;p&gt;Also I was thinking of having etchings on the obelisks each etching could provide a way of controlling what happens when you summon around that obelisk. So just thought I would throw in this little update to let you know I am still around and working on games.&lt;/p&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-1511163489733956112?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Xy4lSD-QzDaYTgTllSW0h0Rf6fQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Xy4lSD-QzDaYTgTllSW0h0Rf6fQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Xy4lSD-QzDaYTgTllSW0h0Rf6fQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Xy4lSD-QzDaYTgTllSW0h0Rf6fQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/mA4xz8qpaLU" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/10/busy-busy.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1511163489733956112?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1511163489733956112?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/mA4xz8qpaLU/busy-busy.html" title="Busy busy" /><author><name>Nick</name><uri>http://www.blogger.com/profile/00969811931456041499</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/10/busy-busy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUFQnw9fCp7ImA9WhdWE00.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-5417597749444300391</id><published>2011-09-06T06:00:00.001-04:00</published><updated>2011-09-06T06:00:13.264-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-06T06:00:13.264-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ideas" /><category scheme="http://www.blogger.com/atom/ns#" term="Notes" /><category scheme="http://www.blogger.com/atom/ns#" term="game design" /><category scheme="http://www.blogger.com/atom/ns#" term="Design" /><title>Game Rhythm</title><content type="html">&lt;div&gt;Every game has a rhythm to it, whether it's noticed or not. The intensity builds up and things become more difficult. This can just happen naturally if the game copies current trends in games or common game design and level design principles. But there is a reason for it and that is creating rhythm and if you pay attention to the rhythm of a game you can create a greater and more intense play experience.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;I need a break&lt;/b&gt;&lt;br /&gt;
Breaks are an important part of creating rhythm. One tends to focus on the fun parts those with more action intense aspects. But properly timing the breaks between intensity helps keep immersion. Leveling systems for example naturally create the opportunity for a break in action. After an intense point in a level there is usually a lull and it's a good place to save progress. Progress saving provides a weak reward and a marker for achievement in the players mind. It also is a weak goal for the player, "make it to the next checkpoint". I say a weak goal because it really has no intrinsic meaning to it. And doesn't always tie into the theme very well, and its a big risk for breaking the immersion unless it somehow helps define the game world in a unique way.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Failing&lt;/b&gt;&lt;br /&gt;
I find when I loose a level or fail to reach a checkpoint and have to start over I don't feel rewarded but punished and quickly forget about the events of the failure. The game usually does too not counting how many times I tried nor does it gauge my skill level based on attempts or alter difficulty.&lt;br /&gt;
The question for the designer is how to keep the player interested and coming back after a failure. Nine and three quarters times out of ten I will stop playing a game when I fail to reach a checkpoint a certain number of times dependent on how long it took and whether or not I am willing to put in as much time to try again or based on if I think I can beat it the next time I try.&lt;br /&gt;
&lt;br /&gt;
So for a designer you have to make sure your checkpoints are reasonable if you are using such a system. Or you can try something different. Like tracking the number of failures and making it easier next time the player tries. This will help push them through parts their having trouble with. That might actually make the game less challenging however so you'd have to be careful. It'd be nice to see games try things like this but only if the game keeps trying to challenge me instead of just sticking difficulty on low because I am having trouble and leaving it there. &lt;br /&gt;
&lt;br /&gt;
If your looking to design an action game focusing on creating an intense experience of combat then rhythm is important. You want to steadily but subtly increase the combat intensity. You don't just want a steady continuous steam of baddies bombarding the player. This will just lead to boredom because nothing changes so there is nothing new for the player to grok.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Enough &lt;/b&gt;&lt;b&gt;is &lt;/b&gt;&lt;b&gt;enough&lt;/b&gt;&lt;br /&gt;
While you want to control the intensity of the game part of creating a rhythm is the lulls, yes lulls not lols. after the culmination of build up you want to provide a sort of safe point and give the player reward. this can all be seen and came about in designs naturally. Now it seems like games do this more out of tradition than good design, in a level you fight continuously harder baddies until the end of the level where there is usually a boss, the gameplay is usually changed in boss fights creating almost a separate unique experience depending on implementation. Then comes the satisfaction of once again not anticipating dying, this is the lull.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Beat &lt;/b&gt;&lt;b&gt;the &lt;/b&gt;&lt;b&gt;game&lt;/b&gt;&lt;br /&gt;
The game is over when the player says it's game is over. The player doesn't have to and won't continue playing if there is no enjoyment left.&amp;nbsp; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-5417597749444300391?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OhpjgnekQe6bZ-nVHdlrhFkJUns/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OhpjgnekQe6bZ-nVHdlrhFkJUns/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OhpjgnekQe6bZ-nVHdlrhFkJUns/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OhpjgnekQe6bZ-nVHdlrhFkJUns/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/4cJ-Slw_uUI" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/08/game-rhythm.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5417597749444300391?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/5417597749444300391?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/4cJ-Slw_uUI/game-rhythm.html" title="Game Rhythm" /><author><name>Nick</name><uri>http://www.blogger.com/profile/00969811931456041499</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/08/game-rhythm.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMERHY5fip7ImA9WhdXFkQ.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-4646532311809945196</id><published>2011-08-30T06:00:00.003-04:00</published><updated>2011-08-30T06:00:05.826-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-30T06:00:05.826-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="game design" /><category scheme="http://www.blogger.com/atom/ns#" term="advice" /><category scheme="http://www.blogger.com/atom/ns#" term="game logic" /><title>Focus on Game Logic</title><content type="html">&lt;b&gt;The focus is what gives the game programmer his power.&lt;/b&gt;&lt;br /&gt;
It took me years to get to the point where I finally realized that most 2D games have a very simple set of code necessary from the graphics and collision ends. All you need is the ability to draw images and detect collisions, and maybe play sounds (qed eh), the rest is all game logic. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;It binds the games together&lt;/b&gt;&lt;br /&gt;
The game logic is the truly unique and interesting pieces of code, had I known this long ago or listened to people when they told me to focus on making a game and not just the graphics and structural code, I would have had so much more experience programming game logic. Alas, it is what it is and I need to churn out game logic code like there's no tomorrow in order to catch-up on missed opportunities. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Use the focus Luke, let go your graphics!&lt;/b&gt;&lt;br /&gt;
So a word to the wise, frequently implement as many different types of game logic code as possible. This will help familiarize you with the implementation problems and challenges and help you flush out ideas much more quickly in the future. Believe me when I say I've spent enough time coding to realize the first time is always the hardest when implementing something you've never done. Each time afterwards becomes much easier, so much so that eventually you can implement it as fast you are able to type.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Not this crude matter!&lt;/b&gt;&lt;br /&gt;
By game logic, I am referring to things like scoring, inventory, turn based battles, tech trees, quest systems and puzzles etc... Also get into level design early, the hardcore performance heavy and resource intensive code doesn't matter as much as being a good content creator. Sadly these are things I never really got to implement, I was too busy focused on the structural OO design and making a complete engine package or more and more advanced graphics and 3D work. Recently I've been trying to undo years of focusing on the wrong thing. I was in the whole boat of the having a million small projects but none ever got finished.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;You're my only hope&lt;/b&gt;&lt;br /&gt;
As many people will tell you one finished polished game is better than thousands of unfinished ones. This is due to the myriad things needed to polish off a game. Down to minute details that you don't anticipate like crouching and reloading at the same time. Things like balancing and making sure the game is fun and the shotgun isn't too powerful or too weak, the bfg is hard enough to get and you don't get it till later. All those things add up and sometimes are so specific to your game design that you would never think about it until you've implemented game X at least once.&lt;br /&gt;
&lt;br /&gt;
Good Luck! &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;P.S. I'd love to hear of others experiences and advice when implementing game logic. And some good coding exercises to help refine your skills to make game making easier!&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-4646532311809945196?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qP-v2nTiQqUqmei8u2_7JAtXQW4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qP-v2nTiQqUqmei8u2_7JAtXQW4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qP-v2nTiQqUqmei8u2_7JAtXQW4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qP-v2nTiQqUqmei8u2_7JAtXQW4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/CifVFh57RlY" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/08/focus-on-game-logic.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/4646532311809945196?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/4646532311809945196?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/CifVFh57RlY/focus-on-game-logic.html" title="Focus on Game Logic" /><author><name>Nick</name><uri>http://www.blogger.com/profile/00969811931456041499</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/08/focus-on-game-logic.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8EQXg6eSp7ImA9WhdQFks.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-2730826752403011330</id><published>2011-08-18T08:00:00.001-04:00</published><updated>2011-08-18T08:00:00.611-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-18T08:00:00.611-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mechanics" /><category scheme="http://www.blogger.com/atom/ns#" term="prototypes" /><category scheme="http://www.blogger.com/atom/ns#" term="game mechanics" /><title>Deceptively Simple Prototypes</title><content type="html">I decided to work on some very simple types of snippets related to game mechanics. Small little almost but not quite games! Definitely not polished.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ln4n6iZCwCU/TkultLJsV9I/AAAAAAAAAL4/zU07cfZe4lk/s1600/hit-me-screen01.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="151" src="http://2.bp.blogspot.com/-ln4n6iZCwCU/TkultLJsV9I/AAAAAAAAAL4/zU07cfZe4lk/s200/hit-me-screen01.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;This one I came up with is insanely simple. It's only purpose is just to focus on a process for prototyping different game mechanics. This isn't really a mechanic you would directly use as-is in a game. The core mechanic here being "click" the moving re-sizing circle as close to the center as possible to get maximum points.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Evolution&lt;/b&gt;&lt;br /&gt;
I tend to like exercises to come up with ways to change a currently working game or in this case snippet to turn it into something else. To sort of evolve it into it's own thing. There are a number of things I could add or change to enhance this and eventually make it into a game. It would be a casual arcade style game. I am not sure how well this idea of taking a simple mechanic and expanding on the gameplay works to create a fully polished game, but in my opinion it's better than just trying to brainstorm and come up with a game even if you're a designer and are good at visualizing the end product.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Prototypes&lt;/b&gt;&lt;br /&gt;
From my perspective it's definitely worth it. The experience of coding any gameplay mechanics no matter how small is useful. It forces you to turn the ideas in your head into something tangible and to work out coding issues you WILL have later on in development. Almost every game development team I have been on has always focused on the graphics and architecture first. The successful teams either use an existing engine or separate the graphics and architectural code from the game logic such that they are independent.&lt;br /&gt;
&lt;br /&gt;
Your real drive is to get to the good stuff, the fun aspects of game making, the actual design. Coming up with battle systems, interesting weapons, big explosions, and detailed adventure areas, using all your creative juices. I have been tap-dancing around writing any game logic code for years. But I have always found small simple examples to be the best way to explore new areas in coding. So I am pushing myself to create as many small examples of different types of mechanics as possible. And I will of course post them here.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Snippet&lt;/b&gt;&lt;br /&gt;
This snippet wasn't hard to get setup and rendering, one of the reasons I enjoy using Java for game development. It's basically create a window and a thread that continuously renders to the screen capture input via mouse position and do stuff when the buttons released. &lt;br /&gt;
&lt;br /&gt;
Here's the 200+ line snippet. &lt;br /&gt;
&lt;pre class="brush: java"&gt;import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class SimpleGame extends JComponent {

    public static class ScoreEffect {

        private static final double MAX_TIME  = 300;

        private final long          starttime = System.currentTimeMillis();

        private final int           score;

        private final int           x;

        private final int           y;

        protected ScoreEffect(int score, int x, int y) {
            this.score = score;
            this.x = x;
            this.y = y;
        }

        public void draw(Graphics2D init) {
            Graphics2D g = (Graphics2D) init.create();
            long cur = System.currentTimeMillis();
            double scale = ((cur - starttime) / MAX_TIME) + 1;
            g.translate(x, y);
            g.scale(1.5 * scale, 1.5 * scale);
            g.drawString(String.format("+%d", score), 0, 0);
            g.dispose();
        }

        public boolean isMax() {
            return System.currentTimeMillis() - starttime &amp;gt; MAX_TIME;
        }

        public static ScoreEffect valueOf(int score, int x, int y) {
            return new ScoreEffect(score, x, y);
        }
    }

    private static final int       MAX_HIT_COUNT = 20;
    private double                 direction     = 1;
    private double                 x             = 0;
    private double                 y             = 0;

    private double                 rsize;
    private int                    mouseX        = 0;
    private int                    mouseY        = 0;

    protected int                  score;

    private int                    hitCount      = MAX_HIT_COUNT;

    private boolean                isGameOn;

    private final Set&amp;lt;ScoreEffect&amp;gt; scores;

    public SimpleGame() {
        this.setPreferredSize(new Dimension(300, 200));
        this.setDoubleBuffered(true);

        scores = new HashSet&amp;lt;ScoreEffect&amp;gt;();

        (new Thread() {
            Object lock = new Object();

            @Override
            public void run() {
                synchronized (lock) {
                    while(true) {
                        repaint();

                        checkLooseCondition();

                        try {
                            lock.wait(10);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            }
        }).start();

        Dimension size = getPreferredSize();
        if(x == 0) {
            x = size.width / 2;
        }

        if(y == 0) {
            y = size.height / 2;
        }

        addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                mouseX = e.getX();
                mouseY = e.getY();
            }
        });

        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if(!isGameOn) {
                    isGameOn = true;
                } else {
                    double distance = Math.pow(mouseX - (x + rsize / 2), 2)
                            + Math.pow(mouseY - (y - rsize / 2), 2);
                    if(distance &amp;lt;= 400) {
                        int addPoints = (int) (10 * (distance / 400.0d)) + 1;
                        scores.add(ScoreEffect.valueOf(addPoints,
                                e.getX(),
                                e.getY()));
                        score += addPoints;
                        x = 0;
                        direction = 1;
                    }
                }
            }
        });
    }

    protected void checkLooseCondition() {
        if(hitCount &amp;lt;= 0) {
            isGameOn = false;
        }
    }

    @Override
    public void paintComponent(Graphics init) {
        Graphics2D g = (Graphics2D) init.create();

        if(isGameOn) {
            rsize = Math.abs(getWidth() / 2 - x);

            rsize /= getWidth() / 2;

            rsize = 1 - rsize;

            rsize *= 20;

            if(x &amp;lt;= 0) {
                direction = 1;
            }

            if(x &amp;gt;= getWidth() - rsize) {
                --hitCount;
                direction = -1;
            }

            x += direction * 2;
            g.setColor(Color.black);
            g.drawOval((int) x, (int) (y - rsize / 2), (int) rsize, (int) rsize);

            g.drawString(String.format("Score: %d", score), 10, 25);
            String hits = String.format("Hits Left: %d/%d",
                    hitCount,
                    MAX_HIT_COUNT);
            g.drawString(hits, getWidth() - 10
                    - g.getFontMetrics().stringWidth(hits), 25);

            Set&amp;lt;ScoreEffect&amp;gt; remove = new HashSet&amp;lt;ScoreEffect&amp;gt;();
            for(ScoreEffect e : scores) {
                e.draw(g);
                if(e.isMax()) {
                    remove.add(e);
                }
            }

            scores.removeAll(remove);
        } else {
            String gameon = "Game Over - click to restart!";
            g.drawString(gameon, getWidth() / 2
                    - g.getFontMetrics().stringWidth(gameon) / 2, getHeight()
                    / 2 - g.getFontMetrics().getDescent());

            String lastScore = String.format("Last Score: %d", score);
            g.drawString(lastScore,
                    getWidth() / 2 - g.getFontMetrics().stringWidth(lastScore)
                            / 2,
                    getHeight() / 2 - g.getFontMetrics().getDescent() + 30);

        }
        g.dispose();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                JFrame frame = new JFrame("Hit Me");
                SimpleGame g = new SimpleGame();
                frame.add(g);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-2730826752403011330?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gZcstiKUdJpnQ9dH_qmrRCYgunc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gZcstiKUdJpnQ9dH_qmrRCYgunc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gZcstiKUdJpnQ9dH_qmrRCYgunc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gZcstiKUdJpnQ9dH_qmrRCYgunc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/XiPh5USmwrg" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/08/deceptively-simple-prototypes.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/2730826752403011330?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/2730826752403011330?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/XiPh5USmwrg/deceptively-simple-prototypes.html" title="Deceptively Simple Prototypes" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-ln4n6iZCwCU/TkultLJsV9I/AAAAAAAAAL4/zU07cfZe4lk/s72-c/hit-me-screen01.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/08/deceptively-simple-prototypes.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMGQXs_eSp7ImA9WhdRGUo.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-1832536785185689319</id><published>2011-08-10T07:07:00.004-04:00</published><updated>2011-08-10T07:07:00.541-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-10T07:07:00.541-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="mechanics" /><category scheme="http://www.blogger.com/atom/ns#" term="progress" /><category scheme="http://www.blogger.com/atom/ns#" term="platform" /><category scheme="http://www.blogger.com/atom/ns#" term="game mechanics" /><category scheme="http://www.blogger.com/atom/ns#" term="jumping" /><category scheme="http://www.blogger.com/atom/ns#" term="jump mechanic" /><category scheme="http://www.blogger.com/atom/ns#" term="updates" /><category scheme="http://www.blogger.com/atom/ns#" term="platformer" /><title>Current snippets update</title><content type="html">Still working on getting some useful mechanics snippets out. I want to focus on posting snippets that are the most helpful and insightful into some of the problems in coding game mechanics and game logic. I am working on the jump mechanic and others for platformers. What I am finding more and more is that most platformers have very specific code for handling their basic mechanics, since this is the first time I've actually attempted to write platformer movement code it's taking a while to get right. So today I will am posting my current progress it works in the sense that you can add platforms and jump from platform to platform but there are a number of subtle issues that you wouldn't want in the end.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;To Fall or not to Fall&lt;/b&gt;&lt;br /&gt;
All I really wanted to show was a jump mechanic then I decided to add gravity since it is needed in order to do jumping, and then I figured we need platform collisions to stop the player and provide a base for jumping. The problem I am facing as of this writing is that of gravity as a constant acceleration in a direction (at this point it's mainly in the positive y direction or down but it's not hard and set in code) I am thinking I am trying to do too much at once perhaps it's better to do some daily progress. I don't expect the progress to be that great as it is I don't have much time to spend on doing these snippets and often second guess posting some times to hold out for a better idea or a more critiqued snippet and post.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Why I never tried coding a platformer before?&lt;/b&gt;&lt;br /&gt;
I've been programming games for a long time now 10+ years and while I did originally start a project similar to a platformer at that time I did not know the necessary physics to code the movement. The main reason though is that I've never been that much of a platformer player or enthusiast. I traditionally like strategy games and action-adventure's and as a game designer am enthralled with the design of arcade and puzzle games mainly due to a history of diverse and interesting mechanics and design.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Small Simple Prototypes&lt;/b&gt;&lt;br /&gt;
As a game programmer I often find it very helpful to iron out small simple snippets to test drive certain game code such as creating a specific effect or as previous posts suggest, framework code (e.g &lt;a href="http://gpsnippets.blogspot.com/2008/07/resource-manager-snippet.html"&gt;Resource Manager&lt;/a&gt;, &lt;a href="http://gpsnippets.blogspot.com/2007/06/game-state-machine.html"&gt;Game State Machine&lt;/a&gt;, and things like &lt;a href="http://gpsnippets.blogspot.com/2007/07/timed-animation.html"&gt;Timed Animation&lt;/a&gt; etc.). I am confident in my knowledge base for graphics and API code plus the core framework coding to move on to the more important code which is the actual interactive elements of game code. I think small self contained example code lends itself well to solving buggy mechanics or smoothing out small issues. It helps you experiment with an idea and I believe it allows you to evolve mechanics easily. At the very least it is the exercise of taking your ideas for a specific piece of code in a game and presenting you with actual syntactical and logic problems.&lt;br /&gt;
&lt;br /&gt;
Once you've mastered the basic logic structure of something like, "obtaining gold coins to use in a store to buy better weapons to kill more enemies to get more gold". You can most likely implement it much better in the future. If you've never coded something before you can't predict how long it will take to get right, but once you have that and similar codes become easier and easier.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Progress&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="https://sites.google.com/site/morbidmorvick/JumpPlatforms.java?attredirects=0&amp;amp;d=1"&gt;JumpPlatforms.java&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-1832536785185689319?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/JcjqbPTUsARjrQvULdbP3xmfirY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JcjqbPTUsARjrQvULdbP3xmfirY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/JcjqbPTUsARjrQvULdbP3xmfirY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/JcjqbPTUsARjrQvULdbP3xmfirY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/aUVhPivbfnc" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/08/current-snippets-update.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1832536785185689319?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1832536785185689319?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/aUVhPivbfnc/current-snippets-update.html" title="Current snippets update" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/08/current-snippets-update.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMDQ3w7eCp7ImA9WhdRF0Q.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-1187991505984255027</id><published>2011-08-08T05:07:00.000-04:00</published><updated>2011-08-08T05:07:52.200-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-08T05:07:52.200-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="movement" /><category scheme="http://www.blogger.com/atom/ns#" term="timing" /><category scheme="http://www.blogger.com/atom/ns#" term="timestep" /><category scheme="http://www.blogger.com/atom/ns#" term="Animation" /><category scheme="http://www.blogger.com/atom/ns#" term="Jitter" /><category scheme="http://www.blogger.com/atom/ns#" term="threading" /><title>Enhancement: Smoother Movement</title><content type="html">A while ago I found an article while searching for reasons why some of my movement code was a bit choppy and had some jitter problems. I found this article&amp;nbsp;&lt;a href="http://gafferongames.com/game-physics/fix-your-timestep/"&gt;Fix Your Timestep!&lt;/a&gt;&amp;nbsp;it's a bit abrupt but it has helped.&amp;nbsp;While I wasn't able to completely fix the propagation errors since I haven't mastered the interpolation concept completely or how exactly to work it into my designs.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Concept&lt;/b&gt;&lt;br /&gt;
Make sure that your game updates only in discrete blocks as to not cause erroneous errors in movement and to account for time missed or wait until time has accumulated.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The interpolation&lt;/b&gt;&lt;br /&gt;
Used to compensate for formula errors in translational movement which add up overtime eventually causing objects to be positioned unrealistically. Though I haven't figured out how different it makes things using interpolation versus without it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt;
I took the &lt;a href="http://gpsnippets.blogspot.com/2010/10/character-8-directional-movement.html"&gt;Character 8 directional-movement&lt;/a&gt; snippet and changed the updating thread code, check it out, not perfect but much better than it was before works pretty well at least on my PC.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: java"&gt;// our main task for handling the rendering and for updating and
  // handling input and movement events.
  renderTask = new Thread() {
   // no local variables in a constant loop.
   long lasttime = -1;
   long msDelta  = 0;
   double dt   = 0.01;
   long time;
   double deltaTime = 0;
   double accumulator = 0;

   @Override
   public void run() {
    final Object sync = new Object();
    while (true) {
     synchronized (sync) {
      // use nano time, for more accuracy
      time = System.nanoTime();

      // record the initial last time
      if (lasttime == -1) {
       lasttime = time;
      }

      // delta in milliseconds
      msDelta = (long) ((time - lasttime) * 0.000001d);
      
      // delta in seconds
      deltaTime = (time - lasttime) * 0.000000001d;

      // cap the number of update loops needed to keep up with
      // high frame-rates.
      if (deltaTime &amp;gt; 0.25) {
       deltaTime = 0.25;
      }

      lasttime = time;

      accumulator += deltaTime;

      // accurate update rates, loop for each fixed 
      while (accumulator &amp;gt; deltaTime) {
       update(dt);
       accumulator -= dt;
      }

      //check to make sure that the renderstrategy is valid
      if(SmoothMovement.this.isShowing()) {
       render();
      }

      // if there is any time left due to quick updating and
      // rendering then the thread can sleep
      long timeLeft = (10 - msDelta);
      if (timeLeft &amp;gt; 0) {
       try {
        sync.wait(timeLeft);
       } catch (InterruptedException e) {
       }
      }
     }
    }

   }
  };&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Give it a Try&lt;/b&gt;&lt;br /&gt;
Test it out for yourself and let me know if you still find jitter or notice any places for improvement. I try to always look for ways to improve code and will go back to code I've done previously and see a lot of new optimization's I can make.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Full Source&lt;/b&gt;&lt;br /&gt;
Here's the whole file for you to take a look at.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://sites.google.com/site/morbidmorvick/SmoothMovement.java?attredirects=0&amp;amp;d=1"&gt;SmoothMovement.java&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-1187991505984255027?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wfTBVi6aaTHJTjfq9ESukEjLGWw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wfTBVi6aaTHJTjfq9ESukEjLGWw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wfTBVi6aaTHJTjfq9ESukEjLGWw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wfTBVi6aaTHJTjfq9ESukEjLGWw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/ImNU9Moto_M" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/08/enhancement-smoother-movement.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1187991505984255027?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1187991505984255027?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/ImNU9Moto_M/enhancement-smoother-movement.html" title="Enhancement: Smoother Movement" /><author><name>Nick</name><uri>http://www.blogger.com/profile/00969811931456041499</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/08/enhancement-smoother-movement.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIMRHs7eSp7ImA9WhdSFk0.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-6847831800751768763</id><published>2011-07-25T11:09:00.000-04:00</published><updated>2011-07-25T11:09:45.501-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-25T11:09:45.501-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="vector" /><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="math" /><title>Platform Jumping needs vector-ing</title><content type="html">I was, on my way to showing a simple jump mechanic for a platformer when things just got way to complex for my liking especially the different physics variables, gravity, player speeds, jumping states etc... I had a speed constant and an velocity for jumping and for gravity and for the player. I had this messed up sense of the direction the player was moving, which was a radian angle. It didn't lend itself well to player movement in a platformer. I was flip flopping sin/cos and rotating the angles all over the place. It was a mess, then I just gave in and started using vectors.&lt;br /&gt;
&lt;br /&gt;
Without vectors I had the player falling through the platforms even when it detected hits. I had a bug where I could only move in the air, then I was able to only move on the platform. Had the player repeatedly flying straight up like a rocket. And some double jump code didn't work right either, I kept increasing the velocity applied for the jumping to the point where you wouldn't just smoothly jump up. You'd immediately reach your apex and slowly come back down due to gravity. &lt;i&gt;So yeah there is a lot of stuff to figure out.&lt;/i&gt; &lt;br /&gt;
&lt;br /&gt;
So here is the vector class in all it's wondrous glory, I've used it to good effect so far without needing many changes. The most important functions are the normalize, magnitude, dot, and cross product functions. Those are necessary to perform many physics calculations.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Caveats&lt;/b&gt;: &lt;i&gt;Originally I made this an immutable type but later added mutation methods (set(x,y)). There's probably a few hundred ways to do these calculations, for instance you could just use stand-a-lone static functions, or maybe a class that uses all Point2D.Double's for the vector data, etc... The ZERO static is not usable in calculations if you use the mutator methods, it will mutate the global instance. (oops!!! yeah I found it out because I was using it, should make a subclass for ZERO as a completely immutable type.)&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: java"&gt;/**
 * File: Vector.java
 *
 * This file is free to use and modify as it is for educational use.
 * brought to you by Game Programming Snippets (http://gpsnippets.blogspot.com/)
 *
 * Revisions:
 * 1.1 Initial Revision
 *
 */
package snippets.math;

/**
 * Mathematical vector class implementation. Provides the necessary methods to
 * use vector in physics calculations, ray tracing operations, and other types
 * of directional vectoring math applications. 
 *
 * @author Nick
 */
public class Vector {

 public static Vector ZERO = new Vector(0, 0);

 private double x = 0.0d;
 private double y = 0.0d;

 public Vector(double x, double y) {
  this.x = x;
  this.y = y;
 }

 public Vector add( double c ) {
  return new Vector(this.x+c,this.y+c);
 }

 public Vector add( double x, double y ) {
  return new Vector(this.x+x,this.y+y);
 }

 public Vector add( Vector v ) {
  return new Vector(this.x+v.x,this.y+v.y);
 }

 public Vector cross( Vector v ) {
  return new Vector(this.y - v.y, this.x - v.x );
 }

 public Vector divide( double c ) {
  return new Vector(this.x/c,this.y/c);
 }

 public Vector divide( double x, double y ) {
  return new Vector(this.x/x,this.y/y);
 }

 public Vector divide( Vector v ) {
  return new Vector(this.x/v.x,this.y/v.y);
 }

 public double dot( Vector v ) {
  return this.x * v.x  + this.y * v.y;
 }

 @Override
 public boolean equals(Object o) {
  if(o instanceof Vector) {
   Vector v = (Vector)o;
   return x == v.x &amp;&amp; y == v.y;
  }
  return false;
 }

 public double getX() {
  return x;
 }

 public double getY() {
  return y;
 }

 public double magnitude() {
  return Math.sqrt(this.x * this.x + this.y * this.y);
 }

 public Vector multiply( double c ) {
  return new Vector(this.x*c,this.y*c);
 }

 public Vector multiply( double x, double y ) {
  return new Vector(this.x*x,this.y*y);
 }

 public Vector multiply( Vector v ) {
  return new Vector(this.x*v.x,this.y*v.y);
 }

 public Vector negative() {
  return this.multiply(-1);
 }

 public Vector normalize() {
  double mag = magnitude();
  if(mag != 0) {
   return new Vector(x/mag, y/mag);
  }else {
   return new Vector(x,y);
  }
 }

 public void set(int i, int j) {
  this.x = i;
  this.y = j;
 }
 
 public void set(double x, double y) {
  this.x = x;
  this.y = y;
 }

 public void set(Vector v) {
  x = v.x;
  y = v.y;
 }

 public void setX( double x ) {
  this.x = x;
 }

 public void setY( double y ) {
  this.y = y;
 }

 public Vector subtract( double c ) {
  return new Vector(this.x-c,this.y-c);
 }

 public Vector subtract( double x, double y ) {
  return new Vector(this.x-x,this.y-y);
 }

 public Vector subtract( Vector v ) {
  return new Vector(this.x-v.x,this.y-v.y);
 }

 @Override
 public String toString() {
  return String.format("(%f,%f)", x, y);
 }

 public static Vector valueOf(float x, float y) {
  return new Vector(x, y);
 }

 public static Vector valueOf(double x, double y) {
  return new Vector(x, y);
 }
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-6847831800751768763?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/e6V2T4JJyuUxfvKtKfXtWsxWyWE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e6V2T4JJyuUxfvKtKfXtWsxWyWE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/e6V2T4JJyuUxfvKtKfXtWsxWyWE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e6V2T4JJyuUxfvKtKfXtWsxWyWE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/-OTLVjpZoEk" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/07/platform-jumping-needs-vector-ing.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6847831800751768763?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6847831800751768763?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/-OTLVjpZoEk/platform-jumping-needs-vector-ing.html" title="Platform Jumping needs vector-ing" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/07/platform-jumping-needs-vector-ing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMERX44fSp7ImA9WhdSEkg.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-4098977691650309452</id><published>2011-07-21T09:20:00.000-04:00</published><updated>2011-07-21T09:20:04.035-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-21T09:20:04.035-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="updates" /><title>I hate stagnant blogs don't you!</title><content type="html">I want to just apologize for not having posted in a while, especially to those who frequent this blog, if anyone does yet I want to say thanks for your patience. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Excuses, Excuses&lt;/b&gt;&lt;br /&gt;
Well guys, I've been busy as usual, this economy man it's a killer! Though that seems to be a common excuse these days. And since I have a regular job it isn't really true. Let's just put it this way, things just got busy. You know life stuff hard to keep a good blogging habit with lots of ya know that "stuff".&lt;br /&gt;
&lt;br /&gt;
I've also been putting more time into the Android platform, as well as trying to figure out what the hell I should post next so many ideas and nothing seems to fit. Oh and I have to fight with my lackluster to code lately, yeah I am sorry I am one of those guys. Hey, look man I'm trying!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Blog Stuff&lt;/b&gt;&lt;br /&gt;
So every now and then I like to just randomly rearrange the blog and adjust settings, I noticed with the poll that it was creating scroll-bars, I hate when it does that, so annoying, though i don't think it did it on all browsers. But it did it in chrome which is the one I like to use on a regular basis, migrated from firefox though all three IE, firefox, and chrome have lodged themselves on my computer. &lt;br /&gt;
&lt;br /&gt;
So I was going through the gadgets looking for something interesting and I dunno how does one choose from the pictures of hot chicks, puppy's, and style tips. Such tough decisions, yeah don't need to put any of those here, I doubt you want to be distracted by cute puppy's while reading or do you? So I decided on showing the Total pageviews thing, it's not terribly exciting only 12,188 at the time of this post. About 10-20 average visits a day. Not enough to make a living on, maybe someday. It'd be nice to be able to work on games all day as I do most of this in my little free time. So while I wait for that to happen I will just keep working on more snippets. Also removed some extra clutter with the external links, didn't really see a need for them but if someone liked using them please let me know. Added rss feed to gamasutra which I find an extremely good source for game design articles and other industry news as well as a couple of blog writers who share insights into how studios handle particular issues.&lt;br /&gt;
&lt;br /&gt;
I really hope they are useful and anything you can think of that would help you out don't hesitate to ask me to try and figure out. Still need to figure out how to make the toggle screen-mode more professional.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-4098977691650309452?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vcHzRBLv0dXpkmA4NJjUDSXHJJ4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vcHzRBLv0dXpkmA4NJjUDSXHJJ4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vcHzRBLv0dXpkmA4NJjUDSXHJJ4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vcHzRBLv0dXpkmA4NJjUDSXHJJ4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/ZkbHDzRnHNQ" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/07/i-hate-stagnant-blogs-dont-you.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/4098977691650309452?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/4098977691650309452?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/ZkbHDzRnHNQ/i-hate-stagnant-blogs-dont-you.html" title="I hate stagnant blogs don't you!" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/07/i-hate-stagnant-blogs-dont-you.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEERnY5fSp7ImA9WhZXEEQ.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-8664012364761358932</id><published>2011-04-29T11:55:00.001-04:00</published><updated>2011-04-29T11:56:47.825-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-29T11:56:47.825-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="poll" /><category scheme="http://www.blogger.com/atom/ns#" term="gamasutra" /><category scheme="http://www.blogger.com/atom/ns#" term="status" /><category scheme="http://www.blogger.com/atom/ns#" term="acheivements" /><title>Regarding Poll</title><content type="html">I just realized something about the poll I put up, trying to see what people are interested in so I can focus on those snippets first. Whether it be collision detection, effects (particle system, animational effects etc.), game mechanics (scoring, acheivement systems, quests, stat systems, etc.), content tools would be like map editors, file format converters, asset building tools, particle engine editors, model viewers etc. And of course it isn't hard to guess what I meant with full game tutorials.&lt;br /&gt;
&lt;br /&gt;
Anyways, what I realized is that I could probably use more of all of them, so I just wanted to see which ones I should work on first. Life being busy doesn't really leave me much time to work up solid snippets to help other developers.&lt;br /&gt;
&lt;br /&gt;
Enough lamenting, on to more important issues,&amp;nbsp;achievements, saw a good article for those of you who are interested and don't watch &lt;a href="http://www.gamasutra.com"&gt;gamasutra&lt;/a&gt;, like I do, here it is:&lt;br /&gt;
&lt;a href="http://www.gamasutra.com/view/feature/6360/the_cake_is_not_a_lie_how_to_.php?page=1"&gt;The Cake Is Not a Lie: How to Design Effective Achievements&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Some things to keep in mind if you are considering adding achievements to a game, some thought provoking analysis of games as always from the articles at gamasutra.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-8664012364761358932?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/nYIdf8YPZuRhUgnQIYupt4pFxBs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nYIdf8YPZuRhUgnQIYupt4pFxBs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/nYIdf8YPZuRhUgnQIYupt4pFxBs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/nYIdf8YPZuRhUgnQIYupt4pFxBs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/Sol47ILokp0" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/04/regarding-poll.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/8664012364761358932?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/8664012364761358932?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/Sol47ILokp0/regarding-poll.html" title="Regarding Poll" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/04/regarding-poll.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08DRH49fSp7ImA9WhZQE0U.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-8097942177818195815</id><published>2011-04-21T07:37:00.000-04:00</published><updated>2011-04-21T07:37:55.065-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-21T07:37:55.065-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="poll" /><category scheme="http://www.blogger.com/atom/ns#" term="status" /><category scheme="http://www.blogger.com/atom/ns#" term="updates" /><title>Status &amp; Poll</title><content type="html">Been kind of busy lately with life, attempting to get into the android market but still have a lot of knowledge to share on making games in Java, I've been wanting to do more jogl and step up to some of the changes in jogl 2.0. I thought I would create a poll to help give me a little direction on what I should post here that would be the most useful for readers.&lt;br /&gt;
&lt;br /&gt;
One of the big issues I have been wrestling with is making games vs. engines it's a tough thing. Especially since my engine is 90% there and almost ready to start being used to make complete games, I have had a few setbacks with select pieces of the design. Aside from that, my day job has been cutting into the amount of energy and desire I have to code when I get home.&lt;br /&gt;
&lt;br /&gt;
This is probably the first actual blog post I've written, weird but it's the truth. Mainly I started this blog to post snippets I wanted to save and to help other developers to see how I solve some of the problems in making Java games. So I figured what the hell I'll actually start blogging instead of letting this blog just sit around idling in the blog'o'sphere.&lt;br /&gt;
&lt;br /&gt;
So please take a second to vote on the poll for the things you are looking for and I will do what I can to help.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-8097942177818195815?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PoKkZylSRxFMcn7yE-qd6XT7g80/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PoKkZylSRxFMcn7yE-qd6XT7g80/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PoKkZylSRxFMcn7yE-qd6XT7g80/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PoKkZylSRxFMcn7yE-qd6XT7g80/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/vtlaVE1popc" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/04/status-poll.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/8097942177818195815?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/8097942177818195815?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/vtlaVE1popc/status-poll.html" title="Status &amp; Poll" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/04/status-poll.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0cDRHwyeCp7ImA9WhZQE0U.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-6788160739394881281</id><published>2011-04-08T08:19:00.002-04:00</published><updated>2011-04-21T07:24:35.290-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-21T07:24:35.290-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="opengl-es" /><category scheme="http://www.blogger.com/atom/ns#" term="demo" /><category scheme="http://www.blogger.com/atom/ns#" term="test" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="first android app" /><title>TapMania: First Android Test App</title><content type="html">&lt;a href="http://3.bp.blogspot.com/-YB8tevV2xSg/TZ773C9erII/AAAAAAAAAKw/6idPO1cUPCY/s1600/TapMania_Screen.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-YB8tevV2xSg/TZ773C9erII/AAAAAAAAAKw/6idPO1cUPCY/s320/TapMania_Screen.png" width="192" /&gt;&lt;/a&gt;I have been getting into Android application development and wrote a small application to get my feet wet. This application just tests some OpenGL render capabilities, touch screen functionality, displays some text output for debugging purposes, and gives some basic menu options.&lt;br /&gt;
&lt;br /&gt;
If you wanna try it out and test your phones touch screen and also help me determine how well it runs on other devices, I would greatly appreciate it. This will also help me to create some snippets for android and let you know what issues I find and things about performance for android games. So far the OpenGL-ES on android is working great on my phone I would love to know how it works on others.&lt;br /&gt;
&lt;br /&gt;
I am still going through the process of setting the application up for publication to the android market as a demo to get more feedback and to grow the application into a game.&lt;br /&gt;
&lt;br /&gt;
Let me know what you think!&lt;br /&gt;
&lt;br /&gt;
Link to apk:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;TapMania.apk (link now removed, app available on the android market)&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;&lt;i&gt;Note: After realizing that the link to my google sites did not successfully allow you to install from your phone I finished the publishing process and got it up on the android market. I have a few small updates that I will publish this weekend.&lt;/i&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-6788160739394881281?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/g0s9O6hz4fJI2UQSDuj1F2-lo6M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g0s9O6hz4fJI2UQSDuj1F2-lo6M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/g0s9O6hz4fJI2UQSDuj1F2-lo6M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/g0s9O6hz4fJI2UQSDuj1F2-lo6M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/PPweK5Bivy0" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/04/tapmania-first-android-test-app.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6788160739394881281?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6788160739394881281?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/PPweK5Bivy0/tapmania-first-android-test-app.html" title="TapMania: First Android Test App" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-YB8tevV2xSg/TZ773C9erII/AAAAAAAAAKw/6idPO1cUPCY/s72-c/TapMania_Screen.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/04/tapmania-first-android-test-app.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUAESH44fSp7ImA9WhZSF0Q.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-2564743916793329092</id><published>2011-04-02T22:28:00.000-04:00</published><updated>2011-04-02T22:28:29.035-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-02T22:28:29.035-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="troubleshooting" /><category scheme="http://www.blogger.com/atom/ns#" term="high CPU usage" /><category scheme="http://www.blogger.com/atom/ns#" term="comments" /><category scheme="http://www.blogger.com/atom/ns#" term="faster rendering" /><category scheme="http://www.blogger.com/atom/ns#" term="responses" /><category scheme="http://www.blogger.com/atom/ns#" term="debugging" /><category scheme="http://www.blogger.com/atom/ns#" term="java rendering performance" /><category scheme="http://www.blogger.com/atom/ns#" term="Double Buffering" /><title>Response: Debugging High CPU Usage</title><content type="html">&lt;i&gt;&lt;b&gt;Answer to:&lt;/b&gt; a comment posted on &lt;a href="http://gpsnippets.blogspot.com/2007/06/double-buffering-and-timed-rendering.html?showComment=1301390661992#c6091470851313847461"&gt;Double Buffering and Timed Rendering&lt;/a&gt; and on &lt;a href="http://gpsnippets.blogspot.com/2007/06/game-state-machine.html"&gt;Game State Machine&lt;/a&gt;&lt;/i&gt; about 100% CPU usage with those samples.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Disclaimer:&lt;/b&gt; If you modified the examples, I can't help you, lol just kidding, it's a silly thing to have to say but try just redownloading and running the examples without any modifications.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The answer is a bit complicated, high CPU usage might be due to a few things.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Note:&lt;/b&gt; One thing I did not do that might make a difference is to use the &lt;a href="http://download.oracle.com/javase/1.4.2/docs/api/java/awt/GraphicsConfiguration.html#createCompatibleImage(int, int)"&gt;createCompatibleImage&lt;/a&gt; method, this might make all the difference but I've never seen it have any effect. Or you could try using a VolatileImage it has it's own issues though, and I've never seen it have any effect either. If that doesn't work turn on java2D logging using the system properties see link below and look to see how long drawing operations are taking. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Another Note: &lt;/b&gt;If not on windows, try turning on opengl rendering and make sure it's actually on, you can verify it by using the "True" string for turning it on, with the capital "T" it will output whether opengl or directx rendering are being used.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Java Version Issues&lt;/b&gt;&lt;br /&gt;
Using your own buffer and repaint should work decently in Java versions on windows greater than 1.4.1 update 2, when directx support was added and turned on by default. Opengl support was added as of 1.5 but is not turned on by default on any platform, so you'd want to try fiddling with some of these properties. See &lt;a href="http://download.oracle.com/javase/6/docs/technotes/guides/2d/flags.html#d3d"&gt;System Properties&lt;/a&gt; docs&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem with Repaint&lt;/b&gt;&lt;br /&gt;
In earlier versions of Java using repaint would result in tearing issues, because old swing versions would be not be double buffered. Thus the example with their own double buffering.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Hardware Acceleration Issues&lt;/b&gt;&lt;br /&gt;
No hardware acceleration will be available &lt;b&gt;if you don't have some type of graphics card&lt;/b&gt; or if java has issues with the &lt;i&gt;drivers&lt;/i&gt;, so it will only go as fast as the underlining computers CPU can handle in that case. Another issue using BufferedImages is the hardware acceleration can be lost if the bufferedimage raster is modified. Another choice is to use the &lt;a href="http://gpsnippets.blogspot.com/2010/10/how-to-use-bufferstrategy-in-java.html"&gt;Canvas approach with BufferStrategy&lt;/a&gt; which I have seen much much better performance than either creating a buffer myself .&lt;br /&gt;
&lt;br /&gt;
I haven't seen 100% constant CPU usage with this example myself. If repaint works I do suggest going with what you know works well until you find something better. &lt;b&gt;In the end if looks good and feels good for your game then it doesn't matter which method you use.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Things I tried&lt;/b&gt;&lt;br /&gt;
Trying to duplicate the 100% CPU usage with the Double Buffering and the Game State Machine examples was unsuccessful. I tried turning off hardware acceleration -Dsun.java2d.noddraw=True still performed as expected. I didn't change any of the code so it was left as is, still no 100% CPU usage, on an old 2.66 GHZ pentium 4 with a NVIDIA GeForce 8400 GS graphics card and tested with Java versions 1.5, 1.6, and 1.7ea without issue.&lt;br /&gt;
&lt;br /&gt;
The only thing I could think of that would cause 100% CPU usage with these examples in their unmodified state is if the TimerTask run method takes more than 16 milliseconds. That would bog down the timer with continuous tasks needing to be fired since the java.awt.Timer is a single threaded queue based task scheduler. I was able to bog down the Timer and see high cpu usage. Haven't tried forcibly making the bufferedimage non-hardware accelerated yet. You could implement your own timer and see if that makes a difference. &lt;br /&gt;
&lt;br /&gt;
I am meaning to work up a new snippet with better rendering methods, and updated code. The &lt;a href="http://gpsnippets.blogspot.com/2010/10/how-to-use-bufferstrategy-in-java.html"&gt;BufferStrategy&lt;/a&gt; approach link above is a good alternative and much better frame rates. Give that a try if your having trouble, I would also like to know if that works better for most systems. It's been a long time since I did those snippets back in 2007 I have learned a lot since then, still there is much much more to learn.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;One Last Thing&lt;/b&gt;&lt;br /&gt;
I do remember that there was some issues I had on windows with a graphics card installed that slowed my rendering significantly, those were the options in the Display Properties -&gt;  Settings (tab) -&gt; Advanced -&gt; Troubleshoot (tab) the Hardware Acceleration, I have seen it have interesting effects at different levels with some of my Java games projects.&lt;br /&gt;
&lt;br /&gt;
For further help just ask and you shall receive, of course more details next time would help tremendously.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Good Luck!&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-2564743916793329092?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YtxJ5hrT69UKSo1mHpqei77kSQA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YtxJ5hrT69UKSo1mHpqei77kSQA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YtxJ5hrT69UKSo1mHpqei77kSQA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YtxJ5hrT69UKSo1mHpqei77kSQA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/t9mbHNeLJQg" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2011/04/response-debugging-high-cpu-usage.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/2564743916793329092?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/2564743916793329092?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/t9mbHNeLJQg/response-debugging-high-cpu-usage.html" title="Response: Debugging High CPU Usage" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2011/04/response-debugging-high-cpu-usage.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUIDSXk5eip7ImA9Wx9RGU4.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-1964518621664192565</id><published>2010-12-21T08:11:00.003-05:00</published><updated>2010-12-21T08:19:38.722-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-21T08:19:38.722-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Maps" /><category scheme="http://www.blogger.com/atom/ns#" term="layering" /><category scheme="http://www.blogger.com/atom/ns#" term="multiple layers multi-layers" /><category scheme="http://www.blogger.com/atom/ns#" term="grid indexing" /><category scheme="http://www.blogger.com/atom/ns#" term="Scrolling" /><category scheme="http://www.blogger.com/atom/ns#" term="Tiles" /><category scheme="http://www.blogger.com/atom/ns#" term="Map Generation" /><category scheme="http://www.blogger.com/atom/ns#" term="2D tile map" /><title>Scrolling Multi-layered Map</title><content type="html">&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_eLO9nXo-B1k/TRCS4NBpHlI/AAAAAAAAAJ0/dRuA96pYIk0/s1600/scrollingtilemap01.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="150" src="http://3.bp.blogspot.com/_eLO9nXo-B1k/TRCS4NBpHlI/AAAAAAAAAJ0/dRuA96pYIk0/s200/scrollingtilemap01.jpg" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Only the top-left most part of the &lt;br /&gt;
generated map&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;The next logical step for a tilemap is to add scrolling. The problem is you don't want to be drawing every tile in the map all the time so our basic approach will not work for larger and larger maps. We need a solution that will only ever loop through and draw the tiles that are going to be visible. This snippet makes sure that only the visible tiles in the background layer are drawn. Its limited though because all the foliage tiles are drawn, however a quick bounds check might be enough to skip the expensive render calls but we would want to find a way to remove those loops entirely.&lt;/div&gt;&lt;br /&gt;
See &lt;a href="http://gpsnippets.blogspot.com/2010/11/rendering-multi-layered-map.html"&gt;Rendering Multi-layered Map&lt;/a&gt; and &lt;a href="http://gpsnippets.blogspot.com/2010/11/rendering-basic-tiled-maps.html"&gt;Rendering Basic Tiled Maps&lt;/a&gt; for details on other pieces in this snippet.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What's Different&lt;/b&gt;&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_eLO9nXo-B1k/TRCTDj-aNdI/AAAAAAAAAJ8/7PJgZiNZQks/s1600/scrollingtilemap02.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="150" src="http://2.bp.blogspot.com/_eLO9nXo-B1k/TRCTDj-aNdI/AAAAAAAAAJ8/7PJgZiNZQks/s200/scrollingtilemap02.jpg" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Larger section of the same map&lt;br /&gt;
Using scrolling&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;The map generation is pretty much the same &lt;i&gt;aside from keeping around the mapping of integers to tiles the method discussed the previous map snippets&lt;/i&gt;. Sorry to say it's not a very good implementation but that is an area that can be improved upon in a future snippet :) . It works for the time being.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A new update method has been added and the unused passed variable in the render thread is now being used to passed the number of seconds passed each frame to the update method. NOTE: this isn't the most accurate way of time keep as it is directly effected by frame rates and could cause jittery and inconsistent animation. But then we're not worried about animation here so it doesn't really matter. I added a keylistener to track when and which arrow keys are down in order to scroll the map. The update method handles the actual calculations to move around the map based on the keys that are pressed, it's just simple input handling nothing special. Here is the update method implementation.&lt;/div&gt;&lt;br /&gt;
&lt;pre class="brush: java"&gt;/**
  * This method will move our position in the map.
  *
  * @param d
  */
 protected void update(double d) {

  Dimension screenSize = getPreferredSize();

  if (up) {
   y -= scrollSpeed * d;
  } else if (down) {
   y += scrollSpeed * d;
  }

  if (right) {
   x += scrollSpeed * d;
  } else if (left) {
   x -= scrollSpeed * d;
  }

  //clamp display area to inside the map
  if(x &amp;lt; 0) {
   x = 0;
  }

  if(y &amp;lt; 0) {
   y = 0;
  }

  // handle what happens when we reach over the edge of the map
  if(x + screenSize.width &amp;gt; mapSize.width) {
   x = mapSize.width - screenSize.width; //revert to last position
  }

  if(y + screenSize.height &amp;gt; mapSize.height) {
   y = mapSize.height - screenSize.height; //revert to last position
  }
 }&lt;/pre&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;So there is some extra handling if we try and scroll outside the visible area of the map. There is bottom and left edge handling which works pretty accurately. So no matter what our speed is we ensure that as soon as the visible area is outside the map we will reset them to be exactly at the edge and never beyond. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The rendering method has been altered heavily for this snippet as it now needs to be able to handle a larger map. &lt;/div&gt;&lt;br /&gt;
&lt;pre class="brush: java"&gt;/**
  * We only want to render what is currently visible on screen, so we need to
  * take into account the current starting x,y coordinates which will be used
  * to scroll through the map during updates. Our world object holds the
  * tiles in terms of a single index value
  *
  * @param g
  */
 protected void render(Graphics2D init) {
  // draw only the tiles that are visible, the visible area is given by
  // the size of the component and the current x,y starting position on
  // screen.
  Dimension screenSize = getPreferredSize();
  Graphics2D g = (Graphics2D) init.create();
  g.setColor(Color.black);
  g.fillRect(0, 0, screenSize.width, screenSize.height);
  g.translate(-x, -y); // move the graphics object to the new position

  // this will give us the row in the map grid we are starting from
  int sRow = (int)y / tileHeight;
  int sCol = (int)x / tileWidth;
  int cols = 1 + screenSize.width / tileWidth; // total number of columns
  int rows = 1 + screenSize.height / tileHeight; // total rows
  int row, col;
  Tile t;
  int index = 0;
  for (int i = 0; i &amp;lt; rows * cols; ++i) {
   row = i / cols;
   col = i - row * cols;

   // transform to new position in the map
   row += sRow;
   col += sCol;

   index = row * (mapSize.width/tileWidth) + col;

   // we are outside the bounds of the map, safety check
   if(index &amp;gt;= tiles.size()) {
    break;
   }

   // draw the tile at the given index
   tiles.get(index).render(g);
  }

  // keeping it simple, and fast
  // TODO: Optimize to only loop over visible objects in the world
  for (Tile tile : world) {
   tile.render(g);
  }
  g.dispose();

  // draw debug string on top of everything
  g = init;
  g.setColor(Color.black);
  g.drawString(String.format("%.2f (%d), %.2f (%d)", x, sCol,y, sRow), 10, 10);
 }&lt;/pre&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;One of the benefits of using the HashMap&lt;integer, tile=""&gt; approach is evident here we can pull the tile to draw from this map with O(1) constant time lookup. This is huge here because we don't need to rebuild a list of all visible tiles nor do we have to partition the map in any way. We've kept the background tiles in a single collection increasing memory efficiency and locality, hopefully. After working with Java's HashMaps you begin to wonder what you would ever do without them.&amp;nbsp;&lt;/integer,&gt;&lt;/div&gt;&lt;integer, tile=""&gt; &lt;br /&gt;
&lt;b&gt;How it works?&lt;/b&gt;&lt;br /&gt;
Going back to a previous snippet "Rendering Basic Tiled Maps" I outlined a way of indexing tiles from top-left to bottom-right.&lt;br /&gt;
&lt;/integer,&gt;&lt;br /&gt;
&lt;pre&gt;+-x 0   1   2
y .---.---.---.
0 | 0 | 1 | 2 |
  |---|---|---|
1 | 3 | 4 | 5 |
  |---|---|---|
2 | 6 | 7 | 8 |
  '---^---^---'&lt;/pre&gt;Basically we will create an index like this for the visible area which is only a subset of the larger map.&lt;br /&gt;
&lt;pre&gt;+-x 0   1   2
y .---.---.---.
0 | 0 | 1 | 2 |      0   1
  |---@@@@@@@@@ =&amp;gt; .---.---.
1 | 3 @ 4 | 5 @  0 | 0 | 1 |
  |---@---|---@    |---|---|
2 | 6 @ 7 | 8 @  1 | 2 | 3 |
  '---@@@@@@@@@    '---^---'
    Full Map        Visible
                     Area&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;We will iterate through the indexes of the visible area grid 0,1,2,3 and for each column and row of that visible area which will be 0-0, 1-0, 0-1 and 1-1 respectively we will add an column and row offset to them based on the visible areas position in the larger map.  The offset in the example above would be 1,1 now the corresponding indexes into the larger map will be (0+1) * 3 + (0 + 1) = 4 then (0+1) * 3 + (1+1) = 5 now we move down one row (1+1) * 3 + (0+1) = 7 and the last is (1+1) * 3 + (1+1) = 8. Pretty neat huh, well at least I thought so when I came up with it years ago while making my first small game in Visual Basic 5, yeah it's been a long time since then.&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Where's the Snippet&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;So here it is, a bit lengthy now at 639 lines but it's all in a single source file if you've been following along with the previous examples it shouldn't be hard to pickup and use these concepts in your own way, if you find them useful. I of course would love to hear more opinions on this method or better implementations. Always looking for more efficient ways to do things and squeeze every nanosecond out of that CPU. Happy Holiday coding everyone!&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="https://sites.google.com/site/morbidmorvick/ScrollingTilemapRendering.java?attredirects=0&amp;amp;d=1"&gt;ScrollingTilemapRendering.java&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-1964518621664192565?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3crqNvrDygM5PTmzI3r7okSx-6Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3crqNvrDygM5PTmzI3r7okSx-6Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3crqNvrDygM5PTmzI3r7okSx-6Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3crqNvrDygM5PTmzI3r7okSx-6Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/I3OPLgnEA2E" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2010/12/scrolling-multi-layered-map.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1964518621664192565?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1964518621664192565?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/I3OPLgnEA2E/scrolling-multi-layered-map.html" title="Scrolling Multi-layered Map" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_eLO9nXo-B1k/TRCS4NBpHlI/AAAAAAAAAJ0/dRuA96pYIk0/s72-c/scrollingtilemap01.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2010/12/scrolling-multi-layered-map.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0AMQ3YzeSp7ImA9Wx9TFUw.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-1415764069108300071</id><published>2010-11-23T08:43:00.000-05:00</published><updated>2010-11-23T08:43:02.881-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-23T08:43:02.881-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Game Engine" /><category scheme="http://www.blogger.com/atom/ns#" term="Game Context" /><category scheme="http://www.blogger.com/atom/ns#" term="Design Patterns" /><category scheme="http://www.blogger.com/atom/ns#" term="Game Engine Design" /><category scheme="http://www.blogger.com/atom/ns#" term="Design" /><title>Game Engine Design: Game Contexts</title><content type="html">I have been working on game engine design for the past... um... hmm I can't remember when I started... well lets just say it's been years. Typically I have entity objects, and a &lt;a href="http://gpsnippets.blogspot.com/2007/06/game-state-machine.html"&gt;Game State Machine&lt;/a&gt; implementation. The entity objects became the base class for all other game objects. Entity objects would have been able to be updated and rendered. This allowed me to do everything I needed specific to each entity.&lt;br /&gt;
&lt;br /&gt;
For rendering I would pass only the graphics object to each entities render method. Something that looks like &lt;code&gt;public void render(Graphics2D g)&lt;/code&gt;. For updating I would pass the time passed since the last call which looked something like &lt;code&gt;public void update(double dt)&lt;/code&gt;. Each entity would have their render/update methods called at least one per frame. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How it used to be!&lt;/b&gt;&lt;br /&gt;
As I was working on a few games using my work-in-progress engine code, I came across situations where it would be easier for the entities to already have all the information they need and have spawn and kill functions. A game entity needs to know information about the world, other objects, screen sizes, etc. Also I needed the ability for an entity to change states of the game system. But that is only because the entities were checking input and doing game logic.&lt;br /&gt;
&lt;br /&gt;
The system worked fine the way it was, it was just very painful modifying constructors and adding parameters to methods, I had even modified the render methods sometimes to be passed the time and dimensions of the screen. I constructed a Spawner interface which essentially was implemented by my world container class and allowed objects to have a spawner and to spawn other objects. The spawner was really really nice because it allowed any entity to create new ones on the fly the creating entity could hold on to them and then kill them if need be. The problem with this approach is that each object contains a reference to a spawner, which had to be set and could potentially not have been set causing errors or lots of additional null checks.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Enter Game Contexts&lt;/b&gt;&lt;br /&gt;
I am a big fan of &lt;a href="http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29"&gt;Design Patterns&lt;/a&gt; and after experimenting with different design patterns in games such as the Composite, Observer, Visitor and Mediator. I found that what my entity objects needed was a mediator between them and the rest of the game system. So I figured I could put all the methods and information needed by the game objects into an interface to be implemented by the main game class. It turned out to look something like this&lt;br /&gt;
&lt;pre class="brush: java"&gt;public interface GameContext {

    // the width of the screen
    public int getWidth();

    // the height of the screen
    public int getHeight();

    // the input manager
    public InputManager getInput();

    // the time passed in seconds between frames
    public double getTimePassed();

    // spawn a new entity
    public void spawn(Entity e);

    // kill the entity
    public void kill(Entity e);

    // switch game states
    public void changeState(State next);

    // return the graphics object used for rendering
    public Graphics2D getGraphics();

    // set fullscreen mode
    public void setFullscreen(boolean fullscreen);

    // return whether the game is fullscreen or not
    public boolean isFullscreen();

}&lt;/pre&gt;This interface gave each game object the methods it needed to do a lot more than they could before. The render/update methods now changed to&lt;br /&gt;
&lt;pre class="brush: java"&gt;public void render(GameContext gc);

public void update(GameContext gc);&lt;/pre&gt;It really does make a lot of difference when creating new entities and you can add lots more to the GameContext. For instance you could have a method for collision detection or initiating certain effects etc... It is also just as efficient as the previous method since only one parameter is being passed to the game objects.&lt;br /&gt;
&lt;br /&gt;
I hope to show a full runnable snippet using this idea sometime in the future. This should be enough to get you started if you already have something in place. If you have an alternative method to share it would be much appreciated, or if you've already used something like this it would be nice to know as well. &lt;br /&gt;
&lt;br /&gt;
That's all for now, getting ready for Turkey day.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-1415764069108300071?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/a85v-ld6niTp-_-3pP3jQq9D2w0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/a85v-ld6niTp-_-3pP3jQq9D2w0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/a85v-ld6niTp-_-3pP3jQq9D2w0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/a85v-ld6niTp-_-3pP3jQq9D2w0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/yA4zUyLToHc" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2010/11/game-engine-design-game-contexts.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1415764069108300071?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/1415764069108300071?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/yA4zUyLToHc/game-engine-design-game-contexts.html" title="Game Engine Design: Game Contexts" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2010/11/game-engine-design-game-contexts.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMNQX4yeSp7ImA9Wx5aGUw.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-6174881188560688991</id><published>2010-11-16T08:34:00.000-05:00</published><updated>2010-11-16T08:34:50.091-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-16T08:34:50.091-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="z-ordering" /><category scheme="http://www.blogger.com/atom/ns#" term="2D Level" /><category scheme="http://www.blogger.com/atom/ns#" term="layering" /><category scheme="http://www.blogger.com/atom/ns#" term="Graphics" /><category scheme="http://www.blogger.com/atom/ns#" term="multiple layers multi-layers" /><category scheme="http://www.blogger.com/atom/ns#" term="Game Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="2D tile map" /><title>Rendering Multi-layered Map</title><content type="html">&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: justify;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_eLO9nXo-B1k/TOKFkzP_BvI/AAAAAAAAAJY/on4kxRobHUI/s1600/layered-tilemap-rendering.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="150" src="http://2.bp.blogspot.com/_eLO9nXo-B1k/TOKFkzP_BvI/AAAAAAAAAJY/on4kxRobHUI/s200/layered-tilemap-rendering.jpg" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Similar to the previous snippet only now the &lt;br /&gt;
green squares and diamonds represent some foliage. &lt;br /&gt;
Note: That the map generation algorithm still needs &lt;br /&gt;
a bit of work to make decent looking terrain.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;When using a map in a game you always are going to want to draw items equipment and perhaps buildings and structures on top of terrain. This is known as layering, you may be familiar with it if you have done used photoshop or perhaps in making your own games. It is even used in GUI programming although it is usually referred to as z-ordering. You want to use it anytime you have a rendering order in which something you are drawing will appear on top of a part of something else but doesn't fully cover it. In 3D graphics many times you don't have to worry about the order in which you draw objects since the graphics card will automatically determine per pixel drawn if it is covered by something else, that entails using a depth buffer.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If we wanted to we could implement our own depth buffering system on the CPU side, however it would take a lot of processing power and be inefficient. So we will draw in top left to bottom right order drawing the bottom layer and then each layer above that separately.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Ordering&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So how do we determine this order and make it flexible for pretty much any game we want to create. Ones first instinct is usually to make a list or map of layers each layer containing all the objects to be rendered on that layer, and traverse these nested lists in order. This results in some nested for loops which I try to avoid at all costs. So my solution is to order each rendered element when you insert it into the collection of all elements to draw. This makes the rendering loop a single continuous loop we can't get much more efficient than that. The only other optimization we can do is to make sure we only draw what is visible on the screen, and nothing we draw is unnecessary, sometimes the cost of removing those unnecessary loop cycles is to expensive so it's best to just try and determine them beforehand or not at all.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Code Snippet&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This snippet is based off of the previous snippet&amp;nbsp;&lt;a href="http://gpsnippets.blogspot.com/2010/11/rendering-basic-tiled-maps.html"&gt;Rendering Basic Tiled Maps&lt;/a&gt;. Not much has changed between the two except the tile class, map generation function, and tileset generation function have added support for layers demonstrated by some placeholder images. The map generation algorithm I'm afraid is a little bit confusing.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;How Layers Work&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This implementation sets each tile with a layer integer that is used in the TreeSet red-black tree sorting. Which makes it efficient because you are going to order the tiles and layers when creating the map and you don't need to touch it after that. Another way of doing this would be to use an ArrayList or any other sortable collection in the Java Collections package and sort when you need to, especially if you need constant time access into the collection. Alternatively you can create another collection of the tiles or containers of subsets of the map in order to do whatever you need. I choose to use TreeSet as it is simple enough for this example, and I won't be needing to do anything but draw the list of objects on the map.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The rendering loop remains the same, just as simple as we can possibly make it.&lt;/div&gt;&lt;pre class="brush: java"&gt;protected void render(Graphics2D g) {
  // keeping it simple, and fast
  for (Tile tile : world) {
   tile.render(g);
  }
 }&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;Any simpler and it'd just be a completed list drawing each tile individually in the order we wanted.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The real meat of this snippet is in the compareTo function of the Tile. Because the TreeSet either requires a comparator to order the elements or requires the element type to implement the Comparable interface we need to provide one of the two. For simplicity I choose the later of the two, even though making a Comparator would be advantageous because then it would be easier to add different types of objects to our map other than just Tile objects.&lt;/div&gt;&lt;pre class="brush: java"&gt;/* (non-Javadoc)
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  @Override
  public int compareTo(Tile o) {
   if (layer &gt; o.layer) {
    // this object should be displayed after o because it is
    // on a higher layer than o
    return 1;
   } else if (layer &lt; o.layer) {
    // o should be displayed before this object because it is
    // on a lower layer than o
    return -1;
   } else {
    // if there are on the same layer sort them top,left to bottom
    // right order
    if (y &lt; o.y) {
     return -1;
    } else if (y &gt; o.y) {
     return 1;
    } else if (x &lt; o.x) {
     return -1;
    } else if (x &gt; o.x) {
     return 1;
    } else {
     // their in the same position same layer, this is probably
     // not intentional, but could happen
     return 0;
    }
   }
  }
 }&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;A bit messy but it gets the job done efficiently. So we compare the layers, if the two objects are not on the same layer there is no need to go any further we return 1 meaning that the tile compareTo was called on should come after the tile o because its on a higher layer, and -1 if it should come before the tile o.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If they are on the same layer we are going to order the objects from top-left to bottom-right order. So we compare the coordinates of each tile. This is actually something that can be handled by the indexing method I explained in the previous post.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So here is the snippet for you to play around with comments are welcome as always.&lt;/div&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;a href="https://sites.google.com/site/morbidmorvick/LayeredTilemapRendering.java?attredirects=0&amp;amp;d=1"&gt;LayeredTilemapRendering.java&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-6174881188560688991?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/09V3uzW-vGVfU8skCMh0vZiky9s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/09V3uzW-vGVfU8skCMh0vZiky9s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/09V3uzW-vGVfU8skCMh0vZiky9s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/09V3uzW-vGVfU8skCMh0vZiky9s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/IliyM_UhFHI" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2010/11/rendering-multi-layered-map.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6174881188560688991?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/6174881188560688991?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/IliyM_UhFHI/rendering-multi-layered-map.html" title="Rendering Multi-layered Map" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_eLO9nXo-B1k/TOKFkzP_BvI/AAAAAAAAAJY/on4kxRobHUI/s72-c/layered-tilemap-rendering.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2010/11/rendering-multi-layered-map.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUcNR30-fyp7ImA9Wx9RGU4.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-818970398514584684</id><published>2010-11-09T08:44:00.005-05:00</published><updated>2010-12-21T08:11:36.357-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-21T08:11:36.357-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Rendering" /><category scheme="http://www.blogger.com/atom/ns#" term="Maps" /><category scheme="http://www.blogger.com/atom/ns#" term="2D Level" /><category scheme="http://www.blogger.com/atom/ns#" term="grid indexing" /><category scheme="http://www.blogger.com/atom/ns#" term="Levels" /><category scheme="http://www.blogger.com/atom/ns#" term="Tiles" /><category scheme="http://www.blogger.com/atom/ns#" term="Map Generation" /><title>Rendering Basic Tiled Maps</title><content type="html">&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;
&lt;tr align="justify"&gt;&lt;td&gt;&lt;a href="http://1.bp.blogspot.com/_eLO9nXo-B1k/TNlSQBPVJeI/AAAAAAAAAJA/IjEVtgupXtw/s1600/AutoGeneratedMap.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="150" src="http://1.bp.blogspot.com/_eLO9nXo-B1k/TNlSQBPVJeI/AAAAAAAAAJA/IjEVtgupXtw/s200/AutoGeneratedMap.jpg" width="200" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Auto generated map and tiles it's a&lt;br /&gt;
bit rough though.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;O.k! So this snippet is a little lengthy, I could not find an acceptable way of showing the map without either using a random map generator or including code for loading a map from a file. I choose the former but the algorithm didn't quite turn out the way I had hoped. It's a bit messy as I tried to avoid recursion and also the generated maps don't really look spectacular. Although it should get the point across and provide a basis for much more work to be done with it.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Tiles&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The tiles are a bit complex and I hope to show much easier and cleaner ways of both representing and rendering. While there is nothing wrong with a loop through all tiles drawing each in it's own known position. It doesn't provide the flexibility we need to add features such as layers, smooth scrolling, at least not in an efficient way. We later we will want to limit our drawing to only show the part of the map that is actually visible, and maps can get large.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Inevitably these limitations will force us to make trade-offs for game performance. If we draw more we will have less time to devout to updating enemies and objects that aren't even on screen yet. And the levels can get larger and larger. Which is why there are concepts like check points and areas where the level is split up. It's not so much keeping that in memory as it is updating those objects every frame. Unfortunately for most game concepts you can't remove unneeded updates to those objects easily unless your game is designed for it. This is most true in strategy games and simulations where the drawing only accounts for a small fraction of the total number of updated objects. But more on these later.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Oddities in Snippet&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A couple things you might find odd about the way I coded the rendering algorithm or my coding style in general. First of all I dislike large procedures so I will try my best to keep every method simple, though there have been a few lengthy ones but they have almost always been cohesive. I avoid nested loops like the plague, so for the creation of the map I use a little mathematical trick I conjured up myself.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;I take the x, and y coordinates and transform them into an index into a grid. The index counts left to right from the top, left tile to the bottom right. All you need to know is the width of the grid and you can calculate what the index is for a given x and y value. You can do the same with the index but it's definitely odd to see in the code.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;For instance in a 3x3 grid the index of the last element or position (2, 2) in the grid is given by&lt;/div&gt;&lt;div style="text-align: justify;"&gt;i = y * cols + x&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;i = 2 * 3 + 2&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;i = 8 (qed)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Meaning that you count up starting from 0, 1, 2, ..., 7, 8, and for a 3x3 grid you get 9 indexes as you should.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So now to reverse this craziness. This is where we have the i value say for a 3x3 grid the i value is 4. Where on the grid x,y might i fall if we were to count starting with 0 from the first box on the grid and go left to right till we got to 4. We need to calculate y first as it will be used to calculate x.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;y = i / cols&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;y = 4 / 3&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The trick here is that the result is truncated. So&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;y = 1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;More mathematically correct is the following formula for y.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;y = floor(4/3)&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In code if we use integers the result of the division will automatically be truncated. Now to the confusing part finding x.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;x = i - y * cols;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;x = 4 - 1 * 3&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;x = 1&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So in a 3x3 grid where x and y start go from 0 to 2 each, index 4 is the point 1,1 or the second row second column.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;pre&gt;+-x 0   1   2
y .---.---.---.
0 | 0 | 1 | 2 |
  |---|---|---|
1 | 3 | 4 | 5 |
  |---|---|---|
2 | 6 | 7 | 8 |
  '---^---^---'&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As you can see the math does work out, provided we use the floor function in our calculations, in code we just have to use integers. This can be useful for representing a grid using a Map of integers to tiles where the integer key is the index in the grid.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;There are quite a few different ways to use this for our drawing purposes as well as converting between coordinate systems, i.e. mouse position to grid position.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;O.K! So now that I've managed to completely confuse you here is the code.&lt;/div&gt;&lt;ul&gt;&lt;li style="text-align: justify;"&gt;&lt;a href="https://sites.google.com/site/morbidmorvick/BasicTilemapRendering.java?attredirects=0&amp;amp;d=1"&gt;BasicTilemapRendering.java&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-818970398514584684?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Dsi8nSJNr6T-4ht4XZglF2FYVew/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dsi8nSJNr6T-4ht4XZglF2FYVew/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Dsi8nSJNr6T-4ht4XZglF2FYVew/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dsi8nSJNr6T-4ht4XZglF2FYVew/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/iYQ_h6Wog4E" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2010/11/rendering-basic-tiled-maps.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/818970398514584684?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/818970398514584684?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/iYQ_h6Wog4E/rendering-basic-tiled-maps.html" title="Rendering Basic Tiled Maps" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_eLO9nXo-B1k/TNlSQBPVJeI/AAAAAAAAAJA/IjEVtgupXtw/s72-c/AutoGeneratedMap.jpg" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2010/11/rendering-basic-tiled-maps.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AFRH07eSp7ImA9Wx5bEko.&quot;"><id>tag:blogger.com,1999:blog-2204332218642508435.post-754296767761896758</id><published>2010-10-28T09:15:00.000-04:00</published><updated>2010-10-28T09:15:15.301-04:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-28T09:15:15.301-04:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Side Projects" /><category scheme="http://www.blogger.com/atom/ns#" term="Dwarf Fortress" /><category scheme="http://www.blogger.com/atom/ns#" term="Game Programming" /><category scheme="http://www.blogger.com/atom/ns#" term="Perlin Noise" /><category scheme="http://www.blogger.com/atom/ns#" term="Minecraft" /><category scheme="http://www.blogger.com/atom/ns#" term="Heightmap" /><category scheme="http://www.blogger.com/atom/ns#" term="Map Generation" /><category scheme="http://www.blogger.com/atom/ns#" term="Infinite world" /><title>Morning Coffee: Fun Projects</title><content type="html">&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_eLO9nXo-B1k/TMlkg6RyliI/AAAAAAAAAHo/JEBwfLm7Zsg/s1600/screenshot.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="243" src="http://4.bp.blogspot.com/_eLO9nXo-B1k/TMlkg6RyliI/AAAAAAAAAHo/JEBwfLm7Zsg/s320/screenshot.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Screen capture of a 230x130 section of the heightmap below. &lt;br /&gt;
the 126,161 blocks are instanced using a single opengl VBO&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Just thought I would share some of the personal projects I have been dabbling with these days. I just started looking at the game &lt;a href="http://www.minecraft.net/"&gt;Minecraft&lt;/a&gt;, and &lt;a href="http://www.bay12games.com/dwarves/"&gt;Dwarf Fortress&lt;/a&gt;. Some of you are probably wondering "where have you been". Well DF (Dwarf Fortress) was started during my college years and probably didn't gain popularity and stability in the game till I graduated so theres that, and Minecraft is a recent development and quiet popular. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;They are very interesting concepts and my mind has been spinning since I was introduced to them by a guy at work. So my project is to make my own game based off these two games. I have always liked the idea of an infinite gameplay world where the player can build pretty much anything they want and create a completely unique experience for themselves. Basing things off a simple set of blocks seems like the easiest way to go. I could just play DF and Minecraft but there are too many things I know I would like to have or different ways I would have done things as it is with most games I play. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Oh that and the fact I am pretty broke atm, too many bills to speak of, darn economy. So paying for Minecraft didn't sound good at this point though I will probably give it a try when I have that extra $15. I have started playing DF but I'm afraid the game is really involved and will take me a while to get into it. I am slowly beginning to learn how to play. So I decided I'd start by using JOGL (hehehe).&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: justify;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_eLO9nXo-B1k/TMlkh6uGfCI/AAAAAAAAAHk/bY1qp5LwMLo/s1600/heightmap.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="215" src="http://4.bp.blogspot.com/_eLO9nXo-B1k/TMlkh6uGfCI/AAAAAAAAAHk/bY1qp5LwMLo/s320/heightmap.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;634x427 Procedurally generated heightmap using perlin noise. &lt;br /&gt;
4 octaves and 0.205 persistence&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;I ran into some issues with the Depth Buffer not working correctly. I basically took a simple cube example from &lt;a href="http://nehe.gamedev.net/"&gt;Nehe&lt;/a&gt; and fixed it up a bit. It was &lt;a href="http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05"&gt;Lesson 05&lt;/a&gt; and I had to fix up the code a little bit because of the changes to JOGL for the most recent aggregated build. And I used a perlin noise generator I wrote based off of pseudo code from an &lt;a href="http://freespace.virgin.net/hugo.elias/models/m_perlin.htm"&gt;article on perlin noise&lt;/a&gt;. So the image above is the generated world, with only a small 250x130 section of the heightmap generating 842,456 blocks, and further reduced to only about 126,161 being drawn. Performance is pretty bad right now because I am drawing all 126,161, no fog or visibility culling. But then lighting isn't turned on which is my next task and will probably kill my Nvidia GeForce 8400 GS.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;I also implemented the Quaternion Camera Class from the &lt;a href="http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class"&gt;Nehe Lesson: Quaternion Camera Class&lt;/a&gt;. I had to implement the quaternion of course I was kind of surprised JOGL does not have an implementation for Quaternions. But then it's supposed to simply be Java bindings to opengl. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_eLO9nXo-B1k/TMl2H8l1sWI/AAAAAAAAAIA/AGDfiHTFVXw/s1600/block-terrain-angleview.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="240" src="http://1.bp.blogspot.com/_eLO9nXo-B1k/TMl2H8l1sWI/AAAAAAAAAIA/AGDfiHTFVXw/s320/block-terrain-angleview.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Angled View: All 126,161 also notice the cutout portion at the bottom. &lt;br /&gt;
Apparently the algorithm needs some work, I don't need the blocks &lt;br /&gt;
on the bottom, or on the sides.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Since I have done a couple implementations of terrain generators and various other land, maze generation it wasn't that hard to implement. I hope to provide from useful snippets for procedural map generation soon. Today's post was actually going to be about 2D map/level rendering, but I didn't have the snippet ready so I decided I'd  write about this little side project instead. By next Tuesday I should have a series of snippets on 2D map and level rendering done. My plan is to go over ways to rendering 2D maps and levels drawing only the visible area, showing a really nice way to draw layers, and how to do smooth level scrolling. After that it's on to collision detection algorithms, and then after that I can finally get to the meat and reason for creating this blog and show the really interesting gameplay snippets and talk about the fun part of game programming.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_eLO9nXo-B1k/TMl2GLMeZ3I/AAAAAAAAAIE/3nzAF1g14h8/s1600/block-terrain-sideview.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="240" src="http://1.bp.blogspot.com/_eLO9nXo-B1k/TMl2GLMeZ3I/AAAAAAAAAIE/3nzAF1g14h8/s320/block-terrain-sideview.jpg" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Side-View: The removing the side and bottom layers of blocks &lt;br /&gt;
should reduce the amount of blocks even more&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Ok that's enough rambling for this morning. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2204332218642508435-754296767761896758?l=gpsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tz4ASp9hqy4GHOeYeRa4ZD8HNRk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tz4ASp9hqy4GHOeYeRa4ZD8HNRk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tz4ASp9hqy4GHOeYeRa4ZD8HNRk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tz4ASp9hqy4GHOeYeRa4ZD8HNRk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/GameProgrammingSnippets/~4/ze7smCOjpKY" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://gpsnippets.blogspot.com/2010/10/morning-coffee-fun-projects.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/754296767761896758?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2204332218642508435/posts/default/754296767761896758?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GameProgrammingSnippets/~3/ze7smCOjpKY/morning-coffee-fun-projects.html" title="Morning Coffee: Fun Projects" /><author><name>MorbidMorvick</name><uri>http://www.blogger.com/profile/06998186152717374184</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_eLO9nXo-B1k/TMlkg6RyliI/AAAAAAAAAHo/JEBwfLm7Zsg/s72-c/screenshot.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://gpsnippets.blogspot.com/2010/10/morning-coffee-fun-projects.html</feedburner:origLink></entry></feed>

