Smiley Space Shooter Multiplayer Flash Game Demo

This wiki guides you through the code for Smiley Shooter demo game.

The demo itself is quite simple. The user first needs to click on the “Start Game” bar at the top. Once the status bar changes to “Started!”, users can use the arrow keys to move up and down and click to shoot ball towards their opponent. Since its a 2 player game, another user will also do the same steps and voila! they can fight against each other and see each other move in real-time.

Watch Video

Now lets understand how the game code works by examining the key code snippets. Entire source code is available and can be downloaded or viewed from our git repo.

First we specify the AppWarp constants that will be used in SpriteMoveDemo.as file

You get your values by registering and creating an AppWarp type of application from AppHq (Shephertz developer dashboard). This wiki page contains a step-by-step guide on how to register, creating the app and a game room. Once you’ve got these values, replace as indicated.

Next we simply add the required UI elements (local player, remote player etc.). For the real-time communication to happen, you need to use AppWarp swc library file. The latest version can be download from our Git Repo here. Add this swc to your project. Next you need to initialize the WarpClient singleton and set up your listeners through which you will get events.

The listener is defined in AppWarpListener.as file and implements the event interfaces required for this sample. ConnectionRequestListener defines the callbacks for connection establishment and tear-down. RoomRequestListener defines the callbacks for the game room’s join and subscribe operations. NotificationListener defines the callbacks for remote notifications such a player sending a chat or updating a rooms properties etc.

Now we are ready to connect to AppWarp cloud and start our game. Now each user that is concurrently connected to your game must have a unique username. In this demo we will simply use a random number for this and connect. You can use other solutions such as a facebook id, email address etc. to guarantee uniqueness depending on your game.

We send a comma separated message to the room with the local players coordinates. This message is received by all players in the room and they can then update their UI in turn. Similarly we handle mouse click by sending the projectile coordinates as follows

When we receive remote messages we need to write some code to update the remote player’s position or projectile depending on the message received. Here is the code snippet which handles it in the AppWarpListener.as file