在SDL中使物体独立移动(如枪声)
我一直在关注 SDL 上的lazyfoos 教程,并且我对他的代码进行了大量修改,以制作一种可以四处移动的船舶游戏。我正在尝试拍摄这艘船,但我完全不知道该怎么做。我在一堂课上讲了船和它的运动以及图像的实际应用,我想知道是否有人有任何技术或某些方法可以有效地使船拍摄,使镜头独立移动,然后在它移动时消失屏幕外。我知道我给出的解释有点模糊,但我不想得到所有的答案,只是一些示例代码和正确方向的一点。
I have been following lazyfoos tutorials on SDL, and I have heavily modified his code to make sort of a ship game, that moves around. I'm trying to make the ship shoot, but i have absolutely no idea how to go about doing this. I have the ship and it's movements and the actual application of the image in a class, and I as wondering if anyone had any techniques or certain ways that are efficient in making the ship shoot, making the shot move independently and then disappearing when it goes off screen. I know that I am giving a vague explanation sort of, but I don't want to be given all of the answers, just a little sample code and a point in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只能绝对推荐Aaron 的游戏编程教程,它使用C++ 和SDL。
I can only absolutely recommend Aaron's Game Programming Tutorials, it uses C++ and SDL.
创建一个类来容纳射弹,其中包含您需要的所有信息,例如:
这个类显然并不完整,您可能想要调整访问级别,并编写一些构造函数和其他东西,但它应该给你基本的想法。
把它们做成一个容器。当船起火时,将一颗放入容器中。每一帧,调用更新、绘制、检查射弹是否死亡并检查与游戏对象的碰撞。如果发生碰撞,请施加损坏或其他什么。如果该物体已死亡,请将其从容器中取出。
Create a class to hold a projectile, with all the information you need in it, such as this:
This class is not complete obviously, you'll probably want to make adjustments to access levels, and write some constructors and other things, but it should give you the basic idea.
Make a container of those. When the ship fires, put one into the container. Each frame, call update, draw, check if the projectile is dead and check for collisions against the game objects. If a collision occurs, apply damage or whatever. If the object is dead, remove it from the container.