这在 JavaScript 中可能吗?

发布于 2024-08-03 20:27:25 字数 477 浏览 3 评论 0原文

我想用 JavaScript 创建一个类似于 ElastoMania 的游戏。

我想知道,使用 div 是否不可能进行碰撞检测,因为它们是方形的,并且游戏原理围绕着上坡等展开?

这在画布上可行吗?

另外,使用 jQuery 这样的库会减慢 JS 游戏的运行速度吗?我注意到大多数游戏都是用 vanilla JS 构建的,所以我认为为此类应用程序(游戏)使用库是一个坏主意。

谢谢

更新

这看起来是一个复杂的游戏!我可能仍然会继续下去。如果有人想加入这个项目,请与我联系。

I want to create a game similar to ElastoMania in JavaScript.

I was wondering, would the collision detection be impossible using divs because they are square, and the game principle revolves around driving up slopes etc?

Would this be doable in canvas?

Also, would using a library such as jQuery slow down the running of a JS game? I've noticed most games are built with vanilla JS, so I had the idea that using a library for this sort of application (a game) is a bad idea.

Thanks

UPDATE

This seems like a complicated game! I may still go ahead with it. If anyone wants to jump aboard this project, please contact me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

听风吹 2024-08-10 20:27:25

将模型与演示文稿分开。

游戏逻辑和“物理”将需要自定义脚本,并且与表示模型(即 div 的)无关。

您也许可以在演示方面使用 jQuery,但这是一个特殊情况,性能密集型应用程序,而且,大多数游戏都是用“普通”脚本编写的,这是有原因的。

Separate your model from your presentation.

The game logic and "physics" will require custom scripting, and have nothing to do with the presentation model (i.e. div's).

You may be able to use jQuery for the presentation side, but this is a special case, performance-intensive application, and, well, there's a reason most games are written in "vanilla" script.

冰魂雪魄 2024-08-10 20:27:25

如果您使用 Canvas 标签,这是很有可能的。

http://developer.mozilla.org/en/Canvas_tutorial

这是 Canvas 中的俄罗斯方块游戏并且该游戏背后的库可供任何人使用:

http://tommysmind.com/gamejs/

如果您正在寻找一些可能有帮助的库:

http://openjsan.org/ (任何人都可以使用的一堆库可以做出贡献)

看起来这样的游戏需要花费相当多的精力来构建。它可能类似于超级马里奥兄弟的实现:

http://nihilogic.dk/labs /mario/mario_small_music.htm

It is very possible, if you use the Canvas Tag.

http://developer.mozilla.org/en/Canvas_tutorial

Here is a tetris game in Canvas and the library behind this game is available to anyone:

http://tommysmind.com/gamejs/

If you are looking for some libraries that may be of help:

http://openjsan.org/ (a bunch of libraries anyone can contribute to)

It looks like such a game would be quite an effort to build. It would probably be similar to this implementation of super mario bros:

http://nihilogic.dk/labs/mario/mario_small_music.htm

梦旅人picnic 2024-08-10 20:27:25

This is a very good javascript implementation of a ball simulator.
Maybe you can learn something from that.
Maybe it is usable for the tire collision detection in your project.
This demo shows that it is possible to implement physical models in javascript at reasonable performance.

As you might already know, there is an open source implementation of a ElastoMania like game called X-Moto
X-Moto uses ODE.

Edit: I just found a JavaScript implementation of Box2D: Box2D-JS

红墙和绿瓦 2024-08-10 20:27:25

如果它在斜坡上行驶,我宁愿使用一维数组来存储每个点的高度,并在每次需要检查玩家相对于地面的位置时引用 id 。因此,您基本上需要一个斜率图像以及每个 x 处相应的 ys 集:

  ___
 /   ---
/       ____

024443330000...等等。

但是有一个问题:您在那里不可能有理想的垂直边缘,因为它们需要 2每 1 x y 点。

If it's driving up slopes I'd rather used a 1-d array for storing the height at each point and referred to id every time I need to check the position of the player against the ground. So, you'd basicaly need an image of the slope AND the corresponding set of y-s at each x:

  ___
 /   ---
/       ____

024443330000... etc.

There is one problem however: you couldn't have ideally vertical edges there, as they'd need 2 y points per 1 x.

画▽骨i 2024-08-10 20:27:25

您可以通过使用不同颜色的 div 边框来获得倾斜效果。

<div style="border-left: solid 10px black; border-top: solid 10px red">

会给你一个对角边框,你可能会发现它很有用。

You can get a slope effect by using different colors of borders of a div.

<div style="border-left: solid 10px black; border-top: solid 10px red">

will give you a diagonal border, which you might find useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文