简体   繁体   English

Django网站,基本的2d python游戏

[英]Django website, basic 2d python game

I'm fairly new to web development and Django so bear with me. 我对网络开发很新,Django也跟我一样。 I'm planning to make a fairly simple website in Django, that part I can manage. 我打算在Django中创建一个相当简单的网站,这是我可以管理的部分。

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. 我正在寻找构建一些基本的2D游戏,我完全理解你可以在flash或作为java web应用程序轻松管理它,但我希望在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? 我已经做了一些研究,但我是空白的,是否有一种直接的方式来创建可以轻松与django集成的2D网页游戏?

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. 我希望用Python构建这些游戏,以便用户可以再次使用Python为游戏编写自己的个人AI,并相互竞争。 As a bit of a competition/learning exercise. 作为一个竞争/学习练习。

Thanks in advance and sorry if it turns out to be a stupid question. 如果事实证明这是一个愚蠢的问题,请提前致谢并对不起。

As browsers (everything except Grail ) do not run python code it is fairly difficult to build the game you want in python. 由于浏览器(除了Grail之外的所有东西)都不运行python代码,因此在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". 从理论上讲,你可以将一些客户端Javascript与在服务器端运行的一些python代码混合在一起,但这不是一个非常糟糕的想法,因为浏览器必须与服务器通信以“游戏中的每一步”。 You can also have server side python rendering html, but that wouldn't make a very good game. 你也可以有服务器端python渲染html,但这不会是一个非常好的游戏。

You could try to make a gaming site for Grail users, but I suppose there aren't many :) 您可以尝试为Grail用户制作游戏网站,但我想没有多少:)

More seriously: 更严重的是:

You can also take a look at pyjs . 你也可以看看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. 我可以想象pyjs几乎就是你必须让它工作。

Similar question to yours has been asked before, you should check the answers. 你之前已经问过类似的问题,你应该检查答案。

I think this article is what your looking for: How to Build a Python Bot That Can Play Web Games . 我认为这篇文章正是您所寻找的: 如何构建可以玩网页游戏的Python机器人 But if it is not, try to implement pygame - it is the most popular library to make 2d games in python. 但如果不是,尝试实现pygame - 它是最受欢迎的库,可以在python中制作2D游戏。 If you can, search and download this: "Making Games with Python & Pygame". 如果可以,请搜索并下载:“使用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. 但是就像上面的答案一样,我相信在网络上构建和实现2D游戏的最简单方法是在客户端使用html5 canvas和javascript。 "HTML5 Canvas Core" is the best book to start learning it. “HTML5 Canvas Core”是开始学习它的最佳书籍。 I hope that this was helpful to you. 我希望这对你有所帮助。 Good luck. 祝好运。

The game will most probably have to run on the client side. 游戏很可能必须在客户端运行。 You should take a look into Javascript and AJAX. 你应该看看Javascript和AJAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM