How can I insert a console in to a pyGame Window?

2019-02-19 15:14发布

I'm making a text adventure, and I want to have pyGame animations and illustrations and a HUD!

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

How can I insert this console?

Thanks!

2条回答
手持菜刀,她持情操
2楼-- · 2019-02-19 15:46

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 (e.g. http://pygame.org/project-pygame-console-287-.html)

查看更多
做个烂人
3楼-- · 2019-02-19 15:49

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. If you can, it will simplify things to Use 2.7 or 2.6. (There is a python2.7 binary, but not on the front page)

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. will have demo code later, if you are interested
  3. dict() of strings, for commands, with values of function names.
  4. draw the last 10 lines of text
  5. up = scroll through command history
  6. allow command aliases, like "n" and "north" will point to move_north
    1. Implement this using a class: Command() . Which stores a list of all aliases.

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

On enter, call the dict's value, if key exists:

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

You could even have the console's print_help() use the function docstrings.

查看更多
登录 后发表回答