/// <summary> return the addition of two colors /// Precondition: input must be on of the basic colors /// Invalid colors default to black /// </summary> /// <param name="color2"></param> second color to be added /// <returns></returns> color of the combination public GameColor add(GameColor otherColor) { if (this.Equals(otherColor)) { return(this); } else if (getColorName() == "clear" || getColorName() == "white") { return(otherColor); } else if (otherColor.getColorName() == "clear" || otherColor.getColorName() == "white") { return(this); } else if (colorsPresent(otherColor, "red", "blue")) { return(new GameColor("purple")); } else if (colorsPresent(otherColor, "red", "yellow")) { return(new GameColor("orange")); } else if (colorsPresent(otherColor, "blue", "yellow")) { return(new GameColor("green")); } else { return(new GameColor("black")); } }
/// <summary> return if some combination of colorName1 and colorName2 is present in color inputs /// /// </summary> /// <param name="otherColor"></param> second color to check agaibst name 1 or 2 /// <param name="colorName1"></param> name of first to try and find /// <param name="colorName2"></param> name of second color to find /// <returns></returns> if color1 is colorname1, or colorname2 and otherColor is the inverse private bool colorsPresent(GameColor otherColor, string colorName1, string colorName2) { if (getColorName() == colorName1 && otherColor.getColorName() == colorName2) { return(true); } else if (getColorName() == colorName2 && otherColor.getColorName() == colorName1) { return(true); } else { return(false); } }
/// <summary> /// GameTexture from existing GameTexture /// </summary> /// <param name="orginalTexture"></param> starting Texture 2D public GameTexture(GameTexture orginalTexture) { width = orginalTexture.width; height = orginalTexture.height; totalColors = new GameColor[width, height]; blackLayers = new int[width, height]; tex = new Texture2D(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GameColor color = orginalTexture.GetPixel(x, y); if (color.getColorName().Equals("black")) { blackLayers[x, y] = 1; } else { blackLayers[x, y] = 0; } totalColors[x, y] = color; } } }
/// <summary> /// Contruct game texture from 2d array of color strings /// </summary> /// <param name="colorStrings"></param> public GameTexture(string[,] colorStrings) { width = colorStrings.GetLength(0); height = colorStrings.GetLength(0); totalColors = new GameColor[width, height]; blackLayers = new int[width, height]; tex = new Texture2D(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GameColor color = new GameColor(colorStrings[x, y]); if (color.getColorName().Equals("black")) { blackLayers[x, y] = 1; } else { blackLayers[x, y] = 0; } totalColors[x, y] = color; } } }
/// <summary> /// add all colors from texToAdd to this /// </summary> /// <param name="texToAdd"></param> GameTexture we want to add public void addTexture(GameTexture texToAdd) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GameColor color = texToAdd.GetPixel(x, y); if (color.getColorName().Equals("black")) { blackLayers[x, y]++; } if (blackLayers[x, y] > 0) { totalColors[x, y] = new GameColor("black"); } else if (blackLayers[x, y] < 0) { totalColors[x, y] = new GameColor("clear"); } else { totalColors[x, y] = GetPixel(x, y).add(color); } } } }
/// <summary> return comination of colors apart from color /// /// /// </summary> /// <param name="color"></param> color to subtract from black from /// <returns></returns> all color combination expect selected color private GameColor subtractFromBlack(GameColor color) { if (color.getColorName() == "red") { return(new GameColor("green")); } else if (color.getColorName() == "blue") { return(new GameColor("orange")); } else if (color.getColorName() == "yellow") { return(new GameColor("purple")); } else if (color.getColorName() == "orange") { return(new GameColor("blue")); } else if (color.getColorName() == "purple") { return(new GameColor("yellow")); } else if (color.getColorName() == "green") { return(new GameColor("red")); } else if (color.getColorName() == "clear") { return(new GameColor("black")); } else { return(new GameColor("white")); } }
public bool Equals(GameColor otherColor) { if (colorsPresent(otherColor, "white", "clear")) { return(true); } else { return(getColorName().Equals(otherColor.getColorName())); } }
public string[,] GetColorStrings() { string[,] returnString = new string[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { GameColor color = GetPixel(x, y); returnString[x, y] = color.getColorName(); } } return(returnString); }
/// <summary> subtract one color from the other /// invalid colors default to clear /// /// </summary> /// <param name="otherColor"></param> color to subtract /// <returns></returns> valid color for color1 - otherColor public GameColor subtract(GameColor otherColor) { if (Equals(otherColor)) { return(new GameColor("white")); } else if (getColorName() == "clear" || getColorName() == "white") { return(new GameColor("clear")); } else if (otherColor.getColorName() == "clear" || otherColor.getColorName() == "white") { return(this); } else if (getColorName() == "purple" && otherColor.getColorName() == "red") { return(new GameColor("blue")); } else if (getColorName() == "purple" && otherColor.getColorName() == "blue") { return(new GameColor("red")); } else if (getColorName() == "green" && otherColor.getColorName() == "yellow") { return(new GameColor("blue")); } else if (getColorName() == "green" && otherColor.getColorName() == "blue") { return(new GameColor("yellow")); } else if (getColorName() == "orange" && otherColor.getColorName() == "red") { return(new GameColor("yellow")); } else if (getColorName() == "orange" && otherColor.getColorName() == "yellow") { return(new GameColor("red")); } else if (getColorName() == "blue" && (otherColor.getColorName() == "purple" || otherColor.getColorName() == "green")) { return(new GameColor("white")); } else if (getColorName() == "red" && (otherColor.getColorName() == "purple" || otherColor.getColorName() == "orange")) { return(new GameColor("white")); } else if (getColorName() == "yellow" && (otherColor.getColorName() == "orange" || otherColor.getColorName() == "green")) { return(new GameColor("white")); } else { return(this); } }