예제 #1
0
        /// <summary>
        /// Calls the appropriate check function against the type of the inputted collider.
        /// </summary>
        /// <param name="collider">The collider to check against</param>
        /// <returns>Returns true if a collision occurred</returns>
        public virtual bool CheckCollisionWith(Collider collider)
        {
            RectangleCollider rectangleCollider = collider as RectangleCollider;

            if (rectangleCollider != null)
            {
                bool result = CheckCollisionWith(rectangleCollider);
                CollidedThisFrame = CollidedThisFrame || result;

                return(result);
            }

            CircleCollider circleCollider = collider as CircleCollider;

            if (circleCollider != null)
            {
                bool result = CheckCollisionWith(rectangleCollider);
                CollidedThisFrame = CollidedThisFrame || result;

                return(result);
            }

            DebugUtils.Fail("Checking against an unknown collider.");
            return(false);
        }
        /// <summary>
        /// Returns the appropriate texture based on what type of tile we are creating
        /// </summary>
        /// <returns></returns>
        private string QueryTextureAsset()
        {
            switch (QueryPositionType())
            {
            case Position.kLeft:
                return(GenerationData.WalkableLayerLeftTextureAsset);

            case Position.kMiddle:
                return(GenerationData.WalkableLayerMiddleTextureAsset);

            case Position.kRight:
                return(GenerationData.WalkableLayerRightTextureAsset);

            default:
                DebugUtils.Fail("No texture asset for this direction");
                return("");
            }
        }
예제 #3
0
        /// <summary>
        /// Deserialize the xml file represented by the inputted path and return it casted to the type T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xmlFilePath"></param>
        /// <returns></returns>
        public static T Deserialize <T>(string xmlFilePath)
        {
            // Create and load the XML document.
            XDocument doc = null;

            try
            {
                doc = XDocument.Load(xmlFilePath);
            }
            catch (Exception e)
            {
                DebugUtils.Fail("There was a problem loading the XML file with path " + xmlFilePath);
                return(default(T));
            }

            // Create an XmlReader using the XML document.
            XmlReader nodeReader = doc.CreateReader();

            // Move to the XnaContent element - this is to support backwards compatibility with our existing data files
            // One day we may run a script to change them all
            Debug.Assert(nodeReader.ReadToDescendant("XnaContent"), "No XnaContent element found as root tag");

            // Now move to the Asset element - this contains the name of the type we are trying to load
            Debug.Assert(nodeReader.ReadToDescendant("Asset"), "No Asset element found");

            // Obtain the Type attribute so we can reflectively work out the type
            string dataType = nodeReader.GetAttribute("Type");

            // Get the assembly for the type we are trying to load - this has to pass
            Assembly assembly = null;

            Debug.Assert(TryGetAssembly(ref dataType, out assembly));

            // Move either to the </Asset> tag if we have no data to load, or to the first data element
            nodeReader.Read();

            // Load the type
            return(ReadType <T>(nodeReader, assembly, dataType));
        }
예제 #4
0
        /// <summary>
        /// Loads all the assets of an inputted type that exist in our Content folder
        /// </summary>
        /// <typeparam name="T">The type of asset to load</typeparam>
        /// <param name="content">The ContentManager we will use to load our content</param>
        /// <param name="path">The path of the assets we wish to load</param>
        /// <returns>Returns the dictionary of all loading content</returns>
        private static Dictionary <string, T> Load <T>(ContentManager content, string path)
        {
            Dictionary <string, T> objects = new Dictionary <string, T>();
            List <string>          files   = AssetCollectionManager.AssetCollectionTechnique != null?AssetCollectionManager.AssetCollectionTechnique.GetAllXnbFilesInDirectory(content, path) : new List <string>();

            for (int i = 0; i < files.Count; i++)
            {
                // Remove the directoryPath from the start of the string
                files[i] = files[i].Remove(0, path.Length + 2);

                // Remove the .xnb at the end
                files[i] = files[i].Split('.')[0];

                try
                {
                    objects.Add(files[i], LoadAssetFromDisc <T>(Path.Combine(path, files[i])));
                }
                catch { DebugUtils.Fail("Problem loading asset: " + files[i]); }
            }

            return(objects);
        }
예제 #5
0
        /// <summary>
        /// Performs JUST debug checks on the data and texture asset.
        /// Then makes sure our texture asset is set for loading
        /// </summary>
        public override void LoadContent()
        {
            // Check to see if we should load
            CheckShouldLoad();

            // Either we have a valid data asset and valid data or we have set a texture asset
            if (!string.IsNullOrEmpty(DataAsset))
            {
                // Make sure we always load and set the texture asset - even with no asserts
                if (Data == null)
                {
                    DebugUtils.Fail("Data cannot be null");
                }
            }
            else
            {
                // If we have got in here, the data asset was not specified and so our texture asset was manually set.
                // Should check that this is true.
                Debug.Assert(Data != null || !string.IsNullOrEmpty(TextureAsset));
            }

            // This will handle the loading if not done so already.
            base.LoadContent();
        }
예제 #6
0
 /// <summary>
 /// No drawing in commands
 /// </summary>
 /// <param name="spriteBatch"></param>
 public override void Draw(SpriteBatch spriteBatch)
 {
     // No drawing for commands
     DebugUtils.Fail("No drawing in commands");
 }
예제 #7
0
 /// <summary>
 /// Saves data to an XML file on disc.
 /// </summary>
 /// <typeparam name="T">THe type of data we wish to save</typeparam>
 /// <param name="data">The data we are saving</param>
 /// <param name="path">The full path of where to save the data e.g. "Screens\\MainMenuScreen"</param>
 public static void SaveData <T>(T data, string path) where T : BaseData
 {
     DebugUtils.AssertNotNull(data);
     DebugUtils.Fail("TODO");
     //XmlDataSerializer.Serialize(data, ScreenManager.Instance.Content.FullRootDirectory() + "\\" + DataPath + path);
 }
예제 #8
0
 /// <summary>
 /// Stops the thread and triggers the finished callback if not null
 /// </summary>
 public void Stop()
 {
     RequestStop = true;
     DebugUtils.Fail("Not implemented yet - look at CancellationTokenSource");
 }