C# XNA - 库存/可破坏地形和收藏
我无法在标题中很好地描述问题。如果有人拥有编辑权限并且可以更好地表达它,请随意。
所以我有一个不错的小地形,它是可破坏的,但是如果有人,比如说,打破了一棵树,我怎样才能让它在他们的库存中添加一棵树呢?
我不是在寻找代码,只是在寻找方法。
每个方块都有自己的类,全部继承自基类 Block,当方块被破坏时,它会掉落一种可拾取的婴儿方块。
我可以做到这一点,但我很困惑,因为这个想法是你可以打破方块并将它们放置在其他地方(是的,有点像《我的世界》),那么我该如何让这个库存系统工作呢?我想了两天,却没有任何收获。
I can't describe the problem well enough in the title. If somone has edit permissions and can phrase it better, feel free to.
So I've got a nice little terrain going, it's destructable and all, but if somone, say, breaks a tree, how can I make it add a tree to their inventory?
I'm not looking for code, just a method.
Each block has it's own class all inheriting from the base class Block, and when the block is destroyed, it drops a sort of pickup-able baby block.
I'm able to do this, but I'm confused because the idea is you can break blocks and place them somewhere else (Yeah, kinda like Minecraft), so how would I make this inventory system work? I've been thinking for two days and I got nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
物品需要某种 ID 代码。显然你已经有了一个来存储世界本身。
当你砍倒它时,该块有一种“树”。
“树”+砍=> “砍伐的树”
当它被拾取时,您可以从世界中删除砍伐的树图形,并将砍伐的树项目放入玩家的库存中。
Items need some sort of ID code. You obviously already have one to store the world itself.
The block had a type of "tree" when you chopped it.
"Tree" + Chop => "Chopped tree"
When it's picked up you remove the chopped tree graphic from the world and put a chopped-tree item in the player's inventory.
我认为使用一些伪代码会更容易,而不是用文字解释它:
Instead of explaining it with words I figured it will be easier with some pseudo code: