AuthorTopic: a new, better wiimote flash api in just 24 hours!  (Read 9555 times)

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

a new, better wiimote flash api in just 24 hours!

on: April 01, 2007, 10:27:59 pm
I'm copy-pasting this from TIGF cuz i'm lazy!

Hey guys!  I wanted to show you my new project, and maybe have some people beta test it for free?  This stuff is always browser-sensitive, so I want to make sure I have this junk workin right.  Also, I am not really a flash or javascript guru, I just do what I can to get stuff to work!  Ok, here we go!

MarioToo is a WiiMote API, like the one that seems so popular over at Wiicade, only I'm not squirreling away all my javascript, and I think I've got a much more redundant implementation anyways.  My API, like Wiicade's, is based heavily off of Mario Klingemann's demo from I think December.  Unlike Wiicade, he also made the javascript available for download, and I spent most of last night reengineering it to get the kinks out and make it easier for people to work with.  The result is 'MarioToo', what I hope will become the standard for great Wii Flash games to come!  The best part is its very easy to use, and you can deploy it on ANY website, not just wiicade's ad-fest!

MarioToo is very, very easy to use if you know any flash at all.  It includes a full-featured javascript library that handles all of the HTML and reflector hacks for you; all you have to do is plug it into your flash game, and include my javascript library and flash reflector on your website.  Here is the example site I am currently hosting:

http://www.lastchancemedia.com/mariotoo/

This is a flash file running at 720x480, and all it does is echo button presses, very simple.  It also demonstrates the smart 'classic' mode and the PC-friendly keyboard bindings a la Wiicade's closed library.  Heavy redundancy and a better javascript setup mean I can handle upwards of 7 or 8 simultaneous button presses with no missed events to screw up your game state.  Here is the HTML for that webpage:

Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 strict//EN">
<html>
    <head>
        <title>MarioToo: A WiiMote Flash API</title>
        <script type="text/javascript" src="wiimote.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            CreateHTML('MarioToo_Demo.swf',720,480,'#FFFFFF','#CCCCCC');
        </script>
    </body>
</html>

Very very simple as you can see.  The CreateHTML call does all the heavy lifting for you, setting up and hiding the reflector, bla bla bla.  It takes params for the flash file URL, width, height, page color, and flash background color.  Moving on, here is all the code from the demo actionscript:

Code: [Select]
// MarioToo Wii Flash API Demo
//
// Version 1.0
// Author: Adam Saltsman <adam@lastchancemedia.com>
//
// A simple app to show how the MarioToo WiiMote API functions.

import mx.core.UIObject;
import com.lastchance.mariotoo.WiiMote;

class com.lastchance.mariotoo.MarioToo_Demo extends UIObject
{
var status:TextField;
var txtfmt:TextFormat;
function MarioToo_Demo()
{
WiiMote.init(); //initialize the wiimote
WiiMote.setClassic(true); //rotate the d-pad on the wii
WiiMote.bindDefaults(); //arrow keys, z, x, shift + ctrl
WiiMote.bind(WiiMote.BUTTON_A,65); //the 'a' key on the keyboard

txtfmt = new TextFormat();
txtfmt.size = 72;
txtfmt.color = 0xffffff;
txtfmt.align = "center";

createTextField("status", getNextHighestDepth(), 0, 200, 720, 100);
status.multiline = false;
status.selectable = false;
status.text = "";
}
function draw()
{
        if(!this.onEnterFrame)
            this.onEnterFrame = this.updateImage;
    }
function updateImage()
{
status.text = "";
if(WiiMote.isDown(WiiMote.BUTTON_A))
status.text = "A";
if(WiiMote.isDown(WiiMote.BUTTON_B))
status.text += " B";
if(WiiMote.isDown(WiiMote.BUTTON_1))
status.text += " 1";
if(WiiMote.isDown(WiiMote.BUTTON_2))
status.text += " 2";
if(WiiMote.isDown(WiiMote.BUTTON_PLUS))
status.text += " +";
if(WiiMote.isDown(WiiMote.BUTTON_MINUS))
status.text += " -";
if(WiiMote.isDown(WiiMote.BUTTON_UP))
status.text += " ^";
if(WiiMote.isDown(WiiMote.BUTTON_DOWN))
status.text += " v";
if(WiiMote.isDown(WiiMote.BUTTON_LEFT))
status.text += " <";
if(WiiMote.isDown(WiiMote.BUTTON_RIGHT))
status.text += " >";
if(status.text != "")
status.setTextFormat(txtfmt);
}
}

Again, very very straightforward stuff.  Nice and state-based, and the keyboard bindings mask themselves as regular wiimote buttons.  The 'classic' mode, which tilts the d-pad for NES-style play, is automatically avoided if you are using a keyboard, so no multi-config setups for different browsers, etc etc.

Finally, here is the download for the beta version 1.0:

http://www.lastchancemedia.com/mariotoo/MarioToo_b10.rar

It includes all the actionscript, javascript, compiled .swfs, and all that junk.  To get it to run on YOUR site, all you have to do is make sure you include the WiiBounce.swf and wiimote.js files in the same directory as your HTML.  Then, call CreateHTML to have wiimote.js write out your flash containers for you!  If you want to use the wiimote API in your flash file, just make sure you import wiimote.as.  A final note, all flash files were compiled using free, open source software: mtasc and swfmill.  Special thanks to those guys for making projects like this possible!

I think that's about it!  I'm always open to hearing about new features people would like, but I don't want this thing to get too bloated.  If you find bugs please let me know ASAP and I will fix them if the wii browser lets me :)

Thanks!
« Last Edit: April 02, 2007, 09:48:26 pm by AdamAtomic »

Offline willfaulds

  • 0010
  • *
  • Posts: 217
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #1 on: April 02, 2007, 04:01:41 pm
adam, awesome! I'll look in more detail later but it worked on my wii.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #2 on: April 02, 2007, 04:47:52 pm
sweeet - I updated the links above but I've made at least a semi-proper home for it here:

http://www.lastchancemedia.com/mariotoo/

Thanks!

EDIT - updated the javascript a little bit to have better support for PC-side javascript detection, new version is available here:

http://www.lastchancemedia.com/mariotoo/MarioToo_b11.rar
« Last Edit: April 02, 2007, 06:43:01 pm by AdamAtomic »

Offline willfaulds

  • 0010
  • *
  • Posts: 217
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #3 on: April 02, 2007, 07:00:40 pm
excellent.

One minor problem i'm running the latest Mac OS X and Firefox for some reason your flash doesn't seem to pickup the CTRL key...

I don't know if you'd be interested but do you fancy trying to collab on a wii game?

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #4 on: April 02, 2007, 07:13:47 pm
hmmmm that's weird...i'm using the flash symbol Key.CONTROL for that, i have no idea why that wouldn't be working correctly, I am kind of a newb to flash!  any mac Flash experts out there have any insight?  also collabs are always interesting to me :D  PM or IM me your thoughts!

Offline snake

  • 0010
  • *
  • Posts: 314
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #5 on: April 02, 2007, 07:16:10 pm
If I had the slightest knowledge of how to program in Flash I'd be all over this.

Offline AdamAtomic

  • 0100
  • ***
  • Posts: 1188
  • Karma: +0/-0
  • natural born medic
    • View Profile
    • Adam Atomic

Re: a new, better wiimote flash api in just 24 hours!

Reply #6 on: April 02, 2007, 07:25:05 pm
I felt much the same way til a month or two ago - flash is basically javascript, its a total joke if you've ever programmed anything before.  You can even compile stuff for free using:

http://www.mtasc.org/ (an amazing opensource compiler)

and

http://swfmill.org/ (a not entirely amazing but generally decent asset thingy)

I used those two apps to build the demo in less than a day and this game for a client in less than a week (with no prior knowledge/experience):

http://www.wiimarbles.com/

Basically you compile your code with mtasc and swfmill brings it all together with embedded images etc.  Swfmill is definitely alpha software, but it wasn't that big a deal.  From what I hear game dev is even easier and faster if you bother to actually buy Studio or something.  The only limitation with the Wii (or the main one anyways) is that you are restricted to Flash 7-level of compatilibility.  Swfmill sucks at including sound/video, but music is better streamed anyways as far as flash is concerned, and it supports that happily.

Offline snake

  • 0010
  • *
  • Posts: 314
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #7 on: April 06, 2007, 11:12:25 pm
Coding sadly isn't my best field, being dyslectic. Takes a while to get through.

If flash could run a Multimedia Fusion .exe file, I'd be all set. Don't expect that to happen anytime soon though.

I'm considering a little Shmup project right now, but I reckon it's not going to end up in flash in the end.

Offline Soup

  • 0010
  • *
  • Posts: 182
  • Karma: +0/-0
  • Monkey lovvvvvvve
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #8 on: April 09, 2007, 12:56:09 pm
That's amazing! I wish I had flash. Definently would learn it. But what does the b button do?

Offline Stwelin

  • 0011
  • **
  • Posts: 567
  • Karma: +0/-0
    • View Profile

Re: a new, better wiimote flash api in just 24 hours!

Reply #9 on: April 09, 2007, 01:38:18 pm
I know actionscript, but i haaate programming in flash when it comes to games. such a pain in the rear.