[EDIT, July 28, 2011: I’m going to retire this effort. I keep coming up with things that I want to restructure or do differently, and the rewrites, while a great learning exercise for me, are a time killer. Besides, there are plenty of other good basic demos on this site!
I still think using a scheduled game loop makes good sense in many instances. If you decide to do so, I recommend the following:
(1) Use a ScheduledThreadPoolExecutor. It supercedes util.Timer.
(2) Consider running a daemon thread with the following looped indefinitely “Thread.sleep(Long.MAX_VALUE);”. With this running (err…sleeping) in the background, the resolution of the scheduling increases from the nearest 15 msec to within 1 msec on the Windows XP operating system.
Thanks, and good luck!]
I’ve made a little program that introduces Java game programming. It doesn’t create a finished, familiar game like Space Invaders. It was written more to present some basic functionality using core Java libraries, such as setting up the outermost frame and adding a JPanel for the animation display, powering a game loop with a Timer, animating a number of objects, making a collision detector, some mouse interaction.
I use the format of embedded comments in the code. I also spend some time pointing out things that were sources of confusion during my first months of learning Java, and provide many links to relevant tutorials.
It would be great to get some comments from more experienced programmers, especially if there is anything I am doing that would “lead someone astray”. And, of course, it would be great to hear suggestions from people who try to learn from it.
How can I best present it for folks to review and comment upon it? I will attach a JAR file that includes source code. But unless one has an IDE, extracting the source files will be a bit of a nuisance. Another suggestion for presentation? The program has six .java files.
Thanks,
Phil Freihofner
[attachment deleted by admin]