public void GameStart() { foreach (var liquid in liquids) { if (liquid.ingredient != null) { liquid.ingredient.Liquid = null; } liquid.type = LiquidType.None; } if (GlassShape == null) { GlassShape = new List <Polyline>(4); } else { GlassShape.Clear(); } Sum = 0.0f; BeerHead = null; BeerHeadTimer = 0.0f; liquids.Clear(); updateNeeded = true; }
public void DeleteLiquid(GlassLiquid liquid) { if (liquid.ingredient != null) { liquid.ingredient.Liquid = null; if (liquid.ingredient.Measure == null) { liquid.ingredient.LiquidType = LiquidType.None; liquid.ingredient.Disable(); } } liquids.Remove(liquid); liquidsOrderChanged = true; }
public IngredientWin GetWin() { bool hasMeasure = HasMeasure(); bool hasLiquid = HasLiquid(); if (hasMeasure == false) { return(IngredientWin.Wrong); } if (hasLiquid == false) { return(IngredientWin.None); } int ml = 0; int target = Measure.Measure * 25; if (hasLiquid) { ml = Mathf.RoundToInt(GlassLiquid.AmountToMeasures(Liquid.amount, Glass.GlassType)) * 25; if (LiquidType == LiquidType.Beer && Glass.BeerHead != null) { ml += Mathf.RoundToInt(GlassLiquid.AmountToMeasures(Glass.BeerHead.amount, Glass.GlassType)) * 25; } } if (ml == 0) { return(IngredientWin.None); } else if (ml < target) { return(IngredientWin.Partial); } else if (GlassLiquid.MlApprox(ml, target)) { return(IngredientWin.Exact); } else if (ml >= target) { return(IngredientWin.Over); } else { return(IngredientWin.Wrong); } }
public void DoSetup(LiquidType lt, CocktailMeasure measure, Glass glass) { RefreshNeeded = true; LiquidType = lt; Text.enabled = true; Image.enabled = true; Liquid = null; Measure = measure; Glass = glass; if (Measure != null) { Image.sprite = TexNone; Won = IngredientWin.None; } else { Image.sprite = TexIncorrect; Won = IngredientWin.Wrong; } }
public LiquidType GetUniqueRandomLiquid(List <LiquidType> used, LiquidAlcohol al) { int steps = 0; while (steps++ < 100) { int idx = UnityEngine.Random.Range(0, used.Count); LiquidType lt = used[idx]; if (GlassLiquid.LiquidTypeToLiquidAlcohol(lt) != al || lt == LiquidType.BeerHead || lt == LiquidType.Beer) { continue; } used.Remove(lt); return(lt); } return(LiquidType.None); }
public void ControlUpdated() { if (Text == null) { Text = gameObject.GetComponentInChildren <Text>(); } if (Text != null) { if (Liquid != LiquidType.None) { Text.text = GlassLiquid.LiquidTypeToString(Liquid); } else if (Solid != SolidType.None) { Text.text = "Add " + GlassSolid.SolidTypeToString(Solid); } else { Text.text = String.Empty; } } }
public void Update() { if (RefreshNeeded) { RefreshNeeded = false; bool hasMeasure = HasMeasure(); bool hasLiquid = HasLiquid(); if (hasMeasure && Glass != null) { Won = GetWin(); switch (Won) { case IngredientWin.None: Image.sprite = TexNone; break; case IngredientWin.Partial: Image.sprite = TexMiddle; break; case IngredientWin.Exact: Image.sprite = TexCorrect; break; case IngredientWin.Over: Image.sprite = TexPlus; break; case IngredientWin.Wrong: Image.sprite = TexIncorrect; break; } if (hasLiquid && Glass != null) { float liquidAmount = Liquid.amount; if (Liquid.type == LiquidType.Beer && Glass.BeerHead != null) { liquidAmount += Glass.BeerHead.amount; } Text.text = GlassLiquid.LiquidTypeAndMlWithMeasureToString(liquidAmount, Measure.Amount, Liquid.type, Glass.GlassType); } else { Text.text = String.Format("{0}", Measure.Text); } } else if (hasLiquid) { Image.sprite = TexIncorrect; Text.text = GlassLiquid.LiquidTypeAndMeasureToStringFloatAmount(Liquid.amount, Liquid.type, Glass.GlassType); Won = IngredientWin.Wrong; } else { Image.sprite = TexIncorrect; Text.text = String.Format("??? {0} ", LiquidType); } } }
bool CheckControls(bool update) { //const float flowRate = 0.005f; float flowRate = Glass.GlassInfo.flowRate; // BEER - Left Thumb Stick, Pull Down float beerTap = Mathf.Abs(Mathf.Min(0.0f, Controls.LeftStickY)); if (beerTap > 0.0f) { float beerFlowRate = beerTap * 0.5f; float headFlowRate = beerTap * 0.25f; GlassLiquid beer = Pour(LiquidType.Beer, flowRate * beerFlowRate); GlassLiquid head = Pour(LiquidType.BeerHead, flowRate * headFlowRate); update = true; Glass.BeerHeadTimer = 0.0f; } else { if (Unpour(LiquidType.Beer) || Unpour(LiquidType.BeerHead)) { update = true; } } // Action and DPad buttons // Action2 if (Controls.Action2Down && Game.Tap_Action2.Liquid != LiquidType.None) { Pour(Game.Tap_Action2.Liquid, flowRate); update = true; } else if (Game.Tap_Action2.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Action2.Liquid)) { update = true; } } else if (Controls.Action2 && Game.Tap_Action2.Solid != SolidType.None) { AddSolid(Game.Tap_Action2.Solid); } // Action3 if (Controls.Action3Down && Game.Tap_Action3.Liquid != LiquidType.None) { Pour(Game.Tap_Action3.Liquid, flowRate); update = true; } else if (Game.Tap_Action3.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Action3.Liquid)) { update = true; } } else if (Controls.Action3 && Game.Tap_Action3.Solid != SolidType.None) { AddSolid(Game.Tap_Action3.Solid); } // Action4 if (Controls.Action4Down && Game.Tap_Action4.Liquid != LiquidType.None) { Pour(Game.Tap_Action4.Liquid, flowRate); update = true; } else if (Game.Tap_Action4.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Action4.Liquid)) { update = true; } } else if (Controls.Action4 && Game.Tap_Action4.Solid != SolidType.None) { AddSolid(Game.Tap_Action4.Solid); } // Up if (Controls.DPadUpDown && Game.Tap_Up.Liquid != LiquidType.None) { Pour(Game.Tap_Up.Liquid, flowRate); update = true; } else if (Game.Tap_Up.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Up.Liquid)) { update = true; } } else if (Controls.DPadUp && Game.Tap_Up.Solid != SolidType.None) { AddSolid(Game.Tap_Up.Solid); } // Right if (Controls.DPadRightDown && Game.Tap_Right.Liquid != LiquidType.None) { Pour(Game.Tap_Right.Liquid, flowRate); update = true; } else if (Game.Tap_Right.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Right.Liquid)) { update = true; } } else if (Controls.DPadRight && Game.Tap_Right.Solid != SolidType.None) { AddSolid(Game.Tap_Right.Solid); } // Down if (Controls.DPadDownDown && Game.Tap_Down.Liquid != LiquidType.None) { Pour(Game.Tap_Down.Liquid, flowRate); update = true; } else if (Game.Tap_Down.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Down.Liquid)) { update = true; } } else if (Controls.DPadDown && Game.Tap_Down.Solid != SolidType.None) { AddSolid(Game.Tap_Down.Solid); } // Left if (Controls.DPadLeftDown && Game.Tap_Left.Liquid != LiquidType.None) { Pour(Game.Tap_Left.Liquid, flowRate); update = true; } else if (Game.Tap_Left.Liquid != LiquidType.None) { if (Unpour(Game.Tap_Left.Liquid)) { update = true; } } else if (Controls.DPadLeft && Game.Tap_Left.Solid != SolidType.None) { AddSolid(Game.Tap_Left.Solid); } return(update); }
GlassLiquid Pour(LiquidType lt, float pourSize) { GlassLiquid glassLiquid = null; Pour pour = null; pourSize *= 0.35f; // Difficulty modifier for (int ii = 0; ii < pours.Count; ii++) { var p = pours[ii]; if (p.liquidType == lt) { pour = p; break; } } if (pour != null) { pour.isDown = true; pour.downTime += Time.deltaTime; pour.pourRate = pourSize; } else { pour = GetNewPour(); pour.liquidType = lt; glassLiquid = null; foreach (var liquid in Glass.liquids) { if (liquid.type == lt) { glassLiquid = liquid; break; } } if (glassLiquid == null) { for (int ii = 0; ii < Glass.liquids.Count; ii++) { var liquid = Glass.liquids[ii]; liquid.animate = false; } glassLiquid = new GlassLiquid(); glassLiquid.amount = 0.0f; glassLiquid.type = lt; glassLiquid.animationTimer = Time.time; Glass.liquidsOrderChanged = true; pour.liquid = glassLiquid; GlassLiquid topLiquid = Glass.GetTopLiquid(); bool hasHead = topLiquid != null && topLiquid.type == LiquidType.BeerHead; bool isHead = (lt == LiquidType.BeerHead); if (isHead) { glassLiquid.animate = true; Glass.liquids.Add(glassLiquid); Glass.BeerHead = glassLiquid; Glass.BeerHeadTimer = 0.0f; Debug.Log("Beer Head Add"); } else if (hasHead || Glass.Sum >= 1.0f) { glassLiquid.animate = false; Glass.liquids.Insert(0, glassLiquid); } else { glassLiquid.animate = true; Glass.liquids.Add(glassLiquid); } } else { pour.liquid = glassLiquid; } pour.downTime = 0.0f; pour.isDown = true; pour.pourRate = pourSize; } return(glassLiquid); }
public void SetUpControls() { int nbLiquids = (int)LiquidType.COUNT; List <SolidType> solids = new List <SolidType>(8); List <LiquidType> liquids = new List <LiquidType>(nbLiquids); for (int i = 0; i < nbLiquids; i++) { liquids.Add((LiquidType)i); } liquids.Remove(LiquidType.None); SetAlcholControl(0, LiquidType.None, SolidType.None); SetAlcholControl(1, LiquidType.None, SolidType.None); SetAlcholControl(2, LiquidType.None, SolidType.None); SetNotAlcholControl(0, LiquidType.None, SolidType.None); SetNotAlcholControl(1, LiquidType.None, SolidType.None); SetNotAlcholControl(2, LiquidType.None, SolidType.None); SetNotAlcholControl(3, LiquidType.None, SolidType.None); for (int measuresIi = 0; measuresIi < Cocktail.Measures.Count; measuresIi++) { CocktailMeasure measure = Cocktail.Measures[measuresIi]; SolidType solid = SolidType.None; // @TODO. Maybe part of measure? LiquidType liquid = LiquidType.None; liquid = measure.LiquidType; if (solid != SolidType.None) { solids.Add(solid); } if (liquid != LiquidType.None) { liquids.Remove(liquid); if (liquid == LiquidType.Beer) { continue; } LiquidAlcohol alcohol = GlassLiquid.LiquidTypeToLiquidAlcohol(liquid); if (alcohol == LiquidAlcohol.Yes) { if (RandomAddAlcholControl(liquid, solid) == false) { if (RandomAddNotAlcholControl(liquid, solid) == false) { Debug.LogError("Cannot fit in ingredients. Recipe too complicated"); } } } else { if (RandomAddNotAlcholControl(liquid, solid) == false) { if (RandomAddAlcholControl(liquid, solid) == false) { Debug.LogError("Cannot fit in ingredients. Recipe too complicated"); } } } } } // Actions for (int i = 0; i < 3; i++) { ControlMarker ctrl = GetAlcholControl(i); if (!(ctrl.Liquid == LiquidType.None && ctrl.Solid == SolidType.None)) { continue; } LiquidType lt = GetUniqueRandomLiquid(liquids, LiquidAlcohol.Yes); SetAlcholControl(i, lt, SolidType.None); } // DPad for (int i = 0; i < 4; i++) { ControlMarker ctrl = GetNotAlcholControl(i); if (!(ctrl.Liquid == LiquidType.None && ctrl.Solid == SolidType.None)) { continue; } LiquidType lt = GetUniqueRandomLiquid(liquids, LiquidAlcohol.No); SetNotAlcholControl(i, lt, SolidType.None); } }
void ReadCocktails() { Cocktails = new List <Cocktail>(40); String txt = CocktailsTxt.text; using (StringReader reader = new StringReader(txt)) { string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (String.IsNullOrEmpty(line)) { continue; } if (line[0] == '#') { continue; } String[] p = line.Split(';'); if (p.Length < 3) { continue; } Cocktail cocktail = new Cocktail(); Cocktails.Add(cocktail); cocktail.Name = p[0]; cocktail.Glass = GlassLiquid.GlassStringToEnum(p[1]); cocktail.Measures = new List <CocktailMeasure>(3); int left = GlassLiquid.GetGlassSizeInMeasures(cocktail.Glass); ; float glassMeasures = left; for (int i = 2; i < p.Length; i++) { string[] measureText = p[i].Split(new char[] { ' ' }, 2); if (measureText.Length != 2) { Debug.LogErrorFormat("Bad Measure: '{0}', in {1}", p[i], line); continue; } int measure = 0; Int32.TryParse(measureText[0], out measure); if (measure == 0) { measure = left; } String ingredientName = measureText[1]; LiquidType liquidType = GlassLiquid.LiquidStringToEnum(ingredientName); String humanText = GlassLiquid.LiquidTypeAndMlToString(measure * 25, liquidType, cocktail.Glass); CocktailMeasure cocktailMeasure = new CocktailMeasure(); cocktailMeasure.LiquidType = liquidType; cocktailMeasure.Measure = measure; cocktailMeasure.Text = humanText; cocktailMeasure.Amount = measure / glassMeasures; left -= measure; cocktail.Measures.Add(cocktailMeasure); } } } }
void UpdatePour() { Glass.Sum = 0.0f; bool reorderIngredients = false; // UI for (int liquidIi = 0; liquidIi < Glass.liquids.Count; liquidIi++) { var liquid = Glass.liquids[liquidIi]; Glass.Sum += liquid.amount; if (liquid.ingredient == null && liquid.type != LiquidType.BeerHead) { liquid.ingredient = FindIngredientUi(liquid.type); if (liquid.ingredient == null) { liquid.ingredient = MakeIngredientUi(liquid.type); if (liquid.ingredient) { liquid.ingredient.Liquid = liquid; liquid.ingredient.Glass = Glass; liquid.ingredient.Enable(); liquid.ingredient.DoUpdate(); liquid.ingredient.Update(); } } else { liquid.ingredient.Liquid = liquid; liquid.ingredient.Glass = Glass; } } } Glass.BeerHeadTimer += Time.deltaTime; // Beer Head if (Glass.BeerHead != null && Glass.BeerHead.type == LiquidType.BeerHead && Glass.BeerHeadTimer >= 0.1f) { GlassLiquid beer = Glass.FindLiquid(LiquidType.Beer); if (beer != null && beer.amount < 0.95f) { const float flowRate = 0.05f; float headAmount = Glass.BeerHead.amount; float headFlow = flowRate * Time.deltaTime; bool doDeleteHead = false; float newHeadAmount = headAmount - headFlow; if (newHeadAmount <= 0.0f) { doDeleteHead = true; headFlow = headAmount; } beer.amount += headFlow; Glass.BeerHead.amount -= headFlow; if (doDeleteHead) { Glass.DeleteLiquid(Glass.BeerHead); Glass.BeerHead = null; } Glass.updateNeeded = true; } } // Spilling if (Glass.Sum > 1.0f) { float upSum = 0.0f; GlassLiquid topLiquid = null; for (int liquidIi = 0; liquidIi < Glass.liquids.Count; liquidIi++) { GlassLiquid gl = Glass.liquids[liquidIi]; if (liquidIi == Glass.liquids.Count - 1) { topLiquid = gl; } else { upSum += gl.amount; } } if (topLiquid != null) { topLiquid.amount = 1.0f - upSum; if (topLiquid.amount <= 0.0f) { if (topLiquid.ingredient != null) { if (topLiquid.ingredient.HasMeasure() == false) { topLiquid.ingredient.LiquidType = LiquidType.None; topLiquid.ingredient.Disable(); } topLiquid.ingredient.Liquid = null; topLiquid.ingredient.RefreshNeeded = true; } Glass.DeleteLiquid(topLiquid); reorderIngredients = true; } else { topLiquid.animate = true; } Glass.updateNeeded = true; } } if (reorderIngredients) { OrderMeasures(); } // if (reorderIngredients || Mathf.Approximately(lastSum, Glass.Sum) == false) // { // // Debug.Log(GetWin()); // } lastSum = Glass.Sum; // A - Add Drink if (Controls.Action1) { SubmitDrink(); } }
void AddLiquids() { float hgw = glassWidth * 0.5f; float gwAmount = glassWidth * (1.0f / height); if (liquids != null) { float y0 = height - hgw; float amountY0 = 0.0f; for (int liquidIi = 0; liquidIi < liquids.Count; liquidIi++) { var liquid = liquids[liquidIi]; bool isTop = (liquidIi == liquids.Count - 1); float amountY1 = amountY0 + liquid.amount; float y1 = y0 - (height * liquid.amount); Color col = GlassLiquid.GetColour(liquid.type); Color colHead = GlassLiquid.GetColourHead(liquid.type); #region Animation if (liquid.animate) { const int nbTriangles = 17; const float tSpeed = 10.0f; const float offset = 0.05f; liquid.animatingWeights = true; { float n = liquid.visualWeights[0]; float tx = tSpeed * n * Time.deltaTime; n -= tx; if (n < 0.01f) { n = 0.0f; } liquid.visualWeights[0] = n; } { float n = liquid.visualWeights[nbTriangles - 1]; float tx = tSpeed * Time.deltaTime; n -= tx; if (n < 0.01f) { n = 0.0f; } liquid.visualWeights[nbTriangles - 1] = n; } for (int i = 0; i < 8; i++) { float n = liquid.visualWeights[i]; int other = i + 1; float m = liquid.visualWeights[other]; float tx = tSpeed * m * Time.deltaTime; m -= tx; if (m < 0.01f) { m = 0.0f; } n += tx; if (n > 1.0f) { n = 1.0f; } liquid.visualWeights[i] = n; liquid.visualWeights[other] = m; } for (int i = 16; i > 8; i--) { float n = liquid.visualWeights[i]; int other = i - 1; float m = liquid.visualWeights[other]; float tx = tSpeed * m * Time.deltaTime; m -= tx; if (m < 0.01f) { m = 0.0f; } n += tx; if (n > 1.0f) { n = 1.0f; } liquid.visualWeights[i] = n; liquid.visualWeights[other] = m; } if (Mathf.Approximately(liquid.pourSize, 0)) { float sumWeights = 0.0f; for (int i = 0; i < 17; i++) { sumWeights += liquid.visualWeights[i]; } if (sumWeights < 0.05f) { liquid.idleAnimator += Time.deltaTime; } else { liquid.idleAnimator = 0.0f; } if (liquid.idleAnimator > 0.50f) { liquid.animate = false; } } #if OLD_DRAWING_MODE PushQuad(new Vector3(-halfWidth + glassWidth, y0), new Vector3(halfWidth - glassWidth, y1), GlassLiquid.GetColour(liquid.type)); #else //float xx = FindGlassInner(halfWidth, liquid.amount); //PushQuad(new Vector3(-xx * width, y0), new Vector3(halfWidth - glassWidth * 0.5f, y1), GlassLiquid.GetColour(liquid.type)); float xx0 = Mathf.Abs(FindGlassX(amountY0)) * width; float xx1 = Mathf.Abs(FindGlassX(amountY1 - gwAmount)) * width; // PushQuad(new Vector3(-yy1 + glassWidth * 0.5f, y0), new Vector3(yy1 - glassWidth * 0.5f, y1), GlassLiquid.GetColour(liquid.type)); PushQuad(new Vector3(-xx1 + hgw, -y1), new Vector3(+xx1 - hgw, -y1), new Vector3(-xx0 + hgw, -y0), new Vector3(+xx0 - hgw, -y0), GlassLiquid.GetColour(liquid.type)); #endif float triangleWidth = ((xx1 * 2.0f) - (hgw * 2.0f)) / nbTriangles; liquid.animationTimer += Time.deltaTime; updateNeeded = true; float h = 0.0f; //-liquid.visualWeights[0]*0.125f; float ly = y1 + h; float lastOffset = offset; // PushQuad(new Vector3(-xx1 + hgw, y1 - 0.05f), new Vector3(xx1 - hgw, y1 - 0.10f), Color.green); for (int i = 0; i < nbTriangles; i++) { float tx0 = -xx1 + hgw + (i * triangleWidth); float tx1 = tx0 + triangleWidth; float ty = y1; h = -liquid.visualWeights[i] * 0.125f; PushTriangle2(new Vector3(tx0, ly), new Vector3(tx1, y1), new Vector3(tx0, y1), col, col, col); PushTriangle2(new Vector3(tx0, ly), new Vector3(tx1, ty + h), new Vector3(tx1, y1), col, col, col); if (i == 8) { liquid.centerY = ty + (h - offset); } PushTriangle(new Vector3(tx0, ly - lastOffset), new Vector3(tx1, ty + (h - offset)), new Vector3(tx0, ly), colHead); PushTriangle(new Vector3(tx0, ly), new Vector3(tx1, ty + h), new Vector3(tx1, ty + (h - offset)), colHead); ly = ty + h; } } #endregion else { float xx0 = Mathf.Abs(FindGlassX(amountY0)) * width; float xx1 = Mathf.Abs(FindGlassX(amountY1)) * width; liquid.centerY = y1; #if OLD_DRAWING_MODE PushQuad(new Vector3(-halfWidth + glassWidth, y0), new Vector3(halfWidth - glassWidth, y1), col); #else PushQuad(new Vector3(-xx1 + hgw, -y1), new Vector3(+xx1 - hgw, -y1), new Vector3(-xx0 + hgw, -y0), new Vector3(+xx0 - hgw, -y0), GlassLiquid.GetColour(liquid.type)); #endif if (isTop) { #if OLD_DRAWING_MODE PushQuad(new Vector3(-halfWidth, y1), new Vector3(halfWidth, y1 - 0.05f), colHead); #else PushQuad(new Vector3(-xx1 + hgw, y1), new Vector3(xx1 - hgw, y1 - 0.05f), colHead); #endif } } // Pouring Liquid if (Game.State == GameState.Pour && liquid.type != LiquidType.BeerHead && liquid.pourSize > 0) { int nbSplashes = 10; float hh = Mathf.Lerp(-height, liquid.centerY, 1.0f - liquid.pourSize); float ww = Mathf.Lerp(0.25f, 0.0f, 1.0f - liquid.pourSize); float splashWidth = (ww) / nbSplashes; float x0 = -ww * 0.5f; float yy = (liquid.centerY) + 0.5f; if (yy > height - glassWidth) { yy = height - glassWidth; } for (int i = 0; i < nbSplashes; i++) { Color c = col; if (Mathf.Tan(liquid.animationTimer * 2.0f + (i * 233.3292f)) >= 0.0f) { c = colHead; } PushQuad(new Vector3(x0, hh), new Vector3(x0 + splashWidth, liquid.centerY), c); PushFadeDownQuad(new Vector3(x0, liquid.centerY), new Vector3(x0 + splashWidth, yy), c); x0 += splashWidth; } } y0 = y1; amountY0 = amountY1; } } }