/**************************************************************************** * Methods *****************************************************************************/ /// <summary> /// Updates the current position of the points and returns the resulting points /// </summary> /// <returns></returns> internal override Stack <Point[]> updateAllPoints() { Stack <Point[]> retStack = new Stack <Point[]>(); if (this.FramesRemaining <= 0 || !this.IsAlive) { this.IsAlive = false; return(retStack); } //move center point this.CenterPoint = PointAdjuster.adjustPoint( this.CenterPoint, (int)Math.Truncate(this.VeloX + this.VeloXTrun), (int)Math.Truncate(this.VeloY + this.VeloYTrun), this.GamePanel.GetPanelWidth, this.GamePanel.GetPanelHeight); this.VeloXTrun += this.VeloX - Math.Truncate(this.VeloX + this.VeloXTrun); this.VeloYTrun += this.VeloY - Math.Truncate(this.VeloY + this.VeloYTrun); //if center point goes off screen then put it back on screen this.CenterPoint = PointAdjuster.centerPointFix( this.CenterPoint, this.GamePanel.GetPanelWidth, this.GamePanel.GetPanelHeight, this.GamePanel.GetPanelLocX, this.GamePanel.GetPanelLocY); this.FramesRemaining--; retStack.Push(this.AllPoints); return(retStack); }
internal Missle(Point centerPoint, double missleAngle, int id, GenericDrawingPanel gamePanel, int frameRate) { this.GamePanel = gamePanel; this.FrameRate = frameRate; this.SetIDTag = id; this.IsAlive = true; this.IsKillable = true; this.VeloXTrun = 0; this.VeloYTrun = 0; this.FramesRemaining = this.FrameRate * this.LifeSpan; double radAngle = Math.PI / (double)180 * (missleAngle + 90); this.VeloX = this.TotalVelocity * Math.Cos(radAngle); this.VeloY = this.TotalVelocity * Math.Sin(radAngle); this.CenterPoint = PointAdjuster.adjustPointAcc( centerPoint, (int)this.VeloX * 2, (int)this.VeloY * 2, this.GamePanel.GetPanelWidth, this.GamePanel.GetPanelHeight); }
/// <summary> /// Updates the sight of the spaceship's eyes /// </summary> private void updateEyes() { //true when an eye detects an object bool isFound = false; //detect the closest object within range of all eyes for (int i = 0; i < this.NumEyes; i++) { //number of loops equal to the maximum number of points checked for each eye for (int j = 0; j <= 100; j += 5) { //check all of the objects in the game to see if they are within the eye's range for (int k = 0; k < this.FlyingObjects.Count; k++) { //point where an object will be looked for Point testPoint = PointAdjuster.adjustPoint( this.CenterPoint, (int)((double)this.EyeOffcenterArray[i].X * (double)j * (double)0.01), (int)((double)this.EyeOffcenterArray[i].Y * (double)j * (double)0.01), this.GamePanel.GetPanelWidth, this.GamePanel.GetPanelHeight, this.ShipScale, this.ShipDirectionAngle); if ((this.FlyingObjects[k].GetIDTag != this.GetIDTag && CollisionDetection.PointInPolygon(testPoint.X, testPoint.Y, this.FlyingObjects[k].CollisionPoints)) || j == 100) { this.EyeInputArray[i] = new Point(testPoint.X, testPoint.Y); this.EyeFractionArray[i] = (double)j * (double)0.01; isFound = true; break; } } if (isFound) { break; } } isFound = false; } }
/**************************************************************************** * Methods *****************************************************************************/ /// <summary> /// Top of the stack contains the points of the space ship. The rest of the stack is for the eyes. /// </summary> /// <returns></returns> internal override Stack <Point[]> updateAllPoints() { Stack <Point[]> retStack = new Stack <Point[]>(); if (this.FramesRemaining <= 0 || !this.IsAlive) { if (!this.IsUser) { this.allNets.setCurrentScore(this.Score); this.allNets.goToNextNet(); } this.restShip(); } else if ((this.LifeSpan * this.FrameRate) - this.FramesRemaining > this.GraceSpan * this.FrameRate) { this.IsKillable = true; } //handles the thrusting if (this.IsThrust && this.TotalVelocity <= MaxVelocity) { this.IsThrust = true; double radAngle = Math.PI / (double)180 * (270 - this.ShipDirectionAngle); double acceration = 0.5; this.VeloX += acceration * Math.Cos(radAngle); this.VeloY -= acceration * Math.Sin(radAngle); } //move center point this.ShipDirectionAngle += this.AngularV; this.CenterPoint = PointAdjuster.adjustPointAcc( this.CenterPoint, (int)Math.Truncate(this.VeloX + this.VeloXTrun), (int)Math.Truncate(this.VeloY + this.VeloYTrun), this.GamePanel.GetPanelWidth, this.GamePanel.GetPanelHeight, this.ShipScale, this.ShipDirectionAngle); this.VeloXTrun += this.VeloX - Math.Truncate(this.VeloX + this.VeloXTrun); this.VeloYTrun += this.VeloY - Math.Truncate(this.VeloY + this.VeloYTrun); //if center point goes off screen then put it back on screen this.CenterPoint = PointAdjuster.centerPointFix( this.CenterPoint, this.GamePanel.GetPanelWidth, this.GamePanel.GetPanelHeight, this.GamePanel.GetPanelLocX, this.GamePanel.GetPanelLocY); //update the sight of the ship updateEyes(); this.FramesRemaining--; foreach (Point p in this.EyeInputArray) { retStack.Push(new Point[] { this.CenterPoint, p }); } retStack.Push(this.AllPoints); return(retStack); }