- Home /
Painting Scoring system
Is their a way to get a texture and have it so that if a player paints one of the pixels with the right color, he gets 5 points. For example I have a 2d pixel apple. The player has to try and redraw the apple as best as he could. If he uses red and paints the apple correctly, he gets those 5 points. Is it possible for something like this and if so, what are some of the steps to create this?
Do you have any of the functionality in place yet? How are you letting the user choose a color to use?
Answer by Temseii · May 24, 2018 at 06:34 PM
private Color chosenColor;
private int _points;
private Color AppleColor { get { return Color.red; } }
private void CheckColor() {
if(chosenColor == AppleColor) {
_points += 5;
}
}
Something like that?
I belive the script would be more complex than that. The apple was used as an example but what would happen is that the user has to redraw famous paintings. He would be able to pick what color to use by using a RGB color selector. To make things easier for the player there it wouldnt be the exact color but one thats close.
I'm sure it will be. Have you written any sort of base for what you're trying to do here or are you trying to get it done for you? It's a little hard to say where your skill level is at and how much help you actually need without you having submitted any code with your post.
I was using a color picker I found as a base for picking a color. I am working on the drawing mechanic using the color picker. I wanted to know if there was a way to have a scoring system depending on what you paint.
Here is the link to the color picker im using.
Answer by Tobychappell · May 24, 2018 at 10:39 PM
An approach that i think might work is that when the painting is done, you'd compare pixel by pixel (or maybe a 4x4 group of pixels that have their color averaged) of the original(source) and the new painting(target). You may want to give tolerances as getting the EXACT color value will be next to impossible (1 / 2^24 ?). If you exclude the alpha channel and just work with RGB, you get a Vector3. So this tolerance can be the 'max distance' from source to target. and possibly have tiers of tolerances that correspond to points awarded.
demo code:
Texture2D source;
Texture2D target;
float maxTolerance = 1.0f / 16.0f;
void CheckTextures()
{
if(source == null || target == null)
{
Debug.Log("source or target texture not initialised");
return;
}
if(source.width != target.width || source.height != target.height)
{
Debug.Log("source and target textures are not the same width or height");
return;
}
for (int x = 0; x < source.width; x++)
{
for (int y = 0; y < source.height; y++)
{
Color sourceColor = source.GetPixel(x,y);
Color targetColor = target.GetPixel(x,y);
Vector3 sourcePos = new Vector3(sourceColor.r, sourceColor.g, sourceColor.b);
Vector3 targetPos = new Vector3(targetColor.r, targetColor.g, targetColor.b);
if (Vector3.Distance(sourcePos, targetPos) <= maxTolerance)
{
// Grant points
}
}
}
}
Im getting this error error CS0103: The name `tex' does not exist in the current context
Your answer
Follow this Question
Related Questions
Painting terrain problem 12 Answers
Painting materials 1 Answer
Coloring 3d model using camera 0 Answers
Pause Time.time? 1 Answer
Im Doing HighScore System To My Game And There Is Something Wrong In My Scripts 0 Answers