Challenge on Pac-Man Game Widget

Posted: May 25th, 2009 under JavaFX Games, pac-man.
Tags: , , ,

Bookmark and Share

During the weekend, JavaFX expert Jim Weaver had laid a challenge on me to create a WidgetFX widget of the Pac-Man Game, a JavaFX demo game that I introduced in insiderRIA.com. The author of WidgetFX, Stephen Chin even offered to show it in JavaOne if I can finished in time(before June 2-3). With about one week to go, I think it is interesting and fun to give it a try. I will keep track of my progress in this post.


I have installed the WidgetFX package before, but to get a clean start, I re-downloaded the source code from Widgetfx.org. Here is my progress: (updated continuously)



May 24:
Downloaded source code from http://code.google.com/p/widgetfx/downloads/list. Clicked on the Launch Dock link on the front page of widgetfx.org and it run successfully on my computer(Windows XP, with JDK 1.6U13). Read some document from project home. Try to look at some WidgetFX samples, but couldn’t find most of the source code. Anyway, it is not bad for the first day.


May 25:
Got Steve’s response with a tutorial on Calendar widget. This tutorial is quite helpful. From that example, I learnt that the widget container is fundamentally a Stage Class. That’s great! We can put everything into an instance of Group and then put the Group into the Widget class. Because in my Pac-Man Game, I only have a Maze instance in the Stage class, this becomes quite simple now. I quickly modified the Calendar example and put my Maze instance into the Widget. After adjusting the width and height, it was just simply working! (see the image on the left)

Further testing showed that I needed to write some code to handle the docking and resizing events. I will read some more documents and find out more details tomorrow.


May 26:

Steve provided some useful hints on how to deal with the resizing of the widget. It looks like the WidgetFX API is quite intelligent on resizing the window. What I need to do is to define default width/height and aspectRatio and everything else will be taken care of. I modified my original Pac-Man code to allow the game to be paused. Now the game is fully working as a widget. When it is docked, the game will be automatically paused. When it is undocked, it zooms to its original size and the player can press ‘P’ button to continue playing. Click on the below button to see how the Pac-Man widget looks like:


Pac-Man Widget (JavaFX 1.1)


or try widget for WidgetFX 1.2 version

Pac-Man Widget 1.2


Some issues remains: the game is kind of slow on my laptop(single core, 1.6Ghz Intel, WinXP). I am checking with Steve to see if he has any suggestions.



Bookmark and Share

5 Comments

  1. pretty cool, although it is very small in the sidebar. I can barely see the dots. This way it is not that fun :( but anyway, great implementation!

    if you planning on doing games only maybe you should have a look at http://www.interactivemesh.org/ (3D + javafx)

    Although I’m still waiting for the next release of javafx where native 3D support could be expected. Do you know anything about that? (is it possible sometimes soon?)

    Comment by dev567 — May 30, 2009 @ 1:06 pm

  2. Hi, I saw your interesting blog, I just want to report you my JavaFX clone of Crayon Physics game.. I’m still working on it but it’s quite playable right now ;)

    http://theorymatters.wordpress.com/2009/05/28/javafx-crayon-physics/

    regards,
    Claudio

    Comment by Claudio — May 30, 2009 @ 1:30 pm

  3. [...] Articles: Pac-Man Game WidgetFX Widget JavaFX Game Example Code: MineSweeper JavaFX Game Demo Example: [...]

    Pingback by Writing the JavaFX Pac-Man Game Part 3 — May 31, 2009 @ 3:42 am

  4. [...] Games in JavaFX Source of the Pac-Man Game JavaFX Demo Game: MineSweeper JavaFX Demo Game: LinkUP Game Widgets for WidgetFX: Pac-Man My JavaFX Demo Game: [...]

    Pingback by Writing the Pac-Man Game Part 4 — June 6, 2009 @ 7:21 am

  5. [...] before the JavaOne 2009, Jim Weaver asked me to write a widget for my JavaFX Pac-man game. The WidgetFX API was quite simple to use, so I finished it pretty soon. The game widget later got [...]

    Pingback by Pac-Man Widget for JavaFX 1.2 — June 19, 2009 @ 12:38 am

RSS feed for comments on this post.