private void Form1_Paint(object sender, PaintEventArgs e) { Type type = new Robot().GetType(); Graphics g = e.Graphics; e.Graphics.FillRectangle(Brushes.White, new RectangleF(board.Location, board.Size)); Brush myBrush = new SolidBrush(System.Drawing.Color.Red); foreach (Robot r in board.Robots) { float arc = 360F / r.Sensors; int i = 0; for (float f = 225; Math.Ceiling(f) < 360 + 225; f += arc, i++) { //if (r.SensorReadings[i] > 0) { ((SolidBrush)myBrush).Color = Color.FromArgb(255, (byte)(255 * (1 - r.SensorReadings[i])), (byte)(255 * (1 - r.SensorReadings[i]))); g.FillPie(myBrush, r.Location.X - r.SensorRadius, r.Location.Y - r.SensorRadius, r.SensorRadius * 2, r.SensorRadius * 2, f, arc); g.DrawPie(Pens.Black, r.Location.X - r.SensorRadius, r.Location.Y - r.SensorRadius, r.SensorRadius * 2, r.SensorRadius * 2, f, arc); } //else // g.DrawPie(Pens.Black, r.Location.X - r.SensorRadius, r.Location.Y - r.SensorRadius, r.SensorRadius * 2, r.SensorRadius * 2, f, arc); } g.FillEllipse(Brushes.Blue, Utilities.Translate(new RectangleF(r.Location, board.RobotSize))); } for (int j = 0; j < board.Agents.Count; j++) { RoboAgent a = board.Agents[j]; g.FillEllipse(Brushes.Black, Utilities.Translate(new RectangleF(a.Location, board.FoodSize))); } }
public bool ProcessAgent(RoboAgent target) { if (target == this || Utilities.Distance(this, target) > SensorRadius) { return(false); } else { double angledelta = 2 * Math.PI / Sensors; double testangle = -3 * Math.PI / 4; float angle = (float)Math.Atan2(target.Location.Y - Location.Y, target.Location.X - Location.X); for (int j = 0; j < sensorReadings.Length; j++, testangle += angledelta) { if (testangle >= Math.PI) { testangle -= 2 * Math.PI; } if (angle >= testangle && angle <= testangle + angledelta) { sensorReadings[j] = 1; //sensorReadings[j] += 1 - (Utilites.Distance(this, target) / SensorRadius); return(true); } } sensorReadings[sensorReadings.Length - 1] = 1.0; //sensorReadings[sensorReadings.Length - 1] += 1.0 - (Utilites.Distance(this, target) / SensorRadius); return(true); } }
private void OnEnable() { moveInput = GetComponent <MoveInput>(); roboAgent = GetComponent <RoboAgent>(); if (moveInput.manual) { moveSpeed = 4f; rotateSpeed = 240f; } else { moveSpeed = 4f; rotateSpeed = 240f; } firstPosition = transform.position; firstRotation = transform.eulerAngles; gimbalObject = transform.Find("Gimbal").gameObject; gimbalHeadObject = gimbalObject.transform.Find("Gimbal Head").gameObject; fixedPivot = transform.Find("Fixed Pivot").transform; hGimbalPivot = transform.Find("H Gimbal Pivot").transform; vGimbalPivot = gimbalObject.transform.Find("V Gimbal Pivot").transform; roboRigidbody = GetComponent <Rigidbody>(); gimbalRigidbody = gimbalObject.GetComponent <Rigidbody>(); gimbalHeadRigidbody = gimbalHeadObject.GetComponent <Rigidbody>(); pathFinder = GetComponent <NavMeshAgent>(); pathFinder.enabled = false; pathFinder.speed = moveSpeed; pathFinder.angularSpeed = rotateSpeed; }
private void OnEnable() { vMove = 0; hMove = 0; vGimbalRotate = 0; hGimbalRotate = 0; rotate = 0; fire = false; reload = false; wobble = false; wobbleInput = false; roboAgent = GetComponent <RoboAgent>(); }
public bool isValidMove(RoboAgent a, SizeF move) { if (move.Height == 0 && move.Width == 0) { return(false); } double dx = a.Location.X + move.Width; double dy = a.Location.Y + move.Height; if (dx > this.Size.Width || dx < 0 || dy > this.size.Height || dy < 0) { return(false); } else { return(true); } }
private void OnEnable() { roboAgent = GetComponent <RoboAgent>(); health = 2000f; healthSlider = transform.Find("Canvas/Slider").GetComponent <Slider>(); healthSlider.gameObject.SetActive(true); healthSlider.maxValue = startingHealth; healthSlider.value = health; roboWorld = transform.parent.Find("Robo World").gameObject; if (tag == "redAgent") { mapReload = roboWorld.transform.Find("Red Zone/Red Reload").gameObject; } else if (tag == "blueAgent") { mapReload = roboWorld.transform.Find("Blue Zone/Blue Reload").gameObject; } mapManager = roboWorld.GetComponent <MapManager>(); roboMovement = GetComponent <RoboMovement>(); roboShooter = GetComponent <RoboShooter>(); gimbalCoverRenderer = transform.Find("Gimbal/Gimbal Head/Gimbal Cover").GetComponent <MeshRenderer>(); ammoRemain = 40; reloadCount = 2; shieldCount = 2; enemyShieldCount = 2; currentHeat = 0f; reloading = false; isAttacked = false; isShield = false; isEnemyShield = false; frontAttacked = false; leftAttacked = false; rearAttacked = false; rightAttacked = false; isCollide = false; dead = false; amIShootDead = false; isWobble = false; chargeTime = 0f; damage = 50f; fireSpeed = 15f; }
public static float ManhattenDistance(RoboAgent a, RoboAgent b) { return(Math.Abs(a.Location.X - b.Location.X) + Math.Abs(a.Location.Y - b.Location.Y)); }
public static float Distance(RoboAgent a, RoboAgent b) { return((float)Math.Sqrt(Math.Pow(a.Location.X - b.Location.X, 2) + Math.Pow(a.Location.Y - b.Location.Y, 2))); }