Writing the JavaFX Pac-Man Game Part 3

The latest JavaFX article of writing the Pac-Man game is published on May 28. It is the third out of a five-article series: “Writing the Pac-Man Game in JavaFX – Part 3“.

In this article, the ghosts are introduced. The animation of the ghosts are almost the same as the Pac-Man character. It is basically moving a CustomNode and switching the images. There are three sets of images for the animation: normal, hollow and flashing. The moving algorithm of the ghosts is the heart of the code. In this article, for simplicity, a random moving algorithm is applied. A more complicated moving behavior of the ghosts will be introduced in Article 5. Click on the below image to try the program so far. The Pac-man and ghosts cannot eat each other even they meet in the maze. The feature of eating each other will be illustrated in next article. As before, you can try this semi-completed program by clicking Java Web Start button below:


Related Articles:

My JavaFX Demo Game: Pac-Man

Articles on Writing the JavaFX Pac-Man Game

Pac-Man Game WidgetFX Widget

JavaFX Game Example Code: MineSweeper

JavaFX Game Demo Example: Pac-Man


Other unrelated links:

Applicant of American Citizenship Information, software and guide.

Guide American Citizenship in United States

Canadian Citizenship Application and Practice Exam

The 2nd Article on Pac-Man Game with JavaFX

The 2nd article of the series, “Writing the Pac-Man Game in JavaFX“, is published today.

The first article introduced a data model in Java and the JavaFX drawing logic of the maze. In the 2nd article, the animation part of the Pac-Man character is detailed. When you are reading, you can click on the java web start links to see the Pac-Man opening and closing mouths, and gradually moving inside the maze. The keyboard handling code is illustrated as well.

Some JavaFX features demostrated in these two articles include:

. shapes
. keyboard handling
. animation timeline
. java code integration
. Transfromation

Hope you can enjoy reading the articles. You can use arrow keys to play a no-ghost version of the game. The Pac-Man character now can move around and gobble dots. Try it by clicking the below screenshot:


click to run

click to run

Related Articles:

Develop Games in JavaFX

My JavaFX Demo Game: Pac-Man

Articles on Writing the JavaFX Pac-Man Game

After the release of JavaFX 1.0, I wrote a Pac-Man game using the JavaFX API. Many people were quite interested in the game. They either enjoyed playing it or asked me for the details fo the JavaFX code. JavaFX expert Jim Weaver invited me to write some articles about the process of building the game. After a few weeks’ hard work, with Jim’s constructive ideas and great help in proofreading, I finished the articles. Now they are published on insideRIA.com, an O’Reilly’s web site, as featured articles. There will be 5 articles in total and they will run through the coming 5 weeks.

In each article, there are a few web start links that you can click on and start a JavaFX program to see how it works. If you follow the 5 articles, you will find out how the game is built bit by bit. I hope the articles can help people who want to learn JavaFX or want to develop games in JavaFX. Thanks Jim for making these articles possible. My thanks also goes to Rich, the editor of insideRIA.com.

Here is the links for the articles:

May 14, 2009:
Writing the Pac-Man Game in JavaFX – Part 1
May 21, 2009:
Writing the Pac-Man Game in JavaFX – Part 2
May 28, 2009:
Writing the Pac-Man Game in JavaFX – Part 3
June 4, 2009:
Writing the Pac-Man Game in JavaFX – Part 4
June 11, 2009:
Writing the Pac-Man Game in JavaFX – Part 5

Related articles:
Answer: Blinky, Pinky, Inky and Clyde from Jim Weaver’s Blog

My JavaFX Demo Game: PACMAN

JavaFX Demo Game: PAC-MAN

A Wish Tree in JavaFX

This is a JavaFX program for my kids, or say it is some fun for everybody. You can make a wish and put it somewhere on a Wish Tree. Hopefully, it will come true some time pretty soon. A star hanging on the tree denotes a wish. For Phase I, I am building this wish tree as a standalone application. In Phase II, I will make an internet version, so that everyone can place wishes on the same tree(s).


Wish tree: http://www.javafxgame.com


When you click on the wish tree, a wish star appears and a dialog is shown to allow you to enter your name and your wish. Later on, if you click on the same star, you have a chance to modify your wish. My daughter likes it very much, she places all kinds of wishes( such as I want a Barbie) on the tree and really hope they will come true soon. Go have some fun by clicking on the below image to place your wishes and good luck! ( JDK1.5+ is required, JDK 1.6 U13+ is better):


Wish tree: http://www.javafxgame.com

click to start JavaFX Wish Tree


The program utilizes the features of JavaFX effect classes. The source code can be downloaded here. I will write a few articles to explain how to create such an application.

The article is also posted at javafxgame.com: JavaFX Wish Tree.

JavaFX Reserved Words and Syntax Highlighter

Recently, when I was writing some articles on JavaFX, I found it necessary to obtain a list of reserved words(keywords) of JavaFX so that I could use them in a syntax highlighter for blogs and web pages. After some search, I found them at openjfx site. Since the keywords may be useful for other purposes, I list them below ( for JavaFX 1.1):

abstract after and as assert at attribute before bind bound break
catch class continue def delete else exclusive extends false finally
first for from function if import indexof in init insert instanceof
into inverse last lazy mixin mod new not null on or override
package postinit private protected public-init public public-read
replace return reverse sizeof static step super then this throw
trigger true try tween typeof var where while with

Here is a sample of the JavaFX syntax highlighter, if you are intersted, check it out here: JavaFX syntax highlighter.

package pacman;
import java.lang.Math;
import pacman.MazeData;
import pacman.PacMan;

/**
 * @author Henry Zhang
 */

public class MoveDecision {

  // x and y of an intended move
  public var x: Number;
  public var y: Number;

  // evaluate if the move is valid and its score if it's valid
  public function evaluate(pacMan:PacMan, isHollow:Boolean): Void {
    if ( x < 1 or y < 1 or y >= MazeData.GRID_SIZE
         or x >= MazeData.GRID_SIZE){
      score = -1;
      return ;
    }
  }
 . . .
}