11

I'm fairly new to web development and Django so bear with me. I'm planning to make a fairly simple website in Django, that part I can manage.

I'm then looking to build a few basic 2d games into it, I fully appreciate that you can easily manage this in flash or as a java web app but I'm looking to implement them in python. I've done some research but I'm coming up blank, is there a straightforward way to create 2d python web games that would easily be integrated with django?

I'm hoping to build these games in Python so that the users can program their own individual AI's for the game, again in Python, and compete against each other. As a bit of a competition/learning exercise.

Thanks in advance and sorry if it turns out to be a stupid question.

alexedwardjones
  • 561
  • 1
  • 5
  • 18

3 Answers3

6

As browsers (everything except Grail) do not run python code it is fairly difficult to build the game you want in python. In theory you could mix some client side Javascript with some python code running on the server side, but that would not be a very goog idea, since the browser would have to communicate with the server for "every move in the game". You can also have server side python rendering html, but that wouldn't make a very good game.

You could try to make a gaming site for Grail users, but I suppose there aren't many :)

More seriously:

You can also take a look at pyjs. And theres even a game example. You can find the source code for the asteroid game here. I can imagine that pyjs is pretty much all you have got to make it work.

Similar question to yours has been asked before, you should check the answers.

Community
  • 1
  • 1
root
  • 76,608
  • 25
  • 108
  • 120
2

I think this article is what your looking for: How to Build a Python Bot That Can Play Web Games . But if it is not, try to implement pygame - it is the most popular library to make 2d games in python. If you can, search and download this: "Making Games with Python & Pygame".

But like the answers above, I believe that the most easy way to build and implement a 2d game in the web is using html5 canvas with javascript on the client side. "HTML5 Canvas Core" is the best book to start learning it. I hope that this was helpful to you. Good luck.

aneroid
  • 12,983
  • 3
  • 36
  • 66
Jesus Bejarano
  • 1,146
  • 10
  • 9
1

The game will most probably have to run on the client side. You should take a look into Javascript and AJAX.

zmbq
  • 38,013
  • 14
  • 101
  • 171
  • 2
    The issue is and it's my fault for not explaining this, I'm hoping to build these games in Python so that the users can program their own individual AI's for the game, again in Python, and compete against each other. As a bit of a competition/learning exercise. – alexedwardjones Sep 18 '12 at 05:14
  • 1
    but you can upload/POST code to server, execute it there, and get the result in response. – Sashko Lykhenko Jan 17 '15 at 22:46