简体   繁体   English

如何将控制台插入pyGame窗口?

[英]How can I insert a console in to a pyGame Window?

I'm making a text adventure, and I want to have pyGame animations and illustrations and a HUD! 我正在进行文字冒险,我希望有pyGame动画,插图和HUD!

http://imageshack.us/photo/my-images/585/img20110518075206.jpg/

How can I insert this console? 我该如何插入此控制台?

Thanks! 谢谢!

I'm pretty sure that's impossible. 我很确定这是不可能的。 If you want a console within a Pygame screen then you'll have to write your own, or find one written by someone else (eg http://pygame.org/project-pygame-console-287-.html ) 如果你想在Pygame屏幕中使用控制台,那么你必须自己编写,或者找到其他人编写的控制台(例如http://pygame.org/project-pygame-console-287-.html

For your game, you can use subsurface , for the different screen 'sections'. 对于您的游戏,您可以使用地下 ,用于不同的屏幕“部分”。

Using python 3x will have issues with multiple libraries, that are not precompiled for you. 使用python 3x会出现多个库的问题,这些库不是为您预编译的。 If you can, it will simplify things to Use 2.7 or 2.6. 如果可以,它将简化使用2.7或2.6的内容。 (There is a python2.7 binary, but not on the front page) (有一个python2.7二进制文件,但不在首页)

A console isn't too hard. 控制台不是太难。 You need to break down the components, deciding what you need. 您需要分解组件,决定您需要什么。 Start with a miniproject, implementing features one at a time. 从一个小型项目开始,一次实现一个功能。

  1. keyboard input, print letters to console 键盘输入,打印到控制台的字母
  2. render text from a string 从字符串中呈现文本
    1. blit cached text. blit缓存文本。 will have demo code later, if you are interested 如果您有兴趣,我们稍后会有演示代码
  3. dict() of strings, for commands, with values of function names. 字符串的dict() ,用于命令,具有函数名称的值。
  4. draw the last 10 lines of text 画出最后10行文字
  5. up = scroll through command history up =滚动命令历史记录
  6. allow command aliases, like "n" and "north" will point to move_north 允许命令别名,如“n”和“north”将指向move_north
    1. Implement this using a class: Command() . 使用类:Command()实现它。 Which stores a list of all aliases. 其中存储了所有别名的列表。

commands = { "n" : move_north, "s" : move_south, "fps" : toggle_fps, "help" : print_help } commands = {“n”:move_north,“s”:move_south,“fps”:toggle_fps,“help”:print_help}

On enter, call the dict's value, if key exists: 在输入时,如果密钥存在,则调用dict的值:

if cmd in commands:
    commands[cmd]()
    # same as commands["n"]()

You could even have the console's print_help() use the function docstrings. 你甚至可以让控制台的print_help()使用docstrings函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM