Represents the player in the game
Inheritance: PhysicsObject
Beispiel #1
0
 /// <summary>
 /// Checks to see if the player is within range
 /// </summary>
 /// <param name="objects">Objects of the game</param>
 /// <param name="player">Player in the game</param>
 public override void RunTrigger(List<GameObject> objects, Player player)
 {
     if (player.IsCollidingCircleAndBox(this) && !_hasEntered)
         _hasEntered = true;
     else if (!player.IsCollidingCircleAndBox(this))
         _hasEntered = false;
 }
Beispiel #2
0
 public override void RunTrigger(List<GameObject> objects, Player player)
 {
     if (player.IsCollidingCircleandCircle(this) && _musicByteInstance.State != SoundState.Playing)
     {
         GameSound.StopOthersAndPlay(_musicByteInstance);
         GameSound.SetGeneric(_musicByteInstance);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Runs the sound effect
 /// </summary>
 /// <param name="objects">List of objects in the game</param>
 /// <param name="player">Player</param>
 public override void RunTrigger(List<GameObject> objects, Player player)
 {
     if (player.IsCollidingCircleandCircle(this)&&!_playing)
     {
         _soundByte.Play();
         _playing = true;
     }
     else if (!player.IsCollidingCircleandCircle(this))
         _playing = false;
 }
Beispiel #4
0
        /// <summary>
        /// This triggers adds a force in the x direction while the player is within its bounds and removes it
        /// when the player exits
        /// </summary>
        /// <param name="objects">List of objects in the game</param>
        /// <param name="player">Player in the game</param>
        public override void RunTrigger(List<GameObject> objects, Player player)
        {
            foreach (var gObj in objects)
            {
                if(gObj is PhysicsObject)
                {
                    var isColliding = BoundingBox.Intersects(gObj.BoundingBox);
                    var pObj = (PhysicsObject)gObj;

                    if (!_affectedObjects.Contains(pObj) && isColliding)
                    { pObj.AddForce(_mForce); _affectedObjects.Add(pObj); }
                    else if (_affectedObjects.Contains(pObj) && !isColliding)
                    { pObj.AddForce(Vector2.Multiply(_mForce,-1)); _affectedObjects.Remove(pObj); }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Runs the black hole trigger
        /// </summary>
        /// <param name="objects">List of objects in the game</param>
        /// <param name="player">Player in the game</param>
        public override void RunTrigger(List<GameObject> objects, Player player)
        {
            foreach(var gObj in objects)
            {
                if (!BoundingBox.Intersects(gObj.BoundingBox)) continue;

                if (gObj is Player && player.MCurrentTexture != PlayerFaces.FromString("Dead2"))
                    player.MCurrentTexture = PlayerFaces.FromString("Worry");

                if (gObj is PhysicsObject)
                {
                    var pObj = (PhysicsObject)gObj;

                    Vector2 posDiff = Vector2.Subtract(MPosition, pObj.MPosition);

                    //Gets the angle that the player is at
                    double degrees = 0;
                    if(posDiff.X > 0) degrees = Math.Atan(posDiff.Y/posDiff.X);
                    if(posDiff.X < 0 && posDiff.Y >= 0) degrees = Math.Atan(posDiff.Y/posDiff.X) + Math.PI;
                    if(posDiff.X < 0 && posDiff.Y < 0) degrees = Math.Atan(posDiff.Y/posDiff.X) - Math.PI;
                    if(posDiff.X == 0 && posDiff.Y > 0) degrees = Math.PI/2;
                    if(posDiff.X == 0 && posDiff.Y <0) degrees = - Math.PI/2;

                    //Distance of this trigger and pObj, squared
                    var distance = Vector2.DistanceSquared(GridSpace.GetGridCoord(pObj.MPosition),
                                                                    GridSpace.GetGridCoord(MPosition))+1;

                    //Force on the object( G * M / r^2)
                    var newForce = new Vector2(_mForce * (1 / pObj.Mass) / distance * (float)Math.Cos(degrees),
                        _mForce * (1 / pObj.Mass) / distance * (float)Math.Sin(degrees));

                    //Imediately add this to the objects velocity so that we don't have lingering force additions left over
                    pObj.Velocity = new Vector2(Math.Min(newForce.X + pObj.Velocity.X, pObj.Environment.TerminalSpeed),
                            Math.Min(newForce.Y + pObj.Velocity.Y, pObj.Environment.TerminalSpeed));
                }
            }
        }
 public override void RunTrigger(List<GameObject> objects, Player player)
 {
     if (player.IsCollidingBoxAndBox(this) && player.MCurrentTexture != PlayerFaces.FromString("Dead2"))
         player.MCurrentTexture = _face;
 }
Beispiel #7
0
 /// <summary>
 /// Runs whatever the trigger should do.
 /// </summary>
 /// <param name="objects">List of all the objects in the level</param>
 /// <param name="player">The player in the game</param>
 public abstract void RunTrigger(List<GameObject> objects, Player player);
Beispiel #8
0
        /// <summary>
        /// Loads the level from the content manager
        /// </summary>
        /// <param name="content">Content Manager to load from</param>
        public void Load(ContentManager content)
        {
            _mObjects.Clear();
            Reset();

            var importer = new Importer(content);
            importer.ImportLevel(this);

            _mPlayer = new Player(content, ref _mPhysicsEnvironment,
                _mControls, .8f, EntityInfo.CreatePlayerInfo(GridSpace.GetGridCoord(StartingPoint)));

            _mObjects.Add(_mPlayer);
            _mObjects.AddRange(importer.GetObjects(ref _mPhysicsEnvironment));

            _mPlayerEnd = importer.GetPlayerEnd();
            if (_mPlayerEnd != null)
                _mObjects.Add(_mPlayerEnd);

            _mObjects.AddRange(importer.GetWalls(this).Cast<GameObject>());

            _mRails = importer.GetRails();

            _mTrigger.AddRange(importer.GetTriggers());

            PrepareCollisionMatrix();

            MNumCollected = 0;
            MNumCollectable = 0;

            //Clear the collection lists
            _mCollected.Clear();
            _mRemoveCollected.Clear();

            foreach (var gObject in _mObjects)
            {
                if (gObject.CollisionType == XmlKeys.Collectable)
                    MNumCollectable++;
            }
        }