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!

Bluetiger6001
  • 151
  • 2
  • 3
  • 9

2 Answers2

0

Of course you can use brute force method to do this. Here is function to replace color with another in pygame surface.

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
Hannes Karppila
  • 969
  • 2
  • 13
  • 31
0

I assume by image you mean pygame.Surface. You have several options:

  • pygame.Surface.set_at(...)
  • Use a palettized surface. Then change the palette. Based on your use case, this is actually probably what I'd suggest.
  • Use the pygame.PixelArray PyGame module. I don't think it requires NumPy.
  • Just use NumPy. It's really not that huge of a requirement; lots of projects require it and it's simple to set up. You get access to the powerful pygame.surfarray module
geometrian
  • 14,775
  • 10
  • 56
  • 132