Good morning, to explain better what I want to know is to let you know so I can use it.
With a class called
Personaje I want to know how it is dressed, it would be enough to create several variables where a number is stored that identifies the sprite that will be used, example:
Personaje: cabeza = 5 cuerpo = 3 brazos = 88 pantalon = 23 zapatos = 18
But I would like to know if there is any efficient way to do it with just one variable, like this:
Personaje: sprite = 183
Now what I want to know is how I can do to build a number based on the 5 values mentioned above and then break it down and get the 5 values again. Is there already a formula or algorithm for this?
This is more for knowing that out of necessity, I know that using arrays would solve everything easily.
I edit for those who are responding : Their solutions are good and very correct, but it's not exactly what I want, my solution should be more for mathematical knowledge / algorithms / equations than for programming solutions , the solutions that you are giving me are basically to create arrangements or types of data / classes. An example of what I want would be something similar to this:
ancho = 20 alto = 15 tamaño = ancho * alto mapa = Array.new(tamaño) mapa[x + y * ancho] = tile_id
Something similar to that I would like to achieve, in the only solution that I can get with my knowledge would be creating a buffer, so that:
buffer = "000000000000000" #=> Cada 3 digitos es un valor
example of use:
cabeza = 5 cuerpo = 49 brazos = 0 pantalon = 186 zapatos = 650 buffer += cabeza #=> "005 000 000 000 000" buffer += cuerpo #=> "005 049 000 000 000" buffer += brazos #=> "005 049 000 000 000" buffer += pantalon #=> "005 049 000 186 000" buffer += zapatos #=> "005 049 000 186 650" valor final de buffer = "005049000186650"
It is a solution, but still you have to establish the size of the buffer and it is not a mathematical formula that I would like to know, thank you all for your comments and answers! :)