Activate your free membership today | Log-in

Wednesday, May 7th, 2008

Wii Darts: Powering Ajax applications with Wii controllers

Category: Java, Showcase, Games, Presentation

Ben and I gave a presentation at JavaOne on what’s new with Ajax. Since this was JavaOne, we skewed a little more than we normally would to Java topics, and one of them was using the new Java Plugin, that has great new features such as being able to take a running applet out of the web page, and having it continue to live after shutting down the browser. Java is running out of process here, which also helps the “Java crashing the entire browser” problem.

Anyway, back to our demo. For some context, last year at JavaOne had us performing Guitar Hero on stage, so we knew that we had to use a gaming console in some way. This year it had to be the Wii, but instead of using the console, we decided to just use the controllers.

Wouldn’t it be cool to control a Web page using the controllers? We thought so, and we set to it. You can talk to the Wiimotes via Bluetooth, so we needed a stack that would allow us to do just that. Java has a bluetooth stack. We could get an applet to talk to the Java stack. Hmm.

It actually took quite some time to test out the various stacks out there. In the end we went with a native system called Wiiuse that a lot of Wii hackers use. There is a wrapper library called Wiiusej that gave us exactly what we needed.

A quick test later and we had an application that was talking between the remote and the program. It turns out that the main controller sees a series of IR lights that are in the Wii sensor bar, and this allows you to simulate the system with any decent IR source. In the presentation room the big lights that shine on stage were strong enough to act as a sensor bar so we won’t even have to use it. We can just point out to the crowd.

Anyway, back to the application. We then wrote a Java class that acts as a state machine for what the remote is doing. It understands the movements, which buttons are pushed, how fast you are moving the device. With this data we could build a simple darts game. With the state machine Java code, and an Applet wrapper that exposed the information, we were ready to get to the Ajax side of the house.

We painted a darts board onto the screen and then had JavaScript start polling the Applet for information via JSObject (As simple as: document.nameofapplet.pollmethod()). This turned out to be more stable than talking the other way, even though it meant we were polling instead of being entirely event driven. When the JavaScript code polled the applet it would pass back a data structure with the data for the coordinates of the remote, and whether the dart had been fired (button A to fire, button B to reload). We would move the dart image on the screen as you move the remote, and when fired we kicked off an animation to fire the dart at the board.

At first, it was all too simple. You setup the shot and it would get the right area every time. Not a fun game. We then decided to add some simple physics to the Ajax game. We took into account the velocity of the throw (if weak it would fall down) and how straight your shot was. If you wiggle around, the dart will not be accurate.

Anyway, this was a lot of fun, and shows that as much as we mock Java applets, if we forget about using them as fancy blink tags, and instead think of them as more extension points, maybe there is life for them.

The video below shows you a demo of the application, the source code with an explanation, and more details.


Posted by Dion Almaer at 6:08 pm
7 Comments

++++-
4.5 rating from 19 votes

Friday, May 2nd, 2008

XSketch: Pictionary with GWT

Category: Fun, Games, GWT

XSketch

XSketch is “a multiplayer word sketch game. It is programmed in Adobe Flash, Java, Ajax, and GWT. Gameplay is similar to Pictionary where you sketch a picture with the goal of having other players guess your word and vice versa.”

Ryan Dewsbury creator this game, which he adds to his collection of GPokr and KDice.

This one is particularly addicting!

Posted by Dion Almaer at 10:14 am
2 Comments

+++--
3.5 rating from 6 votes

Monday, April 28th, 2008

Java in JavaScript

Category: JavaScript, Java, Games

As John Resig reports, the Japanese Shibuja.JS user group managed to port (at least in parts) the Java Virtual Machine over to JavaScript. The project is called Orto and there is a Japanese PDF explaining the details (I guess) available on John's site.

Using this you can convert Java code into bytecode and embed it in the document.

JAVASCRIPT:
  1.  
  2. "java/lang/Thread 1316742099":function(){var orto333=orto245[0];
  3. var orto336=orto350(orto333);
  4. if(orto336.orto340!=orto310){orto223("java/lang/IllegalThreadStateException",null);
  5. return ;
  6. }
  7.  

One of the examples shown is a pretty cool Tetris game:

Screenshot of Xetris - a Java Tetris in JavaScript

As Orto simulates the multithreaded nature of Java with yields and timeouts this is of course hard-core simulation (read: hack), but the benefit are that you could Java Games on non-JS devices, like the iPhone.

Orto also seems to try to simulate the Java UI conventions, thus making it easy to convert existing applications (to a certain degree as there is no equivalent in HTML for the richness of Java UIs unless you build them yourself as libraries ike Dojo or Quoxdoo did).

More details are available on John Resig's Blog

Posted by Chris Heilmann at 1:26 am
5 Comments

+++--
3.7 rating from 13 votes

Monday, April 21st, 2008

ProtoRPG: Role Playing with Prototype

Category: JavaScript, Prototype, Games, Scriptaculous

Sometimes you want Monday to be a Friday, so we have ProtoRPG, a role playing game written by Pierre Chassaing in JavaScript using Prototype and Script.aculo.us.

Walk around, add to your inventory, and feel like you are playing your first RPG many moons ago, on a Friday.

Proto RPG

Posted by Dion Almaer at 7:32 am
1 Comment

++++-
4.3 rating from 6 votes

Wednesday, April 9th, 2008

Super Mario; 14KB of JavaScript

Category: JavaScript, Fun, Games, Canvas

Jacob Seidelin is doing great work, and for something fun, he build a piece of Super Mario in just 14KB of JavaScript:

Here's an experiment in keepings things small and confined to one Javascript file. There are no external image files or anything, everything is rendered with Javascript using either canvas elements or old fashioned div-making tactics (for IE). The sprites are stored in custom encoded strings in a format that only allows 4 colors for each sprite but in turn only takes up around 40-60 bytes per sprite.

We also have MIDI music embedded as base64-encoded data: URI's. No music for IE, though, and it seems all the other browsers each have different, minor problems with it, but it sort of works.

Posted by Dion Almaer at 12:39 am
15 Comments

+++++
2.754661662493E+48 rating from 116 votes

Friday, March 21st, 2008

Snake

Category: JavaScript, Fun, Games

Snake

Andreas Kalsch has created a simple version of Snake in JavaScript that eats your feeds instead of food.

The first time I ever played snake was on a BBC Micro. I was small.

Posted by Dion Almaer at 7:55 am
4 Comments

+++--
3.9 rating from 12 votes

Thursday, January 24th, 2008

The Art and Science of JavaScript Games

Category: Articles, Games

James Edwards has written a very detailed tutorial on using dhtml to create a game which is part of his book:

In this chapter, we took the languages of CSS and JavaScript well beyond the tasks for which they were intended?the presentation and basic behavior of HTML documents -- and used them to create an interactive 3D maze.

First, we looked at the basic principles by which triangles can be displayed using only CSS. We then extended that concept to render a perspective view, creating the illusion of three dimensions. Next, we established a convention for specifying floor plan data, and for dynamically translating that data into a perspective view. By adding listeners for user events, we successfully created an interactive maze that can be completely customized and extended. To top things off, we added some usability aids, such as a top-down map, and accessibility aids including keyboard navigation and captions.

While I haven't delved into the details of every method that comprises the game script (there are plenty of comments, so I'll leave that for you to pursue in your own time), I hope this chapter has convinced you to look at JavaScript in a new light. The possibilities really are only limited by your imagination!

Wowser :)

Posted by Dion Almaer at 6:04 am
11 Comments

++++-
4.2 rating from 20 votes

Friday, December 21st, 2007

Wii Opera SDK

Category: Games

Daniel Gump has created a set of wrapper classes to form an SDK for Opera on the Wii which covers different ground compared to the Wii Remote API that we posted about

Classes:

  1. Comm - Allows communication between players online
  2. Drawing - Plot polygons and images to a drawing canvas
  3. ThreeD - 3D matrix math for polygons and hidden surfaces (General)
  4. ThreeD - 3D matrix math for polygons and hidden surfaces (FPS optimized)
  5. Wiimote - Wii Remote input and motion interpretation

Now I can finally build "The Wee Game" that I have been promising myself.

Posted by Dion Almaer at 7:08 am
5 Comments

++++-
4.5 rating from 25 votes

Friday, November 16th, 2007

Silverlight Minesweeper

Category: Games, Microsoft

Game Friday is here, and it was time to showcase a Silverlight one. This time we have a Silverlight 1.1 version of Minesweeper, with full source code to check out.

Where is Silver Scrabulous?

Posted by Dion Almaer at 2:12 am
9 Comments

++---
2.2 rating from 38 votes

Friday, November 9th, 2007

Protoscripty Same Game

Category: Prototype, Games, Scriptaculous

Gary Haran wanted to see how well the latest versions of Prototype and Script.aculo.us worked, so he created a game, Same Name.

The 179 lines of JavaScript has fun with animations and sound.

Same Game

Posted by Dion Almaer at 4:50 pm
Comment here

++++-
4.1 rating from 36 votes

Monday, October 15th, 2007

KDice - GWT-based strategy game

Category: Ajax, Fun, Games, GWT

Ryan Dewsbury, creator of gpokr is no stranger to Ajaxian as we did a writeup about his Ajax poker app last year. Ryan has since released another Ajax-based game called Kdice. Kdice is an online strategy game built using the Google Web Toolkit.

The goal of the KDice is to win all territories. At the end of each turn the number of new dice randomly distributed is based on the largest number connected territories for that player.

I've never played Kdice but considering that there are over 30,000 registered players on the site, this game must be a blast!

Posted by Rey Bango at 7:30 am
3 Comments

++++-
4.2 rating from 21 votes

Tuesday, October 2nd, 2007

Dojo GFX Game using SVG/VML rendering

Category: Dojo, Games

Paolo Ardoino has created a fun little web game called Be Quick Or Be Dead:

Game rendering is very simple:

  • ctx = dojox.gfx.createSurface creates 2D drawing surface
  • images, text, rectangles, … are all shapes that can be created on that surface (i.e. img = ctx.createImage(); )
  • shapes could be modified with setShape method (i.e. img.setShape(newShape); )

I hope you will enjoy Be Quick Or Be Dead, because I’m planning to code a multiplayer version :D

Be Quick Or Be Dead

Posted by Dion Almaer at 7:31 am
15 Comments

++---
2.5 rating from 33 votes

Friday, August 24th, 2007

Amazing Ajax Solitaire

Category: Showcase, Fun, Games, Yahoo!, Framework

In the "I-can't-believe-it's-not-Flash" category, Robert Schultz pointed us to his amazing World of Solitaire website, implemented with YUI, MochiKit and PlotKit:

Amazing Ajax Solitaire

It's hard to single out a favorite feature, from it's ability to rescale the size of the cards when you resize the browser window to its impressive animations and smooth drag-and-drop. Definitely worth a look!

Robert gave an interview to the YUI blog that discusses implementation details.

Posted by Ben Galbraith at 10:29 am
15 Comments

+++--
3.2 rating from 121 votes

Friday, August 17th, 2007

Empires: Ajax Axis and Allies

Category: Games

Bryan Brunton has created Empires, a game of expansion and conflict set in an alternate history prior to World War II. You and your opponents are leaders of the most powerful nations in the world. Empires was based upon the board games Attack! and Axis and Allies.

Dojo, DWR, and JavaServer Faces are the weapons of choice.

Ajax Risk

Posted by Dion Almaer at 10:05 am
9 Comments

+++--
3.1 rating from 24 votes

Monday, August 6th, 2007

The Wii Remote API: Now your userbase is four.

Category: Games, Opera

The Opera folk have released an API that allows you, the developer, to be able to monitor all of the remotes that are connected with The Wii Remote API.

This means that you can watch up to four people buzzing around the screen:

Polling the status of a remote

The Wii Remote data is accessed through the opera.wiiremote object. This object offers a single method opera.wiiremote.update(n) which is used to obtain the status of an individual Wii Remote. The method expects a single parameter; the Wii Remote number. The number is zero-based, so it starts at 0 for the first remote, and ends at 3 for the fourth remote. The method returns a KpadStatus object, which has several properties that give information about the remote.

This update method can be called as often as is needed to obtain a fluid response, but note that the Wii is not as powerful as most desktop computers, so it is important to make sure that it is polled only as often as the script that uses that data can process it. For example, if a script uses the Wii Remote status to update the display of a canvas element, and that update will take perhaps 50 ms to update in Opera on a desktop computer, it may take over 100 ms on a Wii. Attempting to use a polling interval of less than 100 ms will cause the response to appear very sluggish.

Note that the opera.wiiremote object only exists in Opera on Wii, so it is important to check for its existence, as well as the existence of the opera object, before attempting to use it.

Examples

JAVASCRIPT:
  1.  
  2. //Obtaining the roll of the third Wii remote in degrees
  3.  
  4. var remote, roll = 0;
  5. //check if the browser provides access to the Wii Remote data
  6. if( window.opera && opera.wiiremote ) {
  7.   //get the KpadStatus object for the third Wii Remote
  8.   remote = opera.wiiremote.update(2);
  9.   //check that the remote is enabled
  10.   if( remote.isEnabled ) {
  11.     //get the roll angle in radians
  12.     roll = Math.atan2( remote.dpdRollY, remote.dpdRollX );
  13.     //convert the roll to degrees
  14.     roll = roll * ( 180 / Math.PI );
  15.   }
  16. }
  17.  
  18. // Checking what buttons are pressed on the second remote
  19. var remote, buttons = {};
  20. //check if the browser provides access to the Wii Remote data
  21. if( window.opera && opera.wiiremote ) {
  22.   //get the KpadStatus object for the third Wii Remote
  23.   remote = opera.wiiremote.update(1);
  24.   //check that the remote is enabled
  25.   if( remote.isEnabled ) {
  26.     //use the bitwise AND operator to compare against the bitmasks
  27.     buttons.pressedLeft = remote.hold & 1;
  28.     buttons.pressedRight = remote.hold & 2;
  29.     buttons.pressedDown = remote.hold & 4;
  30.     buttons.pressedUp = remote.hold & 8;
  31.     buttons.pressedPlus = remote.hold & 16;
  32.     buttons.pressed2 = remote.hold & 256;
  33.     buttons.pressed1 = remote.hold & 512;
  34.     buttons.pressedB = remote.hold & 1024;
  35.     buttons.pressedA = remote.hold & 2048;
  36.     buttons.pressedMinus = remote.hold & 4096;
  37.     buttons.pressedZ = remote.hold & 8192;
  38.     buttons.pressedC = remote.hold & 16384;
  39.   }
  40. }
  41.  

There are a bunch of demonstrations, including a simple game.

I can't wait to see the Star Wars light sabre web game... and then see a Comet based app that grows beyond the four connected devices!

Posted by Dion Almaer at 6:15 pm
13 Comments

++++-
4.6 rating from 21 votes

Tuesday, July 31st, 2007

iPhone Arkanoid

Category: Games, iPhone

Scott Schiller has updated his dHTML Arkanoid game to work on the iPhone.

Although the mouse events meant that the game wouldn't work as-is, Scott added an extra div if the browser is an iPhone, and it handles click events.

JAVASCRIPT:
  1.  
  2. if (isIphone) {
  3.     this.iphoneTarget = document.createElement('div');
  4.     this.iphoneTarget.href = '#';
  5.     this.iphoneTarget.id = 'iphoneTarget';
  6.     this.iphoneTarget.onclick = mmH;
  7.     arkanoidBody.appendChild(this.iphoneTarget);
  8. }
  9.  

DHTML Arkanoid

Posted by Dion Almaer at 5:47 am
8 Comments

+----
1.3 rating from 182 votes

Next Page »