Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 3835 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.

Thanks,

Phil Freihofner

[attachment deleted by admin]

"It's after the end of the world! Don't you know that yet?"
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.

"It's after the end of the world! Don't you know that yet?"
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:
http://www.hexara.com/GameTutorial.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.

"It's after the end of the world! Don't you know that yet?"
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (30 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!