Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django website, basic 2d python game

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.

like image 452
alexedwardjones Avatar asked Sep 18 '12 04:09

alexedwardjones


People also ask

Can you make a 2D game in Python?

Fortunately, the Python arcade library makes creating a 2D game in Python accessible for many programmers! If you haven't already heard about it, the arcade library is a modern Python framework for crafting games with compelling graphics and sound.

Can I create a game with Django?

Even if you wanted to build AJAX games there are several Django apps like Tastypie and Django-REST which can help you build it. Check out Django generic views to find out how you can quickly build the usual lists of objects and object detail views.

Is Django good for game development?

Django is great web development framework. It's far and away my “go-to” when starting a new web project, but like all frameworks and languages, it isn't a fit for all types of apps.


3 Answers

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.

like image 169
root Avatar answered Sep 19 '22 23:09

root


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.

like image 43
Jesus Bejarano Avatar answered Sep 21 '22 23:09

Jesus Bejarano


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

like image 45
zmbq Avatar answered Sep 18 '22 23:09

zmbq