marmalade-demo

*We assure you that we do not spam. You may receive occasional emails from us.
 You can always unsubscribe.

Marmalade Monster Move

Monster Move is a basic demo application, where 5 players can simultaneously move around the screen and can view others players also moving on screen.

AppWarp Marmalade

View Source And Download

The player can choose a monster from 5 monsters available to him. Once he/she chooses his/her monster, they can move on the screen, by simply tapping on a location. As soon as he/she taps on a place, the player starts to move towards that location.

As other players also join the game, they become visible to all players. Everyone can see every other moving on the screen.

Please note: If you are using Maramalade 6.3, you have to change the CIwSVec2() to CIwFVec2() in Drawing functions.

The game has two screens, one is the selection screen for selecting a monster and the other one is game screen, where players can move. The selection shows 5 monsters, from which 1 monster has to selected by simply tapping on it. The game screen shows the monster selected which can moved on the screen by tapping on the screen, wherever you will tap, the monster will move to that location. You can also observe others players moving.

Technical Details

The game is developed using Iw2D. Over Iw2D, a basic game engine is written. The game engine contains classes for Game, Scenes, Players and Background. Every scene contains a background and some players. There can be more than one scene but only one is visible at a time. The Game class manages these scenes.

AppWarp

This demo uses AppWarp’s Marmalade SDK for multiplayer support. AppWarp has to be initialized before using it. The initialize function takes an apiKey and sceretKey as parameters. Please see this page for instructions on how to get your keys. AppWarp SDK is a singleton library. The getInstance() function can be used to get the instance of the singleton AppWarp Client object. Once you get the instance, you can start calling function through that instance.

AppWarp::Client* WarpClientRef;
AppWarp::Client::initialize("<your api key>","<your secret key>");
WarpClientRef = AppWarp::Client::getInstance();

After Initialization, we have to define listeners. You can observe a class Listener in main.h which inherits from AppWarp::ConnectionRequestListener, AppWarp::RoomRequestListener, and AppWarp::NotificationListener.

An object is created for the Listener and assigned to WarpClient by calling setConnectionRequestListener, setRoomRequestListener and setNotificationListener functions.

Listener listener(WarpClientRef,game);
WarpClientRef->setConnectionRequestListener(&listener);
WarpClientRef->setRoomRequestListener(&listener);
WarpClientRef->setNotificationListener(&listener);

It is important to call the update() function on AppWarp instance in the main game loop.

WarpClientRef->Update();

The very first screen is the selection screen, where the player has to select a monster. Once he/she chooses a monster, the game changes its scene from selection screen to game screen. We have generated a random name for the player, which is like monster4NOBBZDYJES, the first character represent the type of the monster i.e. 1-5. and other 10 characters represent a random name. This is because all clients connecting to the same AppWarp app must have a unique username.

As soon as the player gets connected, we send the first location of the player, which is like “120×35″ where 120 is the x position and 35 is the y position. Every time the player taps on the screen, his position is also send using the sendChat() function.

Remote Monsters

Listeners as defined in the games, listen to the responses and notifications sent by the AppWarp server. OnChatRecieved() is called whenever a chat is received. Here we parse the positions of the other players as other players are sending their positions in chat. We also check if the sender is new, we add him to the game. If he/she already exists on the screen, we simply set his/her target to the new position received in the chat and he/she starts to move to that position.

GetPlayer(chatevent.sender);
	if(p != NULL)
	{
		p->SetTarget(x,y);
	}
	else
	{
		gs->AddRemotePlayer(type,chatevent.sender,x,y);
	}

Whenever a player leaves the game he/she is also removed from the screen. This is notified through the onUserLeftRoom notification and is handled as below.

void Listener::onUserLeftRoom(AppWarp::room rData, std::string user)
{
	gs->RemovePlayer(user);
}