Back in November last year I told you that I’d bought a book about Java game programming and that I had grand plans for the future. Since that post it has been awfully quiet and not much has been written on the subject. The main reason is that I turned out to be a pretty crappy game programmer.
From the book, Killer Game Programming in Java, I managed to create a decent framework that handled events, object rendering in Java 2D, frame skipping and other fundamental aspects of a game engine. But the first real hurdle came when I was trying to do something as simple as moving an object from point A to point B on the screen. The object moved all right, but never in a straight line. This is not something that should be hard to implement: Moving an object along a straight line between two points in a coordinate system means moving it along the same coordinates that would be used to draw a straight line between the same two points.
Unfortunately, I suck at computer graphics programming. Thinking back to my time at the university, computer graphics was one of the subjects I just couldn’t get my head around. That’s probably the main reason why I’m usually tinkering in the backend as a professional programmer. But other people have been drawing straight lines on computer screen for ages: Bresenham’s line algorithm is an algorithm which determines which order to form a close approximation to a straight line between two given points. And since I managed to find a Java implementation of the algorithm, my straight line problem was solved.
Solving the straight line issue was a small breakthrough and I’ve now implemented a few other things necessary in a real team strategy game, like multiple select and group movement. The goofy working title on the project is SpaceChase and you can download a JAR version and have a look at the so far. You might get all kinds of warnings from your browser, but everything is perfectly safe. the file is OK. You’ll need Java 7 installed on your computer to get it to work. If you have a public JRE installed, you should be able to simply double click on the downloaded JAR file, if not use “java -jar SpaceChase.jar” to start it.
I’m assuming you know what you’re doing.
The “game” will spawn a 2D “universe” with 45 “ships”, a.k.a “squares”, positioned randomly in a non-resizeable window. Select a ship by left-clicking on it and send it on its way by right-clicking on the destination. Multiple ships can be selected by left-clicking and dragging the selection box around the ships you want to select. Individual ships have no idea that other ships exists, so they will stack on top of each other if you send them to the same location in the universe. They can be unstacked by selecting a single ship (clicking on the stack) and flying that ship to another location in universe.
Future challenges that I have no idea how to solve are, including but far from limited to, acceleration and deceleration, collision detection and hit boxes, zooming in and out and moving the viewport around without rendering anything outside of the viewport.
Now boldly go where no man has gone before.
This post has no feedback yet.
Do you have any thoughts you want to share? A question, maybe? Or is something in this post just plainly wrong? Then please send an e-mail to
vegard at vegard dot net with your input. You can also use any of the other points of contact listed on the About page.