面向对象游戏编程中的物理
所以我正在尝试学习如何开发2D游戏。
我正在使用 Android 和 C#。
我遇到的问题是这样的。
绘制某种精灵是很容易的。我努力的地方是想象如何对屏幕上各种对象的交互进行编码。
例如,假设我有以下对象。
public class MyGenericObject {
public MyGenericObject() {}
public Int32 Width { get; set; }
public Int32 Height { get; set; }
public Int32 X { get; set; }
public Int32 Y { get; set; }
public Image ObjectImage { get; set; }
}
假设我想对 N 个这些对象之间的交互行为进行建模。在这种情况下,人们会使用什么典型模式?
例如,您是否可以简单地调用诸如 MyPhysicsSim.DoPhysics(List
假设这不是一个巨大的延伸。那么,在这个方法内部,如何计算交互作用和产生的运动呢?我只是无法理解它(显然我确实明白有一些基本方程可以求解方向和速度等,但我似乎无法弄清楚如何将它们应用为算法)。
我看过很多教程,所有教程似乎都专注于绘制一个对象,或者假设对内部结构的理解程度超出了我的能力范围。所以我希望得到一个非常简单、简单的回应。
所以基本上我要问的是,对于傻瓜来说,如何在 OO 范式中处理 2D 对象之间的交互?
So I am in the process of trying to learn how to develop 2D games.
I am playing around with both Android and C#.
The issue that I am having is this.
It is easy enough to draw a sprite of some sort. Where I struggle is to visualize how one can code interactions of various objects on screen.
For example lets say I have the following Object.
public class MyGenericObject {
public MyGenericObject() {}
public Int32 Width { get; set; }
public Int32 Height { get; set; }
public Int32 X { get; set; }
public Int32 Y { get; set; }
public Image ObjectImage { get; set; }
}
Lets say I want to model the behavior of an interaction between N number of these Objects. What is a typical pattern one would utilize in such a scenario?
So for example would you simply call a method such as MyPhysicsSim.DoPhysics(List<MyGenericObjects>);
Assuming this is not a huge stretch. Inside of this method then, how do you calculate the interactions and resulting movements? I just can't get my head around it (Obviously I do understand that there are basic equations that can solve direction and speed and so forth but I just can't seem to work out how to apply these as an algorithm).
I have looked at numerous tutorials and all of them seem to concentrate on just drawing an object or assume a level of understanding about the internals that is way over my head. So I am hoping for a really simple, dumbed down response.
So basically what I am asking is how do you approach interactions between 2D objects in a OO paradigm for dummies?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
传统上,大多数游戏在核心位置都有一个类似于下面的循环:
“updatePhysics()”方法可以做一些非常基本的事情,例如:
所以你在模拟的世界中基本上有一个“刻度”,并且您的代码可以反映场景中可能发生的增量。
Traditionally, most games have a loop similar to the one below somewhere at the core:
and the 'updatePhysics()' method can do something very basic, such as:
So you basically have a 'tick' in the world you're simulating, and your code works to reflect the delta in the scene that would have occurred.