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.