Example #1
0
        public override void Collision(GameObject otherObj)
        {
            Rectangle collisionRect = Rectangle.Intersect(destinationBox, otherObj.destinationBox);

            if (!(otherObj is Character))
            {
                // Check otherObj's right side.
                if (otherObj.destinationBox.Right > destinationBox.Left && otherObj.destinationBox.Right <= prevDestinationBox.Left)
                {
                    position = new Vector2((float)collisionRect.Width + position.X, position.Y);
                }
                // Check otherObj's left side.
                if (otherObj.destinationBox.Left < destinationBox.Right && otherObj.destinationBox.Left >= prevDestinationBox.Right)
                {
                    position = new Vector2(position.X - (float)destinationBox.Width, position.Y);
                }
                // Check otherObj's top side.
                if (otherObj.destinationBox.Top < destinationBox.Bottom && otherObj.destinationBox.Top >= prevDestinationBox.Bottom)
                {
                    position = new Vector2(position.X, position.Y - (float)destinationBox.Height);
                    velocity = new Vector2(velocity.X, 0);
                }
                // Check otherObj's bottom side.
                if (otherObj.destinationBox.Bottom > destinationBox.Top && otherObj.destinationBox.Bottom <= prevDestinationBox.Top)
                {
                    position = new Vector2(position.X, position.Y + (float)destinationBox.Height);
                    velocity = new Vector2(velocity.X, 0);
                }
            }

            base.Collision(otherObj);
        }
Example #2
0
        public PlayerObject()
        {
            isAlive = true;
            HP = 100;
            score = 0;
            max_ammo1 = 500;

            Windex = 1;

            fireRate = 10; ////500 shoots every half second
            weapon1 = new GameObject[max_ammo1];
            for (int i = 0; i < max_ammo1; i++)
            {
                weapon1[i] = new GameObject();
                weapon1[i].isAlive = false;
                weapon1[i].position = new Vector2(0, 0);
                weapon1[i].velocity = new Vector2(0, 0);
                weapon1[i].speed = 10f;
            }

            WtimeCount = 0;
        }
Example #3
0
 public virtual void Collision(GameObject otherObj)
 {
 }
 public void RegisterObject(GameObject go)
 {
     _collidables.Add(go);
 }
 /// <summary>
 /// Player killed this unit.
 /// </summary>
 /// <param name="unit"></param>
 public void PlayerKilledThis(GameObject unit)
 {
     ControlledUnit.GainExperience();
 }
 /// <summary>
 /// Player died to this unit.
 /// </summary>
 /// <param name="unit"></param>
 public void PlayerDiedTo(GameObject unit)
 {
     // NYI
     return;
 }
Example #7
0
        /// <summary>
        /// Repositioning of the camera according to player's position.
        /// Handles input.
        /// </summary>
        public void Update(GameTime gameTime)
        {
            Input();
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if(_stopTime >= 0.0f)
            {
                _stopTime -= deltaTime;
            }

            if (_lastActivePlayer != activePlayer)
            {
                _maxSpeed = 1600.0f;
            }

            CalculateDirection();
            UpdateSpeed(deltaTime);
            if (!DestinationReached())
            {
                if (_stopTime <= 0.0f)
                {
                    MoveCamera(deltaTime);
                }
            }
            else
            {
                if (_currentDeceleration != _DECELERATION && !_movingCameraToObject)
                {
                    _currentDeceleration = _DECELERATION;
                }
                if (_movingCameraToObject)
                {
                    _stopTime = 0.5f;
                    _movingCameraToObject = false;
                    _activeGameObject.CameraMovedToObject();
                    _activeGameObject = null;
                    _currentSpeed = 0.0f;
                }
            }

            // Calculate new camera position.
            _transform = Matrix.CreateScale(new Vector3(_zoom, _zoom, 0)) *
                         Matrix.CreateTranslation(-_center.X, -_center.Y, 0);

            xTileViewportLocation = new Location((int)_center.X, (int)_center.Y);
            this.xTILE_viewport.Location = xTileViewportLocation;
            this.xTILE_viewport.Width = (int)(800 * _zoom);
            this.xTILE_viewport.Height = (int)(480 * _zoom);

            _lastActivePlayer = activePlayer;
        }
Example #8
0
        public void MoveCameraToGameObject(GameObject gameObject, float deceleration, float maxSpeed)
        {
            _activeGameObject = gameObject;
            _movingCameraToObject = true;
            _maxSpeed = maxSpeed;

            _destination = new Vector2(
                gameObject.destinationBox.X + (gameObject.destinationBox.Width / 2)
                        - (_viewport.Width / 2),
                gameObject.destinationBox.Y + (gameObject.destinationBox.Height / 2)
                        - (_viewport.Height - _viewport.Height / 3));

            _direction = Vector2.Normalize(_destination - _center);
            _currentDeceleration = deceleration;
        }