示例#1
0
 /// <summary>
 /// Point the tower to target X,Y.
 /// </summary>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 public void PointTo(float x, float y)
 {
     _angle   = SwinGame.CalculateAngle(_position[0], _position[1], x, y);
     _pointAx = _barrelLength * SwinGame.Cosine(_angle - _barrelWidth) + _position[0];
     _pointAy = _barrelLength * SwinGame.Sine(_angle - _barrelWidth) + _position[1];
     _pointBx = _barrelLength * SwinGame.Cosine(_angle + _barrelWidth) + _position[0];
     _pointBy = _barrelLength * SwinGame.Sine(_angle + _barrelWidth) + _position[1];
     _pointSx = _barrelLength * SwinGame.Cosine(_angle) + _position[0];
     _pointSy = _barrelLength * SwinGame.Sine(_angle) + _position[1];
 }
示例#2
0
 protected void TryRotate()
 {
     if (SwinGame.CalculateAngle(controlled.Dir, targetDir).GetSign() > 0)
     {
         turnRightCommand.Execute();
         commandHistory.AddCommand(turnRightCommand);
     }
     else
     {
         turnLeftCommand.Execute();
         commandHistory.AddCommand(turnLeftCommand);
     }
 }
示例#3
0
        /// <summary>
        /// Calculates the angle to move to and moves by speed distance, move half as fast when slowed
        /// </summary>
        /// <param name="destx">destination X</param>
        /// <param name="desty">destination Y</param>
        public void Move(float destx, float desty)
        {
            float angle = SwinGame.CalculateAngle(_position[0], _position[1], destx, desty);

            if (!_slowed)
            {
                _position[0] += (_speed * SwinGame.Cosine(angle));
                _position[1] += (_speed * SwinGame.Sine(angle));
            }
            else
            {
                _position[0] += ((int)(_speed / 2) * SwinGame.Cosine(angle));
                _position[1] += ((int)(_speed / 2) * SwinGame.Sine(angle));
            }
        }
示例#4
0
        private bool AimingAt(int x, int y)
        {
            if (Math.Abs(Math.Round(SwinGame.CalculateAngle(SwinGame.VectorFromAngle(SwinGame.CalculateAngle(_position.X, _position.Y, x, y), 2000), SwinGame.VectorFromAngle(_angleFacing, 2000)))) < _rotateSpeed)
            {
                _angleFacing = SwinGame.CalculateAngle(_position.X, _position.Y, x, y);
                return(true);
            }
            else if (SwinGame.CalculateAngle(SwinGame.VectorFromAngle(SwinGame.CalculateAngle(_position.X, _position.Y, x, y), 2000), SwinGame.VectorFromAngle(_angleFacing, 2000)) > 0)
            {
                _angleFacing -= _rotateSpeed;
                //if( Math.Abs( SwinGame.CalculateAngle(_position.X, _position.Y, x, y) ) <= _rotateSpeed)
                //{
                //	_angleFacing = SwinGame.CalculateAngle(_position.X, _position.Y, x, y);
                //	return true;
                //}
            }
            else
            {
                _angleFacing += _rotateSpeed;
                //if( Math.Abs( SwinGame.CalculateAngle(_position.X, _position.Y, x, y) ) <= _rotateSpeed)
                //{
                //	_angleFacing = SwinGame.CalculateAngle(_position.X, _position.Y, x, y);
                //	return true;
                //}
            }

            if (_angleFacing < 0)
            {
                _angleFacing = _angleFacing + 360;
            }
            else if (_angleFacing > 360)
            {
                _angleFacing = _angleFacing - 360;
            }

            return(false);
        }
示例#5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////


        ///////////////////////////////////////////// FRAME RATE HIT IS IN THE FOLLOWING/////////////////////////////////////////////////////////
        private bool CanSee(SwinGameSDK.Point2D toSee, bool heading)
        {
            // takes the absoloute value of the angle between two vectors. The one between the player and what they're trying to see and the vector in the direction the player is facing.
            // It then checks if this value is less than half the player's fov. This will check if the object is within the player's cone of vision.
            //////////////////////////////////// DROPPED FROM 50 TO 20 WHEN CHANGED FROM CALCANGLE(pt, pt) TO CALCANGLE(x,y,x,y)//////////////////////////////////////////////////////
            float temp = 0;

            if (heading)
            {
                temp = Math.Abs(SwinGame.CalculateAngle(SwinGame.VectorFromAngle(SwinGame.CalculateAngle(_position.X, _position.Y, toSee.X, toSee.Y), 2000), SwinGame.VectorFromAngle(_movementVector.Angle, 2000)));
            }
            else
            {
                temp = Math.Abs(SwinGame.CalculateAngle(SwinGame.VectorFromAngle(SwinGame.CalculateAngle(_position.X, _position.Y, toSee.X, toSee.Y), 2000), SwinGame.VectorFromAngle(_angleFacing, 2000)));
            }

            if (temp < (_fov / 2))
            {
                bool result = true;
                int  minX   = 0;
                int  minY   = 0;
                int  maxX   = 0;
                int  maxY   = 0;

                if (toSee.X < _position.X)
                {
                    maxX = (int)Math.Floor(_position.X / 60);
                    minX = (int)Math.Floor(toSee.X / 60);
                }
                else
                {
                    minX = (int)Math.Floor(_position.X / 60);
                    maxX = (int)Math.Floor(toSee.X / 60);
                }

                if (toSee.Y < _position.Y)
                {
                    maxY = (int)Math.Floor(_position.Y / 60);
                    minY = (int)Math.Floor(toSee.Y / 60);
                }
                else
                {
                    minY = (int)Math.Floor(_position.Y / 60);
                    maxY = (int)Math.Floor(toSee.Y / 60);
                }

                for (int i = minX - 1; i < maxX + 1; i++)
                {
                    for (int j = minY - 1; j < maxY + 1; j++)
                    {
                        if (i > 0 && j > 0 && i < Game.x_width && j < Game.y_height)
                        {
                            if (_allTiles[i, j].GetTileType() == TileType.WALL && !SwinGame.PointInRect(toSee, _allTiles[i, j].GetHitBox()) && SwinGame.LineIntersectsRect(SwinGame.LineFrom(_position, toSee), _allTiles[i, j].GetHitBox()))
                            {
                                result = false;
                            }
                        }
                    }
                }
                return(result);
            }
            return(false);
        }