I want to create a very simple 2d multiplayer browsergame in html5. Something like Scalatron

I mainly want to do this to improve my scala skills, the problem is I would have to code the clientside code in javascript and the serverside code in scala. This would result in duplicated code.

Another option would be to ignore the html5 part and write it in opengl. But I would still prefer to have a html5 game.

I could do this is in javascript, but then it would destroy the whole purpose of learning scala.

Is there a way to use scala with html5? Or what would you recommend me to do?

  • 3
    \$\begingroup\$ There is one valid question though: Is there a way to use scala with html5? \$\endgroup\$
    – Valmond
    Oct 29 '12 at 14:37

The programming language for HTML5 is Javascript. Web browsers can't interprete any other programming languages. When you want to create a HTML application in Scala, you will need a transcompiler which turns your Scala code into Javascript.

I found a project with that goal via Google, but I have no idea if it's usable yet: http://scalagwt.github.com/

By the way: I am currently developing a client/server application with the client in Javascript and the server in Java. There is surprisingly few duplicate code, as long as you follow a strict separation of concerns between client and server (the server does all the game logic, the clients job is taking user input and displaying the game state as told by the server).

  • \$\begingroup\$ How do you keep the client in sync? Do you use ajax to do this? Also the physics should only be on the server, what library do you use to do this? \$\endgroup\$
    – Maik Klein
    Oct 29 '12 at 16:27
  • \$\begingroup\$ That's all very off-topic, but I use WebSockets for client/server communication. I don't use a library for the game mechanics, I wrote them myself. \$\endgroup\$
    – Philipp
    Oct 29 '12 at 16:34

Have a look to http://www.scala-js.org/ - it is Scala to JavaScript compiler. Supports source maps and since version 0.6 is not longer experimental.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.