//updates the unit according to current orders public void Update(float increment) { switch (State) { case "move": { Vector direction = new Vector(destination.X - Location.X, destination.Y - Location.Y); direction.Normalize(); Location.Add(direction * movespeed * increment); if(Location.DistanceTo(destination) < movespeed) { Console.WriteLine("unit is idle"); Location = new Point(destination.X, destination.Y); State = "idle"; } break; } case "idle": { Unit closestUnit = battle.GetUnitInRange(this, 100); if (closestUnit == null) { destination = new Point(battle.rand.RandInt(255), battle.rand.RandInt(255)); } else { battle.Shoot(closestUnit); } battle.AddMoveOrder(this, destination); break; } } }
//Add public void Add(Vector _v) { x += _v.X; y += _v.Y; }
//movement, bitches public void move(int increments) { //check if there's actually an order if (currentorder < orders.Count) { //get a direction vector Vector direction = new Vector(orders[currentorder].X - location.X, orders[currentorder].Y - location.Y); direction.Normalize(); //check if it's close enough to the point if (location.DistanceTo(orders[currentorder]) < MoveSpeed / increments) { location = orders[currentorder]; currentorder++; } //otherwise just move else { location.Add(direction * (MoveSpeed / increments)); } } }