protected override void OnHitRobot(HitRobotEvent e) { // If he's in front of us, set back up a bit. //if (e.Bearing > -90 && e.Bearing < 90) Back(100); // else he's in back of us, so set ahead a bit. //else // Ahead(100); }
/** * onHitRobot: Set him as our new target */ protected override void OnHitRobot(HitRobotEvent e) { // Set the target trackName = e.Name; // Back up a bit. // Note: We won't get scan events while we're doing this! // An AdvancedRobot might use setBack(); execute(); gunTurnAmt = normalRelativeAngle((int) e.Bearing + Heading); TurnRight(gunTurnAmt); Fire(3); Back(50); }
protected override void OnHitRobot(HitRobotEvent e) { Back(100); }
protected virtual void OnHitRobot(HitRobotEvent e) {}
internal void ProcessMovement() { // update robot position PointD tOldPosition = m_tPosition; m_tPosition += m_tMovement; m_tMovement = PointD.Empty; // check if we have hit a wall bool bHitWall = false; if (m_tPosition.X - Size.Width / 2.0 < 0) { m_tPosition.X = Size.Width / 2.0; bHitWall = true; } else if (m_tPosition.X + Size.Width / 2.0 > m_pBattle.BattleFieldSize.Width) { m_tPosition.X = m_pBattle.BattleFieldSize.Width - Size.Width / 2.0; bHitWall = true; } if (m_tPosition.Y - Size.Height / 2.0 < 0) { m_tPosition.Y = Size.Height / 2.0; bHitWall = true; } else if (m_tPosition.Y + Size.Height / 2.0 > m_pBattle.BattleFieldSize.Height) { m_tPosition.Y = m_pBattle.BattleFieldSize.Height - Size.Height / 2.0; bHitWall = true; } if (bHitWall) { m_pEvents.Add(new HitWallEvent()); m_dEnergy -= 3.0; } // rotate robot m_nHeading += m_nRotation; if (m_nHeading < 0) m_nHeading = 360 + m_nHeading; if (m_nHeading > 359) m_nHeading -= 360; m_nRotation = 0; PointF tEndPoint = new PointF((float) (Position.X + Math.Sin(HeadingRadians) * BattleFieldSize.Width), (float) (Position.Y + Math.Cos(HeadingRadians) * BattleFieldSize.Width)); // check if we can see another robot for (int i = 0; i < m_pBattle.Robots.Length; i++) { Robot pRobot = m_pBattle.Robots[i]; // make sure we're not testing against ourselves if (pRobot != this) { GraphicsPath pPath = new GraphicsPath(); pPath.AddLine(Position, tEndPoint); pPath.CloseFigure(); pPath.Widen(new Pen(Color.Black, 1)); Region pRegion = new Region(pPath); pRegion.Intersect(pRobot.Bounds); if (!pRegion.IsEmpty(m_pGraphics)) { // we can see this robot PointD tDistance = pRobot.Position - Position; double dDistance = Math.Sqrt(tDistance.X * tDistance.X + tDistance.Y * tDistance.Y); ScannedRobotEvent pEvent = new ScannedRobotEvent( pRobot.Name, pRobot.Energy, pRobot.Heading - Heading, dDistance, pRobot.Heading, pRobot.Velocity); m_pEvents.Add(pEvent); } } } // check if we have collided with another robot for (int i = 0; i < m_pBattle.Robots.Length; i++) { Robot pRobot = m_pBattle.Robots[i]; // make sure we're not testing against ourselves if (pRobot != this) { if (pRobot.Bounds.IntersectsWith(Bounds)) { // send message to ourselves bool bAtFault = true; HitRobotEvent pEvent = new HitRobotEvent(pRobot.Name, Math.Abs(pRobot.Heading - Heading), pRobot.Energy, bAtFault); m_pEvents.Add(pEvent); m_tPosition = tOldPosition; m_dEnergy -= 3.0; } } } }