private void checkForPraysInRadar() { pray = null; velocity = 8; double deltaX, deltaY, distance, percentage; foreach (Pray p in prays) { deltaX = (p.getPosition().X - position.X); deltaY = (p.getPosition().Y - position.Y); distance = Math.Sqrt(((Math.Pow(deltaX, 2)) + (Math.Pow(deltaY, 2)))); if ((distance < radius) && (!p.isHunted()) && (!isHunting())) { pray = p; pray.setPredator(this); if (distance < size / 2) { pray.losesHealth(); } percentage = ((distance * 100) / radius); percentage = Math.Abs(percentage - radius); velocity = velocity + ((int)((percentage * velocity) / 100)); objective = pray.getPosition(); } } }
public void move() { checkForPraysInRadar(); if (isHunting()) { if (index == 0) { Point o = vA.getPoint(); Point d = pray.getPosition(); Point e; double thetaPray, thetaEdge, tempDiff, diff = 100; foreach (Edge ed in vA.getEdges()) { e = ed.getDestination().getPoint(); thetaPray = Math.Atan2((d.Y - o.Y), (d.X - o.X)); thetaEdge = Math.Atan2((e.Y - o.Y), (e.X - o.X)); tempDiff = Math.Abs(thetaPray - thetaEdge); if (tempDiff <= diff) { edge = ed; diff = tempDiff; } } vA.isOccupied(true); vA.updateTimer(); } if ((index + velocity) < edge.getPoints().Count) { index = index + velocity; position = edge.getPointAt(index); } else { vA = edge.getDestination(); position = vA.getPoint(); index = 0; } } else { if (index == 0) { edge = vA.getEdges().ElementAt(random.Next(0, vA.getEdges().Count)); } if ((index + velocity) < edge.getPoints().Count) { index = index + velocity; position = edge.getPointAt(index); } else { vA = edge.getDestination(); position = vA.getPoint(); index = 0; } } }