Thursday, October 13, 2011

Pac-Man in JavaFX 2

JavaFX 2 Beta was FINALLY released for Mac OS X. I thought I would learn it by porting one of my favorite JavaFX 1 games: Pac-Man! The original code was written by Henry Zhang. He wrote a five-part series of articles (Part 1, Part 2, Part 3, Part 4, Part 5) explaining the design of the game. He also wrote a neat widget for the game.

I ported the original JavaFX 1 code to JavaFX 2 using the Java SE bundle of Netbeans 7.1 Beta on my MacBook. If you want to play the game on a Mac you can install the SDK and samples, download my JAR file, and place it in your samples folder. Double-click the pacman.jar file from within the javafx-samples-2.0 folder to launch the game. Make sure you install the samples according to the instructions here.

If you are on Windows, you will need to have Java SE 6 Update 26 or later and the JavaFX 2 runtime installed. If everything is installed correctly, you can click here to launch Pac-Man in Java Web Start. Or you can play in the applet below. If JavaFX 2 is not installed correctly, you will see an image asking you to install JavaFX rather than a working applet.


I can post the source code here or put it on GitHub if anyone is interested. Right now, the code is a bit messy. It still has all of Henry Zhang's original JavaFX 1 code commented-out inline with the new JavaFX 2 code. Enjoy the game!


13 comments:

  1. Nice job!! I would like to see the sources. Thank you.

    ReplyDelete
  2. Nice work.

    Any particular reason why you link to jnlp file directly and not using dtjava? E.g. like it is
    described here:
    http://download.oracle.com/javafx/2.0/deployment/deployment_toolkit.htm#sthref46

    ReplyDelete
  3. @Anonymous:
    All deployment code was automatically generated by NetBeans into the dist/ directory of the project. I simply copied the HTML from the automatically generated files.

    Thanks for the link. I'll play around with having the JavaScript handle the click to see if it works better.

    ReplyDelete
  4. I doing code this game in javafx 2.0, and i have some problem in convert code from javafx 1 to javafx 2. So can you email for me to exchange about this work ? my email: congngale@gmail.com

    ReplyDelete
  5. I have some trouble in javafx 2.0, so can you send me your source code, thanks congale@gmail.com

    ReplyDelete
  6. I'm having trouble installing JavaFX for OSX... actually I wouldn't know where to begin. The downloadable file contains a bunch of dylib/jnilib, where do I put them? The Oracle webstate just states "unzip to your filesystem" as instructions, but obviously that's not much of a help.

    Can someone please help me?

    ReplyDelete
  7. I would like to have a copy of the source code for review. You can send it in my email, gjbalan12@yahoo.com. Thanks.

    ReplyDelete
  8. Hey, very nice work. i am actually expertimenting with javafx2, and it would be a great help to see your source code. can you communicate it?

    ReplyDelete
  9. Can you send me the sourcecode?

    rossmann.dominik@yahoo.com

    ReplyDelete