Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (731)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (798)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  in progress tutorial for newcomers to Java or to game programming  (Read 4671 times)
0 Members and 1 Guest are viewing this topic.
Offline philfrei
« Posted 2010-12-08 01:42:52 »

[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.


Phil Freihofner

[attachment deleted by admin]

music and music apps:
Offline Gudradain
« Reply #1 - Posted 2010-12-10 05:58:32 »

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.

Hello, first I usually don't open random jar file (because of security, because of the trouble, etc.) So maybe you should try to make your demo available as an applet or as java webstart.

For the source code, I usually prefer reading it directly on the web page. But you have 6 java files so it's kinda big to be all on the forum. My suggestion would be to present the essential part of your program on the web site and giving the full source code as an attachment.

I read your code. It's very different than the structure I use for making my game but I guess it work too. Can't say which one is better. One thing I can't complain about are the comment; yes you have commented your code! But to make it quicker to read on the forum, you should just put the code unless the comment are essential to understand what a part of the code does. Most of us can understand what code does just by seeing it. Another suggestion is to write your comment as Javadoc comment. IDE like netbeans and eclipse will be able to recognize them and provide quicker feedback to the reader about what your code is doing. You can also produce html javadoc of your code with a few click.

Btw your code is clear. Good job. I often see code that make me want to stop reading it after the first few line because it's too awful.
Offline philfrei
« Reply #2 - Posted 2010-12-10 21:56:11 »

Thank you so much!

Yes, it is very much "over-commented"--I never write code with this much in the way of comments. My idea in this case was to explain the code for a relative beginner with Java. But you have given  me some good ideas. Perhaps I will turn the six files into a single document, structured more like a text document for reading, then supply a copy of the working program as well with a more normal commenting style.

You've got me thinking--I hope to have time to do the changes next week.

I think the idea of "registering subscribers" (using the Observer pattern) to a Timer for animation is different than the way most people handle the game loop. But it offers a certain steadiness of refreshes, and is very OOP in how it interacts with the rest of the program. NOT that that is always a good thing--sometimes design patterns are more trouble than the benefits.

music and music apps:
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dah01

Junior Devvie

Medals: 7

« Reply #3 - Posted 2011-03-07 03:36:20 »

Does anyone still have this code?
Offline philfrei
« Reply #4 - Posted 2011-03-07 07:22:07 »

Hi -

Well, I did a little more work on this little demo/tutorial, but came to realize a few things, and put it on back burner.

If you want to take a look, feel free to download this jar:
Once you download it, it should be runnable. Requires Java 1.6.

I assume you know how to import into Eclipse or to rename as a ZIP if you want to get at the .java files to see the code. Feel free to copy.

I stripped out most of the comments, with the idea of redoing the project as an article. But I haven't written the article! So aside from a couple of pockets of areas that remain "over-commented" most of the comments are gone. Hopefully the code is simple enough that it is still useful for code reading and seeing some simple functions in action. I would say this is most appropriate for someone who is in the process of learning Java (already knows some Java) and is trying to get oriented in writing a simple 2D game.

Basically, it does animation on a JPanel via a Timer. It shows some simple interaction with a Mouse (one can click and drag the spheres), and simple, brute force collision detection. There's now some background animation (a "star field" that twinkles) where the stars are drawn pixel by pixel using BufferedImage. So that might be interesting as well.

I'm happy to answer any questions about the code as best as I can.

music and music apps:
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Archive (336 views)
2017-04-27 17:45:51

buddyBro (534 views)
2017-04-05 03:38:00

CopyableCougar4 (977 views)
2017-03-24 15:39:42

theagentd (1011 views)
2017-03-24 15:32:08

Rule (991 views)
2017-03-19 12:43:22

Rule (972 views)
2017-03-19 12:42:17

Rule (968 views)
2017-03-19 12:36:21

theagentd (1069 views)
2017-03-16 05:07:07

theagentd (990 views)
2017-03-15 22:37:06

theagentd (759 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!