public void SenseUpdate(){ if(BasicUpdate()) return; if(bonds[0].nodeA == this) viewDirection = -bonds[0].dirAtoB; else viewDirection = bonds[0].dirAtoB; signal = 0f; if(bonds[0].bondType == BondType.signal){ for(int i = 0; i < FoodPellet.GetAll().Count; i++){ FoodPellet currentPellet = FoodPellet.GetAll()[i]; float caloriesTaken = (0.5f / Mathf.Pow(Vector3.Distance(transform.position, currentPellet.transform.position), 2)) * Time.deltaTime * 50f; assembly.calories += caloriesTaken; currentPellet.calories -= caloriesTaken; if(CanSee(currentPellet)) signal += 3f / (Vector3.Distance(transform.position, currentPellet.transform.position) * 0.2f); } if(!arcBillboard) MakeArcBillboard(); } else{ if(arcBillboard) RemoveArcBillboard(); } billboardColor = renderer.material.color; billboardColor.a = signal; // Sense node cone of vision is opposite to bond direction. arcDirection = Quaternion.LookRotation(viewDirection); }
public void LoadContent(ContentManager c) { Texture2D foodtex = c.Load <Texture2D>(@"Art/StrawberryItem"); for (int i = 0; i < 50; i++) { FoodPellet np = new FoodPellet(); np.LoadContent(foodtex); np.Deactivate(); PelletList.Add(np); } }
private void GetFood() { FoodPellet np = PelletList.Find(x => x._CurrentState == Sprite.SpriteState.kStateInActive); if (np != null) { np.Activate(InputHelper.MouseScreenPos); } else { np = new FoodPellet(); np.LoadContent(@"Art/SlimeShot", Content); np._Position = InputHelper.MouseScreenPos; PelletList.Add(np); } }
private void RealFishMove(GameTime gt, List <Items.FoodPellet> pList) { hungerTimer -= gt.ElapsedGameTime.TotalSeconds; if (closestPellet != null && closestPellet._CurrentState == SpriteState.kStateInActive) { closestPellet = null; fishStatus = FishStatus.kStatusRoam; } if (hungerTimer < 0) { Hunger++; hungerTimer = 0.5f; if (fishStatus == FishStatus.kStatusRoam) { if (hunger > 40) { fishStatus = FishStatus.kStatusFood; } } } if (fishStatus == FishStatus.kStatusRoam) { moveTimer -= gt.ElapsedGameTime.TotalSeconds; if (moveTimer <= 0) { moving = true; Random ran = new Random(); moveTimer = ran.Next(0, 8); targetPos.X = ran.Next(10, 750); targetPos.Y = ran.Next(85, 450); } } else if (fishStatus == FishStatus.kStatusFood) { if (pList.FindAll(x => x._CurrentState == SpriteState.kStateActive).Count > 0) { float closestDistance = 100000; foreach (Items.FoodPellet p in pList.FindAll(x => x._CurrentState == SpriteState.kStateActive)) { //find closest pellet. if (p._Position.Y < 70) { continue; } float currentDistance = Vector2.Distance(this.FishMouth.Location.ToVector2(), p._Position); if (currentDistance < closestDistance) { closestPellet = p; closestDistance = currentDistance; } } } if (closestPellet != null) { targetPos = closestPellet._Position; moving = true; if (closestPellet._CurrentState == SpriteState.kStateInActive || closestPellet._Position.Y < 70) { moving = false; if (_FlipX) { MyDir = CurrentDirection.kDirectionLeft; } else { MyDir = CurrentDirection.kDirectionRight; } } if (closestPellet._BoundingBox.Intersects(this.FishMouth)) { closestPellet.Deactivate(); closestPellet = null; Hunger -= 50; moving = false; fishStatus = FishStatus.kStatusRoam; this._Scale.X += 0.3f; this._Scale.Y += 0.3f; if (this._Scale.X > 2.0f) { this._Scale.X = 2.0f; this._Scale.Y = 2.0f; } } } else { fishStatus = FishStatus.kStatusRoam; } } //else if(fishStatus == FishStatus.kStatusDead) //{ // this._Rotation = MathHelper.ToRadians(180); // if(this._Position.Y > 70) // { // float speed = 100f; // this._Position.Y -= (float)(speed * gt.ElapsedGameTime.TotalSeconds); // } //} //if (InputHelper.LeftButtonClicked) //{ // moving = true; // targetPos = InputHelper.MouseScreenPos; //} //if(Hunger >= 100) //{ // this.fishStatus = FishStatus.kStatusDead; //} if (moving) { float speed = 100f; if (Math.Abs((this.FishMouth.Location.ToVector2().X - targetPos.X)) > 5) { if (this.FishMouth.Location.ToVector2().X < targetPos.X) { this._Position.X += speed * (float)gt.ElapsedGameTime.TotalSeconds; if (Math.Abs((this.FishMouth.Location.ToVector2().X - targetPos.X)) > 20) { this._FlipX = false; MyDir = CurrentDirection.kDirectionRight; } } else if (this.FishMouth.Location.ToVector2().X > targetPos.X) { this._Position.X -= speed * (float)gt.ElapsedGameTime.TotalSeconds; if (Math.Abs((this.FishMouth.Location.ToVector2().X - targetPos.X)) > 20) { this._FlipX = true; MyDir = CurrentDirection.kDirectionLeft; } } } if (Math.Abs((this.FishMouth.Location.ToVector2().Y - targetPos.Y)) > 5) { if (this.FishMouth.Location.ToVector2().Y < targetPos.Y) { this._Position.Y += speed * (float)gt.ElapsedGameTime.TotalSeconds; if (Math.Abs((this.FishMouth.Location.ToVector2().Y - targetPos.Y)) > 15) { if (_FlipX) { //this._Rotation = MathHelper.ToRadians(-45); MyDir = CurrentDirection.kDirectionLeft; } else { //this._Rotation = MathHelper.ToRadians(45); MyDir = CurrentDirection.kDirectionRight; } } } else if (this.FishMouth.Location.ToVector2().Y > targetPos.Y) { this._Position.Y -= speed * (float)gt.ElapsedGameTime.TotalSeconds; if (Math.Abs((this.FishMouth.Location.ToVector2().Y - targetPos.Y)) > 15) { if (_FlipX) { //this._Rotation = MathHelper.ToRadians(45); MyDir = CurrentDirection.kDirectionLeft; } else { //this._Rotation = MathHelper.ToRadians(-45); MyDir = CurrentDirection.kDirectionRight; } } } } else { this._Rotation = 0; } if (Vector2.Distance(this.FishMouth.Location.ToVector2(), targetPos) < 10) { moving = false; this._Rotation = 0; if (_FlipX) { MyDir = CurrentDirection.kDirectionLeft; } else { MyDir = CurrentDirection.kDirectionRight; } } } if (closestPellet != null) { pelletLastFrame = true; } else { pelletLastFrame = false; } }
} // End of BasicUpdate(). public bool CanSee(FoodPellet food) { return (nodeType == NodeType.sense) && (Vector3.Angle(viewDirection, food.transform.position - transform.position) < viewAngle); }