public void StepChanged(Step s) { s.SetDirty(true); // Check for input item conditions if (s.GetInput() is FoodState) { FoodState input = (FoodState)(s.GetInput()); if (ItemClonedIntoPreviousStep(input, s.GetStepNumber())) { DestroyItem(input.gameObject); } } else if (s.GetInput() is FoodStateGroup) { FoodStateGroup input = (FoodStateGroup)(s.GetInput()); if (GroupClonedIntoPreviousStep(input, s.GetStepNumber())) { DestroyItem(input.gameObject); } } // Wrong type of item is dropped into input zone else { if (s.inputZoneRef.transform.childCount == 1) { DestroyItem(s.inputZoneRef.transform.GetChild(0).gameObject); } } // Check for output item conditions if (s.GetOutput() is FoodState) { FoodState outputToBeRemoved = (FoodState)(s.GetOutput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); } else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup outputToBeRemoved = (FoodStateGroup)(s.GetOutput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); } // Wrong type of item is dropped into action zone if (s.GetPseudoAction() == null) { if (s.actionZoneRef.transform.childCount == 1) { DestroyItem(s.actionZoneRef.transform.GetChild(0).gameObject); } } // Finally recalculate outputs of each step RegenerateSteps(); }
//Using the timer to change the state of the hunger need and calling to update the food ui private void UpdateFoodData(object sender, ElapsedEventArgs e) { TimeSpan foodTimeElapsed = e.SignalTime - foodTimeKeeper.FoodStartTime; FoodState newFoodState = yoshi.CurrentFoodState; if (foodTimeElapsed.TotalSeconds < 10) { newFoodState = FoodState.good; } else if (foodTimeElapsed.TotalSeconds < 20) { newFoodState = FoodState.normal; } else if (foodTimeElapsed.TotalSeconds >= 20) { newFoodState = FoodState.bad; } if (newFoodState != yoshi.CurrentFoodState) { yoshi.CurrentFoodState = newFoodState; updateFoodUI(); } }
public void DropFood() { int score = this.snakeState.score / 2; float delta = 0.1f; float d = delta; float radius = this.snakeState.GetSnakeThickness(); int ds = score; Vector2 curr = this.snakeState.GetHeadPosition(); while (d <= this.snakeState.GetSnakeLength()) { if (ds <= 0) { break; } FoodState food = GameObject.Instantiate <FoodState>(this.foodPrefab); food.transform.position = curr + new Vector2(Random.Range(-radius, +radius), Random.Range(-radius, +radius)); food.weight = Mathf.Min(Random.Range(2, 8), ds); ds -= food.weight; d += delta; curr = this.snakeState.CalcBackboneParametizedPosition(d); } }
/// <summary> /// 食物参数函数入口 /// </summary> /// <param name="type">物品类别,这里只实现food</param> /// <param name="id">物品编号</param> /// <param name="quality">物品品质</param> /// <param name="state">食物目前的状态</param> public void SetInventory(ItemType type, int id, ItemQuality quality, FoodState state) { this.Type = type; this.ID = id; this.Quality = quality; this.State = state; }
public void changeState(FoodState newState) { currentState.gameObject.SetActive(false); newState.gameObject.SetActive(true); newState.currentTime = 0; currentState = newState; }
void Start() { int currentX = startX; int currentY = startY; int loopCount = 0; foreach (GameObject o in foodList) { GameObject newPickupZone = GameObject.Instantiate(dummyPickupZoneRef); newPickupZone.transform.SetParent(viewportContentRef.transform, false); string foodName = o.GetComponent <FoodStatus>().foodIdentifier; newPickupZone.GetComponentInChildren <Text>().text = foodName; RectTransform rt = newPickupZone.GetComponent <RectTransform>(); FoodState newFoodState = newPickupZone.GetComponentInChildren <FoodState>(); Vector3 newPos = new Vector3(startX + spacingX * (loopCount % itemCountPerRow), startY + (((loopCount) / itemCountPerRow) * spacingY), 0); rt.anchoredPosition3D = newPos; newPickupZone.gameObject.name = foodName + "PickupZone"; newFoodState.gameObject.name = foodName; loopCount++; } }
// Head collision logic (todo: move) void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Food") { FoodState food = other.gameObject.GetComponent <FoodState>(); this.score += food.CollectFood(this); } }
// Use this for initialization void Start() { this.foodState = this.gameObject.GetComponent <FoodState>(); this.scaleFactorUnsmoothed = this.foodState.scaleFactor; // Vary food collection rates this.foodGrowthSpeed += Random.Range(0.0f, 2.0f); }
protected virtual void BurnedFood() { currentState = FoodState.Burned; gameObject.GetComponent <MeshRenderer>().material.SetColor("_Color", burnedColor); cookedSteam.SetActive(false); burnedSmoke.SetActive(true); StartCoroutine(DestroyBurned()); }
private void DropFoodAtTail() { FoodState food = this.gameObject.GetComponent <LocalSnakeBody>().foodPrefab; GameObject.Instantiate <FoodState>(food); food.transform.position = this.CalcBackboneParametizedPosition(this.GetSnakeLength()); food.weight = GameConfig.FOOD_WEIGHT_DROP_TURBO; this.score -= food.weight * 2; }
private void GenerateFoods() { for (int i = 0; i < maxFoods; i++) { FoodState food = Instantiate <FoodState>(this.localFoodPrefab); food.transform.position = this.gameWorld.GenerateRandomWorldPoint(0.0f, this.gameWorld.worldRadius); food.weight = (int)Random.Range(2.0f, 8.0f); } }
public Step GetNextRelatedStep(Step prevStep) { // Check if this food/foodGroup is used for creating a new group foreach (GroupFromSteps gfs in groups) { if (gfs.boundedSteps.Contains(prevStep)) { // Check if this group is used as input in a step foreach (Step s in steps) { if (s.GetInput() is FoodStateGroup) { if ((FoodStateGroup)(s.GetInput()) == gfs.GetFoodStateGroup().clone) { return(s); } } } } } if (prevStep.GetOutput() is FoodState) { FoodState prevFs = (FoodState)prevStep.GetOutput(); // Check if this food is used as input in a step foreach (Step s in steps) { if (s.GetInput() is FoodState) { if ((FoodState)(s.GetInput()) == prevFs.clone) { return(s); } } } } else if (prevStep.GetOutput() is FoodStateGroup) { FoodStateGroup prevFsg = (FoodStateGroup)prevStep.GetOutput(); // Check if this food group is used as input in a step foreach (Step s in steps) { if (s.GetInput() is FoodStateGroup) { if ((FoodStateGroup)(s.GetInput()) == prevFsg.clone) { return(s); } } } } return(null); }
private void Start() { if (!TryGetComponent(out sp)) { throw new Exception("SpriteRenderer is MISSING"); } CurrentState = foodState[nbHit]; sp.sprite = CurrentState.FoodStatesSprite; }
//State Change calls (call from other scripts. public void Pickup(GameObject other) { //pass ref to this object to player (for shooting and eating, and type.) player = other; foodState = FoodState.Held; offset = Vector3.zero; // this.transform.position - other.transform.position; }
// Use this for initialization void Start() { petrolPointA = transform.localPosition; //petrolPointB = new Vector2(Random.Range(-29, 29), Random.Range(-29, 29)); petrolPointB = new Vector2(29, 29); currentState = FoodState.patrol; currentDestination = petrolPointB; playerTrans = GameObject.Find("Player").transform; }
private void ServiceNormalState() { if (this.current_tick * Time.deltaTime > sec_til_turn_bad) { this.swap_img(); this.current_tick = 0; this.current_state = FoodState.BadState; audioEffect.Play(); } ++this.current_tick; }
public void TestMethod1() { var FoodStates = new FoodStates(); FoodState foodState = FoodState.good; var expectedResult = "good"; FoodState result = FoodStates.GetFoodState(expectedResult); Assert.AreEqual(foodState, result); }
public void Smash() { player = null; foodState = FoodState.None; //reset the player, reset the food's player, reset the foodstate. this.gameObject.SetActive(false); flyClone.source.Stop(); // this Does work //sets up nicely for possible pooling later on }
protected override void Kill() { nbHit++; if (nbHit < foodState.Length) { CurrentState = foodState[nbHit]; sp.sprite = CurrentState.FoodStatesSprite; } else { Destroy(gameObject); } }
private bool CheckIfFoundPlayer() { var dist = GetPlayerDistance(); if (dist > followDistance) { currentState = FoodState.patrol; return(false); } timer = 4.0f; currentState = FoodState.follow; return(true); }
//call on player, when press trigger. (this instance already passed.) public void Launched(float angle) { //set speed and transforming //calculate xspeed and yspeed with trig, set to Vector3 xspeed = Mathf.Cos(angle * Mathf.Deg2Rad) * maxSpeed; yspeed = Mathf.Sin(angle * Mathf.Deg2Rad) * maxSpeed; speedWagon = new Vector3(xspeed, yspeed); foodState = FoodState.Shot; //sound flyClone.source.Play(); }
// This function returns true if item given as parameter is cloned into a previous step. public bool ItemClonedIntoPreviousStep(FoodState fs, int stepNo) { foreach (Step s in steps) { if (s.GetOutput() is FoodState) { FoodState outputFood = (FoodState)(s.GetOutput()); if (outputFood.clone == fs && stepNo < s.GetStepNumber()) { return(true); } } } return(false); }
public static string GetFoodString(FoodState foodState) { switch (foodState) { case FoodState.good: return("good"); case FoodState.normal: return("normal"); case FoodState.bad: return("bad"); default: return("dead"); } }
public void FoodTestMethod() { var FoodStates = new FoodStates(); FoodState foodState = FoodState.good; var expectedResult = "good"; FoodState result = FoodStates.GetFoodState(expectedResult); Assert.AreEqual(foodState, result); //Trying to use get string rather than get state (Doesnt Work) //var FoodStates = new FoodStates(); //FoodState foodState = FoodState.good; //var expectedResult = "good"; //FoodState result = FoodStates.GetFoodString(foodState expectedResult); //Assert.AreEqual(expectedResult, result); }
public void CreatePanel(ItemType type, int id, ItemQuality quality, FoodState state = FoodState.good) { GameObject go = GameObject.Instantiate(go_Inventory, transform.position, Quaternion.identity, transform); //先生成InventoryGameObject inventory = go.GetComponent <Inventory>(); //获取脚本后,调用SetInventory函数,这个函数有3个重载,通过传入不同的参数可以生成不同的物品 go.transform.SetParent(panel.transform); if (type == Inventory.ItemType.food) { inventory.SetInventory(type, id, quality, Inventory.FoodState.good); } else if (type == Inventory.ItemType.other) { inventory.SetInventory(type, id); } else { inventory.SetInventory(type, id, quality); } }
//private Rigidbody2D rbody; void Awake() { this.foodState = this.GetComponent <FoodState>(); this.foodView = this.GetComponent <FoodView>(); this.foodView.scaleFactor = 0.0f; this.circleCollider = this.gameObject.GetComponent <CircleCollider2D>(); if (this.circleCollider == null) { this.circleCollider = this.gameObject.AddComponent <CircleCollider2D>(); } this.circleCollider.isTrigger = true; this.circleCollider.radius = 0.0f; this.tag = "Food"; //this.transform.position = this.foodState.position; }
public void SyncFoods(FoodState[] foodList) { for (int i = 0; i < foodList.Length; i++) { FoodState food = foodList[i]; if (!m_allFoods.ContainsKey(food.guid)) { TableFoodPos tFood = TableManager.instance.GetPropertiesById <TableFoodPos>(food.tableId); GameObject go = (GameObject)Object.Instantiate(Resources.Load(tFood.modelPath)); FoodCtrl _ctrl = go.GetComponent <FoodCtrl>(); if (_ctrl == null) { _ctrl = go.AddComponent <FoodCtrl>(); } _ctrl.name = "Food_" + food.guid; _ctrl.guid = food.guid; m_allFoods.Add(food.guid, _ctrl); } m_allFoods[food.guid].Sync(food); } }
public bool CheckGroupEligibility(Step s) { // If this step is already grouped, we cannot regroup it. if (s.GetHasGroup()) { return(false); } // If output is used in another step, we can't group this step anymore. if (s.GetOutput() is FoodState) { FoodState fs = (FoodState)s.GetOutput(); if (fs.clone != null) { return(false); } } else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup fsg = (FoodStateGroup)s.GetOutput(); if (fsg.clone != null) { return(false); } } // There is no output else { return(false); } // It can be grouped return(true); }
public void MarkRefsAsDirty(FoodStateGroup foodStateGroup) { if (foodStateGroup == null) { return; } foreach (Step s in steps) { if (s.GetInput() is FoodStateGroup && (FoodStateGroup)(s.GetInput()) == foodStateGroup) { s.SetDirty(true); if (s.GetOutput() is FoodState) { FoodState outputToBeRemoved = (FoodState)(s.GetOutput()); FoodState inputToBeRemoved = (FoodState)(s.GetInput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); DestroyItem(inputToBeRemoved.gameObject); break; } else if (s.GetOutput() is FoodStateGroup) { FoodStateGroup outputToBeRemoved = (FoodStateGroup)(s.GetOutput()); FoodStateGroup inputToBeRemoved = (FoodStateGroup)(s.GetInput()); MarkRefsAsDirty(outputToBeRemoved.clone); DestroyItem(outputToBeRemoved.gameObject); DestroyItem(inputToBeRemoved.gameObject); break; } } } }
//Pooling functionality public void OnObjectSpawn() { //spawn set food state to none foodState = FoodState.None; if (player != null) { Debug.Log("Spawn Error: A held food has Respawned"); Smash(); } //clear up prisoner #region OnSpawn //mathf will pick even numbers on .5, may need your own math here. int foodNumber = Mathf.RoundToInt(Random.Range(0.0f, 2.0f)); // Randomizes the FoodType foodType = (Food.FoodType)foodNumber; // Sets the FoodType enum using the random number //DEBUG: say type //Debug.Log("I am a " + foodType); //SPRITE RENDERING //set food sprite switch (foodType) { case FoodType.Carbs: { // setup carb foodTexture = Resources.Load <Texture2D>("sprites/bread"); break; } case FoodType.Proteins: { // setup proteins foodTexture = Resources.Load <Texture2D>("sprites/egg"); break; } case FoodType.Vegetable: { // setup vegetables foodTexture = Resources.Load <Texture2D>("sprites/tomato"); break; } default: { Debug.Log("No foodType specified. Refusing to instantiate Food Object."); break; } } //Sprite render foodSprite = Sprite.Create(foodTexture, new Rect(0, 0, foodTexture.width, foodTexture.height), Vector2.zero); spriteRenderer.sprite = foodSprite; //getting collider to match sprite foodBox.size = spriteRenderer.size; //foodBox.offset = new Vector2((spriteRenderer.size.x / 2), (spriteRenderer.size.y / 2)); Is Implied, with all our current sprites. //generate location to check Vector2 spawnLocation = new Vector2(Random.Range(-6.75f, 6.75f), Random.Range(-2.25f, 2.25f)); // Sets the random location of food spawn within a certain area // check an area around the food to see if another food overlaps, if so then move the spawn location to another spot Collider2D foodInArea = Physics2D.OverlapCircle(spawnLocation, 1.0f); while (foodInArea != null) { spawnLocation = new Vector2(Random.Range(-5.0f, 5.0f), Random.Range(-1.75f, 1.75f)); // checks a smaller area if the first location is too close foodInArea = null; // reset array foodInArea = Physics2D.OverlapCircle(spawnLocation, 1f); // check again //Debug.Log("Foodinarea:" + foodInArea); } //set position foodObject.transform.position = spawnLocation; //Debug.Log("I Shmoove to " + spawnLocation); #endregion }