public Shoot() : base("Shoot") { _targetPosition = null; _targetDistance = 0; _targetBearing = 0; }
public override void EnterState() { base.EnterState(); _targetPosition = Robot.Enemy.Position; _targetBearing = Robot.Enemy.BearingDegrees; _targetDistance = Robot.DistanceRemaining; _targetEnergy = Robot.Enemy.Energy; //Får ut verdien for retningen motstanderen er + retningen roboten er i. double absoluteBearing = Robot.Heading + _targetBearing; //Her brukter vi notmalrelativeangledegress for å finne den korteste veien til retningen du vil bevege deg til. double bearingToEnemy = Utils.NormalRelativeAngleDegrees(absoluteBearing - Robot.GunHeading); //Beveger seg til retningen motstanderen er, hvis ikke den retningen er 0, da er den i sikte if (Math.Abs(bearingToEnemy) < 0) { Robot.TurnGunRight(bearingToEnemy); } else { Robot.TurnGunRight(bearingToEnemy); } }
public void DrawRobotIndicator(Color drawColor, Point2D target) { // Set color to a semi-transparent one. Color halfTransparent = Color.FromArgb(128, drawColor); // Draw rectangle at target. Graphics.FillRectangle(new SolidBrush(halfTransparent), (int)(target.X - 26.5), (int)(target.Y - 26.5), 54, 54); }
public void SetEnemyData(ScannedRobotEvent newEnemyData, Point2D newPosition) { // First we set the stuff that depends on last updates' values: long deltaTime = newEnemyData.Time - Time; TurnRateRadians = Utils.NormalRelativeAngle(newEnemyData.HeadingRadians - HeadingRadians) / deltaTime; Acceleration = (newEnemyData.Velocity - Velocity) / deltaTime; // General data: Time = newEnemyData.Time; // Compared-to-us data: BearingRadians = newEnemyData.BearingRadians; Distance = newEnemyData.Distance; // Enemy specific data: Name = newEnemyData.Name; Energy = newEnemyData.Energy; Position = newPosition; Velocity = newEnemyData.Velocity; HeadingRadians = newEnemyData.HeadingRadians; //La til en LockOn, som blir true vær gang radaren har gått over motstanderne. LockOn = true; }
// Called once when we transition into this state. public override void EnterState() { _BodyColor = Color.Purple; _GunColor = Color.Purple; _RadarColor = Color.Purple; _BulletColor = Color.Purple; _ScanArColor = Color.Purple; base.EnterState(); _Posistion = new Point2D(Robot.X,Robot.Y); _speed = Robot.Velocity; _velocity = Robot.Velocity; _heading = Robot.Heading; _direction = 1; _energy = Robot.Energy; _battleFieldWidth = Robot.BattleFieldWidth; _battleFieldHeight = Robot.BattleFieldHeight; _maxprediction = Robot.Enemy.Position.length(); _targetBearing = Robot.Enemy.BearingDegrees; _targetDistance = Robot.Enemy.Distance; _targetVelocity = Robot.Enemy.Velocity; }
public void DrawLineAndTarget(Color drawColor, Point2D start, Point2D end) { // Set color to a semi-transparent one. Color halfTransparent = Color.FromArgb(128, drawColor); // Draw line and rectangle. Graphics.DrawLine(new Pen(halfTransparent), (int)start.X, (int)start.Y, (int)end.X, (int)end.Y); Graphics.FillRectangle(new SolidBrush(halfTransparent), (int)(end.X - 17.5), (int)(end.Y - 17.5), 36, 36); }
public Flee() : base("Flee") { _targetPosition = null; _energy = 0; _targetDistance = 0; _targetBearing = 0; _targetEnergy = 0; }
public EnemyData(EnemyData cloneMe) { Time = cloneMe.Time; Name = cloneMe.Name; BearingRadians = cloneMe.BearingRadians; Distance = cloneMe.Distance; Energy = cloneMe.Energy; Position = new Point2D(cloneMe.Position); Velocity = cloneMe.Velocity; Acceleration = cloneMe.Acceleration; HeadingRadians = cloneMe.HeadingRadians; TurnRateRadians = cloneMe.TurnRateRadians; }
// Public Methods public EnemyData() { Time = 0; Name = null; BearingRadians = 0.0; Distance = 0.0; Energy = 0.0; Position = new Point2D(); Velocity = 0.0; Acceleration = 0.0; HeadingRadians = 0.0; TurnRateRadians = 0.0; LockOn = false; CloseToRobot = false; }
//Denne metoden får inn data av andre roboter når radaren treffer de andre robotene. public override void OnScannedRobot(ScannedRobotEvent scanData) { //Tar imot retningen robot ligger i forhold til sin posisjon. double enemyAbsoluteBearing = HeadingRadians + scanData.BearingRadians; //Tar imot lengden fra motstanderen til din robot. double enemyDistance = scanData.Distance; //Lagrer posisjonen som en Point2D, egen klasse som tar imot x og y posisjonen til roboten. Point2D robotLocation = new Point2D(X, Y); //Regner ut hvor fiendens posisjon ved hjelp av MathHelpers klassen. Point2D enemyLocation = MathHelpers.project(robotLocation, enemyAbsoluteBearing, enemyDistance); //Sender dataen videre til enemydata klassen og sender med informasjonen fra scan methoden og posisjonen til motstanderen. Enemy.SetEnemyData(scanData, enemyLocation); }
public Circle() : base("Circle") { _battleFieldHeight = 0; _battleFieldWidth = 0; _direction = 0; _targetDistance = 0; _heading = 0; _maxprediction = 0; _Posistion = null; _prediction = 0; _speed = 0; _targetBearing = 0; _targetVelocity = 0; _velocity = 0; _energy = 0; }
public override void EnterState() { _BodyColor = Color.Yellow; _GunColor = Color.Yellow; _RadarColor = Color.Yellow; _BulletColor = Color.Yellow; _ScanArColor = Color.Yellow; base.EnterState(); _energy = Robot.Energy; _targetPosition = Robot.Enemy.Position; _targetDistance = Robot.Enemy.Distance; _targetBearing = Robot.Enemy.BearingDegrees; _targetEnergy = Robot.Enemy.Energy; }
public Point2D(Point2D cloneMe) { X = cloneMe.X; Y = cloneMe.Y; }