0

I'm making a simple game, whereby I want my characters quite customizable. I want my characters to be able to be fully edited in colours, for example, if a player wants their character to have cyan skin, they just put into the sliders, or what I choose to use, "0,255,255", or purple "255,0,255", or something random "25,125, 156", and have their character be that colour. I haven't even started creating the game, but I've got the basis down and I know exactly what I must do for pretty much every EXCEPT this.

I done a search in Google, and it turns out, I need numerical python for this? Well this is a whole new package, and in order for the average player to play, I must change it to EXE form... (or have python, pygame and numerical python installed onto their PC, which will be a problem if they have a later version...). Now, it's already getting complex with just pygame, but with numerical python as well, is there even a tutorial on how to do this?

Any suggestions? Thanks!

4

2 回答 2

0

当然,您可以使用蛮力方法来做到这一点。这是在 pygame 表面中用另一种颜色替换颜色的功能。

def color_replace(surface, find_color, replace_color):
    for x in range(surface.get_size()[0]):
        for y in range(surface.get_size()[1]):
            if surface.get_at([x, y]) == find_color:
                surface.set_at([x, y], replace_color)
    return surface
于 2015-03-01T19:17:41.943 回答
0

我假设image你的意思是pygame.Surface。你有几个选择:

  • pygame.Surface.set_at(...)
  • 使用调色板表面。然后更改调色板。根据您的用例,这实际上可能是我的建议。
  • 使用pygame.PixelArrayPyGame 模块。我认为它不需要 NumPy。
  • 只需使用 NumPy。这真的不是那么大的要求。很多项目都需要它,而且设置起来很简单。您可以访问强大的pygame.surfarray模块
于 2015-03-01T19:25:37.697 回答