Forums

HTML5 game [Construct 2][AJAX][web2py]

This is for anyone, who's into playing around with some html5 stuff, who likes python and preferably wants to make some multiplayer turn-based games.

Short intro. I have quite intermediate programming skills(you know, don't even bother handling errors and stuff like that). I like python and I am quite lazy to study how to do the things I want in say PHP, which most shared hosting providers prefer, so I figured to work around it by using cross-domain ajax calls to pythonanywhere.com where I've launched web2py.

So what has to be done is, you make a HTML5 game, I made mine with Construct 2. You set up ajax calls to hit yourname.pythonanywhere.com/welcome/default/call/run/your_function_name/variable1/variable2 Edit the default.py file with the functions responsible for handling game logic, connections, id assignment and so on, give them @service.run decorators so that you can access them with "..call/run/..." and don't forget to set in every function: response.headers["Access-Control-Allow-Origin"] = '*' * - means calls from all domains will be accepted, when 'http://name.com' would only allow calls from this domain.

And your ready to go.

You can check out my Space tic-tac-toe game on the domain http://zerostatesociety.com which is the shared host I talked about, and see the game in action. Just launch 2 tabs and challenge yourself.

A more detailed tutorial with the default.py and db.py files can be found on: https://www.scirra.com/tutorials/1062/multiplayer-tic-tac-toe-c2web2pypythonajaxcross-domain

Thanks for reading.

Awesome! Thanks for posting that :-)

Glad that it's helpful :)

That's really cool