Pygame中的关卡设计 [英] Level Design in Pygame

查看:42
本文介绍了Pygame中的关卡设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿-我正在尝试使用Python的Pygame库设计我的第一款游戏,我想知道总体上关卡设计的最佳实践是什么.我很想听听你们认为是用于管理关卡的良好的面向对象设计模式.另外,我对Python还是很陌生-谢谢!

Hey--I'm trying to design my first game using the Pygame library for Python, and I was wondering what the best practices are for level design in general. I would love to hear what you guys think are good object oriented design patterns for managing levels. Also, I'm fairly new to Python--thanks!

推荐答案

在这种类型的游戏中,您的地图以图块为单位(我假设按级别表示您是个人级别,而不是管理所有级别).每个图块都有

With this type of game your maps are in terms of tiles (I'm assuming that by level you mean an individual level, not managing all of your levels). Each tile has

  • 相关图片(显示屏上的外观)
  • 一种类型(例如,墙壁,地面,陷阱等)

当我在Pygame中创建基于图块的游戏时,通常会有一个 Map 类,其中包含当前地图:

When I create tile-based games in Pygame, I usually have a Map class which contains the current map:

  • 地图的 pygame.Surface (您将向显示内容发短信的地方)
  • 列表(即矩阵)的列表,其中每个项目都是一个Tile对象(我也做过游戏,在其中您只有一个字符串可以告诉您瓷砖是什么类型,然后您就不需要了一个单独的Tile类)
  • the pygame.Surface of the map (what you'll be blitting to the display)
  • a list of lists (ie, a matrix) where each item is a Tile object (I've also done games where you just have a string that tells you what type of tile it is, and then you don't need a separate Tile class)

地图应该是相对静态的-踩到陷阱后,陷阱可能会变成普通的图块(这很简单-当您进行碰撞检测并且很流行时,只需将图块更改为其他图块对象(大概是一个用于空白图块)),但如果可以的话,您不希望地图中出现字符或可移动块.由于可移动块具有它们如何移动的规则,因此它不只是更改一个图块那么简单-您将拥有一整套逻辑,并且至少必须更改两个图块(如果您更改了该图块,该怎么办?可以将块移动到陷阱上-然后,您必须分别记住它下面的内容-死机).在我看来,为每个移动的物体和物品设置一个类会更容易.

The map should be relatively static - you could have that traps become normal tiles after you step on them (this is pretty easy - when you do collision detection and it's a hit, just change that tile to a different Tile object (presumably the one for an empty tile)), but you don't want characters or movable blocks in the map if you can help it. Since the movable blocks have their own rules for how they can be moved, it's not as simple as just changing a tile - you'd have a whole set of logic, and at least two tiles would have to be changed (and what if you could move the blocks onto traps - you'd then have to remember, separately, what was below it - bleh). In my opinion it's easier to just have a class for each moving object and item.

简而言之,您拥有:

  • 平铺
  • 地图
  • 阻止
  • 其他可移动对象/精灵

这基本上就是您的整体水平.对于多个级别,如果各个级别始终相同,则可以只具有一个 Map 对象列表,每个级别一个.

And that's basically your whole level. For multiple levels, if individual levels are always the same, you can just have a list of Map objects, one for each level.

这篇关于Pygame中的关卡设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆