Peer to peer shooter + source code

A few weeks ago I had the idea of creating a multiplayer Flash game, using the new peer to peer connection capabilities of FlashPlayer 10. Here is the result.

Start the game:
P2PShooter

Building a multiplayer game comes with it’s own set of challenges. The first one being the initial creation of a p2p connection, which basically comes down to four steps:

 

  • Connecting to Adobes Cirrus server (formerly Stratus) using a personalised Cirrus server address and a developer key. For more info click here: http://labs.adobe.com/technologies/cirrus/
  • Receiving a peer ID from the Cirrus Server.
  • Sending that peer ID to the second Player.
  • Sending the peer ID from the second Player to the Cirrus server.

 

I decided to simplify that process by using SWFAddress, creating a custom URL + peer ID that could be send to the second player. This prevented him from being forced to re-enter the peer ID into his client. After that you have to find a convenient way of sending the game URL to the second Player.

In a second step I would have tried to add a social media component to the Game. For example: Using a Twitter login to start and immediately publish a game request.

Since debugging and testing the game is somewhat of a hassle, I decided to stop development on it. You can however download the complete source code from here:

DOWNLOAD – P2PShooter (204 KB)

Before you start editing the code, be sure to get a Cirrus developer key and connection URL first (see step 1).

Insert your developer key and server address into the static constants in MPShooter.as.

To compile the Game use the MPShooter.as in the package de.davidochmann.games.mpshooter (I used FDT, but Flash Develop should work fine to). Using FlashPlayer 10 as target player is required.

Please be aware that the game in its current state is a proof of concept. There aren’t a whole lot of code comments, and some approaches aren’t very good (e.g. try using registerClassAlias instead of relying on the anonymous Data object).

DoSite v0.61 Easily create Flash microsites

DoSite is a simple AS3 framework that helps you to create Flash microsites.

DOWNLOAD – DoSite v0.61 (4,2 MB)

The Library simplifies a lot of chores that occur during Flash-Website development, such as: sub-site creation, site transitions, content handling or external library connection (e.g. SWFAddress or Analytics).

Click on the image to see DoSite in action:
Viva Espana

The basic idea:
DoSite allows you to distribute your project using independent swfs for each part of the website. The interplay between swf files being handled trough the framework.

(You can however use a single swf to carry all of your code using the embed method. See example “05_single_swf”.)

How it works:
In general DoSite uses two xml files to build the content of the website. The first defines the paths to the content of the website (the swf, jpg, xml files etc.), the second the composition (position, url, names etc.).

The framework than combines the content according to the “id” property of each xml tag.
The visual representation of the content is held in the “DoSite.container():Sprite” that can be added to the stage after including the content.

Every website element is either a fixed content (always visible) or a sub-site.
At runtime only one sub-site is displayed at once (!), although this might change in future releases.

Please take a look at the examples to get a closer look at how DoSite works.

The examples:

  • 01 basic: A simple DoSite setup This example shows you the basic structure of both xml files as well as simple sub-site navigation with DoSite.
  • 02 external xml: How to pull the xml information out of the fla and into separate files.
  • 03 animation: A simple sub-site animation example using TweenMax.
  • 04 swf address: How to connect your website to SwfAddress for sub-site browser navigation.
  • 05 without xml: How to build a DoSite project without using xml.
  • 06 single swf: A full-fledged DoSite example using the embed tag to bundle the website content into a single swf.
  • Example 01 to 04 use the same layout and content to exemplify the functions of DoSite.
    Example 05 however was created as a school project. The website had to run locally, which forced me to dispense external swf or xml files to avoid security restrictions.

    I will extend this website with examples and documentations as DoSite evolves.

    Have fun with DoSite,

    David

    Changelog:
    v0.61

  • Added a Data class that holds every framework property. It replaces the content and composition classes in the “xmlparser” package.
  • It is no longer necessary to assign the content or composition xml to the framework. All properties can now be set via the new Data class or directly with DoSite.compositon() or DoSite.content() after initializing DoSite.
  • DoSite can now be initialized without an open SubSite. This is important for utilizing a See-and-Point navigation structure.
  • Removed a bug that caused the content to align to the wrong position when the container align is set to „tl“.
  • Renamed the addSubsite function to addSubsiteContainer.
  • Renamed the addFixed function to addFixedContainer.
  • Various code optimizations.
  • Bubbles!

    Bubbles is a little time-killing experiment. The swf generates a bunch of circles and moves them accros the stage.
    The speed of each circle is determined by its size, its blurriness is a combination of the x and y position relative to the content of the stage.

    As allways you can download the source code:

    DOWNLOAD – Bubbles (12 KB)

    Click on the image to open Bubbles.
    Scroller image

    AS3 scroller reference

    Below you can find a quick reference for creating an AS3 scroller.
    The example shows a simple (though spaghetti coded) way to create a fluid and functional AS3 scroller.

    DOWNLOAD – AS3 scroller reference (20 KB)

    This blog post is manly done for self-reference reasons. There are a lot of other Flash blogs and tutorial sites that deal with flash scrollers. This is just one solution that I happen to use quite frequently.

    Chances are that if you create Flash content, you stumbled upon scrollers.
    The problem is, while scrollers aren’t that hard to do, there are quite a few ways to create them, and the most obvious solution to do them, may not be the best way (I’m talking to you start- and stopDrag functions).
    This is a best practice solution for creating scrollers. It relies on the MouseEvent.MOUSE_MOVE Event to render. The big advantage compared to a scroller using the Event.ENTER_FRAME event is that it renders a lot quicker since mouse events are able to render between frames.

    Changelog:
    – I updated the scroller reference to be a little more OOP friendly.

    Click on the Image to open the example:
    Scroller image

    DoConvert v0.70 – String to Object converter

    Easily convert Strings to Objects (or Arrays) with DoConvert.

    DOWNLOAD – DoConvert v0.70 (52 KB)

    The Library allows you to parse any String formatted in the short Array or Object syntax.
    Any given datatype within the String will be converted to its logical ActionScript 3 pendant (i.e. {a:true, b:50}, the value a will be typed Boolen. The value b, uint).

    example:
    DoConvert code example

    Yes, I know. It’s kinda like JSON ;).

    Changelog:
    v0.6

    • Removed a bug in the StringToObject.as and DoGesture.as, that prevented DoConvert to parse Strings including breaks and/or tabs.
    • Various code optimizations.

    v0.62

    • Removed the NaN compiler error.
    • Various code optimizations.

    v0.70

    • Added Actionscript 2 version.
    • Reduced Filesize by removing the classes ToArray.as, ToObject.as and Type.as.
    • Various code optimizations.