Esempio n. 1
0
 public void SetEnemy(Player enemy)
 {
     _enemy         = enemy;
     _enLastSeen.X  = -404;
     _enLastSeen.Y  = -404;
     _enLastHeading = _enemy.GetCurrentVelocity();
 }
 public Bullet(int x, int y, int damage, SwinGameSDK.Vector direction, Player origin, List <Entity> collideAgainst) : base(x, y, 1)
 {
     _collideAgainst = collideAgainst;
     _damage         = damage;
     _direction      = direction;
     _origin         = origin;
 }
 public PathfinderTile()
 {
     _currentState = TileState.NOT_ACTIVATED;
     _value        = 500;
     _direction    = new Vector();
     _waypoint     = false;
     _pos          = new Point2D();
 }
Esempio n. 4
0
 public override void BulletCollision(Bullet b)
 {
     b.SetToRemove();
     _health -= b.GetDamage();
     if (_health < 1)
     {
         _state = State.DEAD;
     }
     if (_state == State.SEEKING_ENEMY)
     {
         _state = State.PURSUING_ENEMY;
     }
     _enLastSeen    = _enemy.GetPos();
     _enLastHeading = _enemy.GetCurrentVelocity();
 }
Esempio n. 5
0
        private SwinGameSDK.Vector GetPathVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, Point2D destination, bool selected)
        {
            SwinGameSDK.Vector pathVector = new SwinGameSDK.Vector();

            if (_inControl)
            {
                ///////////////////////ALLOWS CONTROL OF PLAYERS////////////////////////////////
                if (SwinGame.KeyDown(KeyCode.vk_RIGHT) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(0, 8));
                }
                if (SwinGame.KeyDown(KeyCode.vk_DOWN) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(90, 8));
                }
                if (SwinGame.KeyDown(KeyCode.vk_LEFT) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(180, 8));
                }
                if (SwinGame.KeyDown(KeyCode.vk_UP) && selected)
                {
                    pathVector = SwinGame.AddVectors(pathVector, SwinGame.CreateVectorFromAngle(-90, 8));
                }
                ///////////////////////ALLOWS CONTROL OF PLAYERS////////////////////////////////
            }
            else
            {
                if (_toUpdate)
                {
                    _forces    = AStarPathfinder.CalculateForces(playerPos, tileSet, destination);
                    _toUpdate  = false;
                    pathVector = CurrentForce(playerPos, tileSet);
                }
                else
                {
                    pathVector = CurrentForce(playerPos, tileSet);
                }
            }

            if (pathVector.Magnitude > 3)
            {
                pathVector = SwinGame.LimitVector(pathVector, 3);
            }

            return(pathVector);
        }
Esempio n. 6
0
        public Player(int fov, int reloadSpeed, int maxAmmo, int health, int damage, int firerate, int bulletSpread, int speed, int rotateSpeed, int posX, int posY, Color colour, Tile[,] tiles, List <Entity> refToEnts) : base(posX, posY, 20)
        {
            _state           = State.SEEKING_ENEMY;
            _enemy           = null;
            _angleFacing     = 0;
            _movementVector  = new SwinGameSDK.Vector();
            _fov             = fov;
            _reloadSpeed     = reloadSpeed;
            _maxAmmo         = maxAmmo;
            _ammo            = maxAmmo;
            _health          = health;
            _damage          = damage;
            _firerate        = firerate;
            _bulletSpread    = bulletSpread;
            _speed           = speed;
            _rotateSpeed     = rotateSpeed;
            _enLastSeen.X    = 700;
            _enLastSeen.Y    = 700;
            _colour          = colour;
            _destination.X   = 700;
            _destination.Y   = 700;
            _allTiles        = tiles;
            _movementManager = new ForceMap();
            _ignoreEnemy     = false;
            _selected        = false;
            _toAdd           = new List <Entity>();
            _refToEnts       = refToEnts;
            _timer           = 0;
            _predictMovement = true;

            _knownTiles = new Tile[Game.x_width, Game.y_height];
            for (int i = 0; i < Game.x_width; i++)
            {
                for (int j = 0; j < Game.y_height; j++)
                {
                    _knownTiles[i, j] = new Tile(TileType.UNKNOWN, i * 60, j * 60, 60);
                }
            }
        }
Esempio n. 7
0
        private void PursuingEnemy()
        {
            AimingAt((int)(_position.X + _movementVector.X), (int)(_position.Y + _movementVector.Y));

            SetDest(_enLastSeen);

            if ((_position.X <= _enLastSeen.X + 60) && (_position.X >= _enLastSeen.X - 60) && (_position.Y <= _enLastSeen.Y + 60) && (_position.Y >= _enLastSeen.Y - 60))
            {
                _timer = (int)Math.Floor((double)(360 / _rotateSpeed));
                _state = State.ON_LAST_SEEN;
            }
            if (CanSee(_enemy.GetPos(), false))
            {
                _state         = State.AIMING;
                _destination.X = _position.X;
                _destination.Y = _position.Y;
                _enLastHeading = _enemy.GetCurrentVelocity();
            }
            if (_enLastSeen.X == -404)
            {
                _state = State.SEEKING_ENEMY;
            }
        }
Esempio n. 8
0
        public SwinGameSDK.Vector GetMovementVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, SwinGameSDK.Vector currentMoveVector, Point2D destination, bool selected)
        {
            if (currentMoveVector.Magnitude > 8)
            {
                currentMoveVector = SwinGame.LimitVector(currentMoveVector, 8);
            }

            if (!_velocity)
            {
                currentMoveVector = new SwinGameSDK.Vector();
            }

            currentMoveVector = SwinGame.AddVectors(currentMoveVector, GetPathVector(playerPos, tileSet, destination, selected));

            currentMoveVector = SwinGame.AddVectors(currentMoveVector, GetDistractionVector(playerPos, tileSet, currentMoveVector));

            if (SwinGame.PointPointDistance(playerPos, destination) < 120)
            {
                if (SwinGame.PointPointDistance(playerPos, destination) < 60)
                {
                    if (currentMoveVector.Magnitude < 2)
                    {
                        return(SwinGame.VectorFromAngle(currentMoveVector.Angle, 0));
                    }
                    else
                    {
                        return(SwinGame.LimitVector(currentMoveVector, (float)(currentMoveVector.Magnitude * 0.7)));
                        //////////////////////////FIIIIIIIIIIIIIIIIX
                        ///
                    }
                }
                // FIX FIX FIX FIX FIX
                return(SwinGame.LimitVector(currentMoveVector, (float)(currentMoveVector.Magnitude * 0.9)));
            }

            return(currentMoveVector);
        }
 public void FaceTowards(Point2D pos, Point2D nextWaypoint)
 {
     _direction = SwinGame.VectorFromAngle(SwinGame.CalculateAngleBetween(pos, nextWaypoint), 8);
 }
Esempio n. 10
0
        public override void Main()
        {
            if (_state != State.DEAD)
            {
                _movementVector = _movementManager.GetMovementVector(_position, _knownTiles, _movementVector, _destination, _selected);

                _position.X += _movementVector.X;
                _position.Y += _movementVector.Y;

                if (_position.X < _size)
                {
                    _position.X = 0 + _size;
                }
                else if (_position.X > SwinGame.ScreenWidth() - _size)
                {
                    _position.X = SwinGame.ScreenWidth() - _size;
                }

                if (_position.Y < _size)
                {
                    _position.Y = 0 + _size;
                }
                else if (_position.Y > SwinGame.ScreenHeight() - _size)
                {
                    _position.Y = SwinGame.ScreenHeight() - _size;
                }
            }

            TileCheck();

            if (_enLastSeen.X != -404)
            {
                if (_enLastSeen.X + _enLastHeading.X > 0 && _enLastSeen.X + _enLastHeading.X < SwinGame.ScreenWidth())
                {
                    if (_enLastSeen.Y + _enLastHeading.Y > 0 && _enLastSeen.Y + _enLastHeading.Y < SwinGame.ScreenHeight())
                    {
                        if (_allTiles[(int)Math.Floor((_enLastSeen.X + _enLastHeading.X) / 60), (int)Math.Floor((_enLastSeen.Y + _enLastHeading.Y) / 60)].GetTileType() != TileType.WALL)
                        {
                            _enLastSeen.X += _enLastHeading.X;
                            _enLastSeen.Y += _enLastHeading.Y;
                        }
                    }
                }
            }

            if (!_ignoreEnemy)
            {
                if (_state == State.AIMING)
                {
                    Aiming();
                }
                else if (_state == State.DEAD)
                {
                    Dead();
                }
                else if (_state == State.HIDING)
                {
                    Hiding();
                }
                else if (_state == State.ON_LAST_SEEN)
                {
                    OnLastSeen();
                }
                else if (_state == State.PURSUING_ENEMY)
                {
                    PursuingEnemy();
                }
                else if (_state == State.RELOADING)
                {
                    Reloading();
                }
                else if (_state == State.SEEKING_ENEMY)
                {
                    SeekingEnemy();
                }
                else if (_state == State.SEEKING_HIDING)
                {
                    SeekingHiding();
                }
                else if (_state == State.FINDING_HIDING)
                {
                    FindingHiding();
                }
                else if (_state == State.SHOOTING)
                {
                    Shooting();
                }
            }

            if (_health <= 0)
            {
                _state = State.DEAD;
            }

            if (CanSee(_enemy.GetPos(), false))
            {
                _enLastSeen    = _enemy.GetPos();
                _enLastHeading = _enemy.GetCurrentVelocity();
            }
        }
Esempio n. 11
0
        private SwinGameSDK.Vector GetDistractionVector(SwinGameSDK.Point2D playerPos, Tile[,] tileSet, SwinGameSDK.Vector currentMoveVector)
        {
            SwinGameSDK.Vector  distractionVector = new SwinGameSDK.Vector();
            SwinGameSDK.Point2D max = new Point2D();
            SwinGameSDK.Point2D min = new Point2D();


            if (currentMoveVector.Angle <= 0)
            {
                min.Y = playerPos.Y + (currentMoveVector.Y * 7);
                max.Y = playerPos.Y;
            }
            else
            {
                max.Y = playerPos.Y - (currentMoveVector.Y * 7);
                min.Y = playerPos.Y;
            }

            if (currentMoveVector.Angle < 90 && currentMoveVector.Angle > -90)
            {
                max.X = playerPos.X + (currentMoveVector.X * 7);
                min.X = playerPos.X;
            }
            else
            {
                min.X = playerPos.X - (currentMoveVector.X * 7);
                max.X = playerPos.X;
            }

            float normalX = SwinGame.VectorNormal(currentMoveVector).X *(12);
            float normalY = SwinGame.VectorNormal(currentMoveVector).Y *(12);

            int iMax = (int)(Math.Ceiling(max.X / 60) + 1);
            int iMin = (int)(Math.Floor(min.X / 60) - 1);
            int jMax = (int)(Math.Ceiling(max.Y / 60) + 1);
            int jMin = (int)(Math.Floor(min.Y / 60) - 1);

            if (iMax > Game.x_width - 1)
            {
                iMax = Game.x_width - 1;
            }
            if (iMin < 0)
            {
                iMin = 0;
            }
            if (jMax > Game.y_height - 1)
            {
                jMax = Game.y_height - 1;
            }
            if (jMin < 0)
            {
                jMin = 0;
            }

            //loops through each square in the min/max of the rect fov.
            for (int i = iMin; i < iMax; i++)
            {
                for (int j = jMin; j < jMax; j++)
                {
                    if (tileSet[i, j].GetTileType() == TileType.WALL)
                    {
                        // I'm so sorry. It's so ugly.
                        if
                        (
                            SwinGame.LineIntersectsRect(SwinGame.LineFrom(playerPos.X + normalX, playerPos.Y + normalY, playerPos.X + (currentMoveVector.X * 7) + normalX, playerPos.Y + (currentMoveVector.Y * 7) + normalY), tileSet[i, j].GetHitBox())
                            ||
                            SwinGame.LineIntersectsRect(SwinGame.LineFrom(playerPos.X - normalX, playerPos.Y - normalY, playerPos.X + (currentMoveVector.X * 7) - normalX, playerPos.Y + (currentMoveVector.Y * 7) - normalY), tileSet[i, j].GetHitBox())
                        )
                        {
                            SwinGameSDK.Vector thisDistraction = new SwinGameSDK.Vector();

                            float distance = SwinGame.PointPointDistance(playerPos, tileSet[i, j].GetPos());
                            if (distance < 0)
                            {
                                distance = 0;
                            }

                            thisDistraction = SwinGame.VectorFromAngle(SwinGame.CalculateAngleBetween(playerPos, tileSet[i, j].GetPos()), distance);

                            distractionVector = SwinGame.AddVectors(distractionVector, SwinGame.InvertVector(thisDistraction));
                        }
                    }
                }
            }

            if (distractionVector.Magnitude > 3)
            {
                distractionVector = SwinGame.LimitVector(distractionVector, 3);
            }

            return(distractionVector);
        }