Beispiel #1
0
        /// <summary>
        /// Construcs a player object, that can live in a physical realm
        /// </summary>
        /// <param name="content">Content manager for the game</param>
        /// <param name="name">Name of the image resource for the player</param>
        /// <param name="initialPosition">Initial posisition in the level</param>
        /// <param name="controlScheme">Controller scheme for the player(Controller or keyboard)</param>
        public Player(ContentManager content, ref PhysicsEnvironment environment, IControlScheme controlScheme, float friction, EntityInfo entity)
            : base(content, ref environment,friction, entity)
        {
            _mControls = controlScheme;
            SpawnPoint = MPosition;
            _mRotation = 0.0f;
            _mGoalRotation = 0.0f;

            _mFaceGoalRotation = 0.0f;
            _mFaceRotation = 0.0f;

            Id = entity.MId;

            PlayerFaces.Load(content);

            MCurrentTexture = PlayerFaces.FromString("Smile");
            MSize = new Vector2(MCurrentTexture.Width, MCurrentTexture.Height);
            _mPreviousDirection = GravityDirections.Down;
        }
Beispiel #2
0
        /// <summary>
        /// Goes through all the entities and finds all of the ones that are Static, or physics(Dynamic maybe in the future)
        /// Creates and returns them using the data found in the xml file
        /// </summary>
        /// <param name="environment">Environment that these items exist in</param>
        /// <returns>A list of objects that are in the game</returns>
        public List<GameObject> GetObjects(ref PhysicsEnvironment environment)
        {
            var objects = new List<GameObject>();
            foreach (var entity in _mEntities)
            {
                //If the object is static, make a static object
                if (entity.MType == XmlKeys.StaticObject)
                {
                    var tile = new Tile(_mContent, .8f, entity);
                    objects.Add(tile);

                }
                //If the object is physics, make a physics object
                if (entity.MType == XmlKeys.PhysicsObject)
                {
                    if (entity.MProperties.ContainsKey("Rail") && entity.MProperties.ContainsKey("Length"))
                        _mRails.Add(entity);

                    var isSquare = entity.MProperties.ContainsKey("Shape") && entity.MProperties["Shape"] == "Square";
                    float mass = 1;
                    if (entity.MProperties.ContainsKey("Mass"))
                    {
                        mass = (float)Convert.ToDouble(entity.MProperties["Mass"]);
                    }
                    if (entity.MProperties.ContainsKey(XmlKeys.Reverse))
                    {
                        var rTile = new ReverseTile(_mContent, ref environment, 0.8f, entity);
                        rTile.Mass = mass;
                        objects.Add(rTile);
                    }
                    else
                    {
                        var mTile = new MovingTile(_mContent, ref environment, 0.8f, entity);
                        mTile.Mass = mass;
                        objects.Add(mTile);
                    }
                }
            }

            return objects;
        }
Beispiel #3
0
        /// <summary>
        /// Goes through all the entities and finds all of the ones that are Static, or physics(Dynamic maybe in the future)
        /// Creates and returns them using the data found in the xml file
        /// </summary>
        /// <param name="environment">Environment that these items exist in</param>
        /// <returns>A list of objects that are in the game</returns>
        public List<GameObject> GetObjects(ref PhysicsEnvironment environment)
        {
            List<GameObject> objects = new List<GameObject>();
            foreach (EntityInfo entity in mEntities)
            {
                //If the object is static, make a static object
                if (entity.mType == XmlKeys.STATIC_OBJECT)
                {
                    Tile tile = new Tile(mContent, .8f, entity);
                    objects.Add(tile);

                }
                //If the object is physics, make a physics object
                if (entity.mType == XmlKeys.PHYSICS_OBJECT)
                {
                    if (entity.mProperties.ContainsKey("Rail") && entity.mProperties.ContainsKey("Length"))
                        mRails.Add(entity);

                    bool isSquare = entity.mProperties.ContainsKey("Shape") && entity.mProperties["Shape"] == "Square";
                    float mass = 1;
                    if (entity.mProperties.ContainsKey("Mass"))
                    {
                        mass = (float)Convert.ToDouble(entity.mProperties["Mass"]);
                    }
                    if (entity.mProperties.ContainsKey(XmlKeys.REVERSE))
                    {
                        ReverseTile rTile = new ReverseTile(mContent, ref environment, 0.8f, entity);
                        rTile.Mass = mass;
                        objects.Add(rTile);
                    }
                    else
                    {
                        MovingTile mTile = new MovingTile(mContent, ref environment, 0.8f, entity);
                        mTile.Mass = mass;
                        objects.Add(mTile);
                    }
                }
            }

            return objects;
        }
Beispiel #4
0
        /// <summary>
        /// Constructs a PhysicsObject; Loads the required info from the content pipeline, and defines its size and location
        /// </summary>
        /// <param name="content">Content pipeline</param>
        /// <param name="spriteBatch">The drawing canvas of the game. Used for collision detection with the level</param>
        /// <param name="name">Name of the physics object so that it can be loaded</param>
        /// <param name="scalingFactors">Factor for the image resource(i.e. half the size would be (.5,.5)</param>
        /// <param name="initialPosition">Position of where this object starts in the level</param>
        public PhysicsObject(ContentManager content, ref PhysicsEnvironment environment, float friction, EntityInfo entity)
            : base(content, friction, entity)
        {
            MEnvironment = environment;
            Velocity = new Vector2(0, 0);
            _mOriginalPosition = OriginalInfo.MLocation;
            IsRail = OriginalInfo.MProperties.ContainsKey(XmlKeys.Rail);

            if (IsRail)
                if (OriginalInfo.MProperties[XmlKeys.Rail] == XmlKeys.RailX)
                {
                    _mHiBound = GridSpace.GetDrawingCoord(_mOriginalPosition).X + (int.Parse(OriginalInfo.MProperties[XmlKeys.Length]) * 64);
                    _mLowBound = GridSpace.GetDrawingCoord(_mOriginalPosition).X;
                    _mAxis = GridSpace.GetDrawingCoord(_mOriginalPosition).Y;
                }
                else
                {
                    _mHiBound = GridSpace.GetDrawingCoord(_mOriginalPosition).Y + (int.Parse(OriginalInfo.MProperties[XmlKeys.Length]) * 64);
                    _mLowBound = GridSpace.GetDrawingCoord(_mOriginalPosition).Y;
                    _mAxis = GridSpace.GetDrawingCoord(_mOriginalPosition).X;
                }
            else
                _mHiBound = _mLowBound = _mAxis = 0;

            UpdateBoundingBoxes();
            MMass = 1;
        }
Beispiel #5
0
 /// <summary>
 /// Constructs a tile that reacts to gravity in the opposite direction
 /// </summary>
 /// <param name="content">The games content manager</param>
 /// <param name="name">Name of the Object("Images/{Type}/{Name}"</param>
 /// <param name="initialPosition">Starting position</param>
 /// <param name="friction">Friction that reacts to physics objects</param>
 /// <param name="isSquare">True if the object should behave like a square</param>
 /// <param name="isHazardous">True if the object should kill the player when touched</param>
 public ReverseTile(ContentManager content, ref PhysicsEnvironment environment, float friction, EntityInfo entity)
     : base(content, ref environment, friction, entity)
 {
     BeingAnimated = false;
     _mAnimationTexture = new AnimatedSprite();
 }