Add Realtime Multiplayer Game Play
& Virtual Room Logic to your
AndEngine Games
Fruity Monster – A Realtime Multiplayer game with AppWarp and AndEngine
- Players connect to AppWarp cloud
- Players can create rooms or join existing rooms
- Once inside a room, players can see each other move in realtime and place fruits to the four corners of the room
Check the Recorded Gameplay
for Fruity Monster Game
Code Walkthrough
Here are few important steps for making this game.
- Edit Constants.java file with your AppWarp keys
- Initialize WarpClientat MainActivity.java with the developer’s api key and secret key that we have defined in Constants.java and connect with AppWarp Service
- In RoomListActivity.java it a list of active game rooms to the user. The list contains rooms with at least one user We use our matchmaking API to build this list.
theClient.getRoomWithNUser(1);// trying to get room with at least one user
The user has the option to either join a room from this list or to start a new room. - Join An Existing Room – To receive the callback for the above request, we need to add a zone request listener as this is a zone level request. We make the RoomlistActivity implement the zone request listener interface and add itself as the listener
@Override public void onGetMatchedRoomsDone(final MatchedRoomsEvent event) { runOnUiThread(new Runnable() { @Override public void run() { RoomData[] roomDataList = event.getRoomsData(); if(roomDataList.length>0){ roomlistAdapter.setData(roomDataList); listView.setAdapter(roomlistAdapter); }else{ roomlistAdapter.clear(); } } }); }
- Join a New Room
- AndEngineTutorialActivity.java
This screen represents SimpleBaseGameActivity(andengine). In this we have defined hashmap to maintain online users who are playing
game in this room. We initilizeandengine in onCreateEngineOptions() and load all resources used in game in onCreateResources()
To get the details refer to the blog at here