Example #1
0
	/**
	 * onScannedRobot: Here's the good stuff
	 */	
	protected override void OnScannedRobot(ScannedRobotEvent e) {

		// If we have a target, and this isn't it, return immediately
		//  so we can get more ScannedRobotEvents.
		if (trackName != null && e.Name != trackName)
			return;

		// If we don't have a target, well, now we do!
    	if (trackName == null) {
			trackName = e.Name;
		}
		// This is our target.  Reset count (see the run method)
    	count = 0;
		// If our target is too far away, turn and move torward it.
		if (e.Distance > 150)
		{
			gunTurnAmt = normalRelativeAngle((int) e.Bearing + Heading);
			
			TurnRight(gunTurnAmt);  	// and see how much Tracker improves...
			Ahead(e.Distance - 140);
			return;
		}

		// Our target is close.
		gunTurnAmt = normalRelativeAngle((int) e.Bearing + Heading);
		TurnRight(gunTurnAmt);
		Fire(3);
		
		// Our target is too close!  Back up.
		if (e.Distance < 100)
		{
			if (e.Bearing > -90 && e.Bearing <= 90)
				Back(40);
			else
				Ahead(40);
		}
 
	}
Example #2
0
		protected override void OnScannedRobot(ScannedRobotEvent e)
		{
			Fire(1);
		}
Example #3
0
		protected virtual void OnScannedRobot(ScannedRobotEvent e) {}
Example #4
0
		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;
					}
				}
			}
		}