Monday, October 28, 2013

Hello RPG... Or writing an RPG game template using Scala, Playframework, Akka, Websockets, Crafty...

After playing with Typesafe Activator I've spotted interesting template: reactive-stocks. The template simulates live data feed of stock prices and allows to look up market sentiments (buy/hold) via RESTful search requests to Twitter and lexical analysis service. It demonstrates several interesting frameworks / techniques. It uses Play-framework / Akka asynchronous and features / Websockets data streaming and browser client backed with JQuery.

After some consideration I thought it would be quite interesting as a project to write a small multiplier RPG game that would also make use of all above cool things:

1) Websockets for realtime communication
2) Akka: Model World / Scenes / Users as Akka actors.
3) Playframework to run the show...
4) JQuery / JSon / HTML at client browser

I also needed of course to have a client side Game engine that would allow me to concentrate on actual game implementation and handle rest of the stuff as Sprites, Animations, Collisions, Sound... And after some research I've found Carfty.

5) So Crafty it was...

I would not be discussing the advantages of technologies but will try to explain how I've used every of those technologies. Obviously some of the components were used more and some less. But all were necessary to put this thing together.


For the game I've looked at this example and took foundation of it for the game. This is good starting point to learning crafty.

Here is some screenshots:

Two browsers side by side / 2 users are at the same scene



Scene transition when one users goes to the next screen



Second user follows and joins the scene



Game uses websockets for real-time message delivery between Player/Browser-> Websocket -> Server -> User brocker-> Scene (that player subscribed) -> back to -> Other Users brockers in this scene -> Websocket -> Browser / Player. Messages are Json objects.

Scene, User and World (consisting of Scenes) were nicely mapped to Akka actors. World has coordinating role between Users and Scenes. User talks to the Scene it was subscribed to and receives notification from it. So World should be able to scale to many scenes... (as Akka is generally scales well). And scene should handle local events for Users subscribed to it.


At the point of writing game supports:

  • 2 players multiplayer game (in general it allows more but 2 were added by the time of writing it)
  • Scene transition. Scenes are defined in JSON and can be added to game

And future plan is to generalize to more players, implement subscription and serialization of the users/scenes states to a DB or drive, allow people to choose character.

I've posted work in progress here and will be updating details over couple of days:

https://github.com/codetinkerhack/hello_rpg





1 comment:

  1. The expansion offers 40 types of monsters, 16 additional levels, and 6 additional weapons. It is the second expansion of Painkiller with the first being Painkiller: Battle out of Hell. Overdose was released in 2007. battlefield 5 hack

    ReplyDelete