예제 #1
0
        //TODO: Implement a collision detection between moving objects
        /// <summary>
        /// Handels Collision between a moving object (i.e. the player or an npc) and the level structure
        /// </summary>
        /// <param name="levelBlock">The levelBlock which the object could collide with</param>
        /// <param name="moveableObject">the animatedobject that needs to be checked</param>
        public void HandleLevelCollisions(LevelBlock levelBlock, MovingObject moveableObject)
        {
            if (levelBlock.IntersectRectangle.Intersects(moveableObject.IntersectRectangle))
            {
                if (moveableObject.PrevPosition.Y > levelBlock.IntersectRectangle.Bottom)
                {
                    moveableObject.Position = moveableObject.PrevPosition;
                    if (moveableObject is Player)
                    {
                        ((Player)moveableObject).AbortJump();
                    }

                }
                else if (levelBlock.IsAboveLevelObject(moveableObject))
                {

                    moveableObject.Position = new Vector2(moveableObject.Position.X,
                                                          levelBlock.Position.Y - moveableObject.Size.Y);
                }
                else if (levelBlock.Position.X > moveableObject.Position.X)
                {
                    moveableObject.Position = new Vector2(moveableObject.PrevPosition.X, moveableObject.Position.Y);
                }
                else if (levelBlock.Position.X < moveableObject.Position.X)
                {
                    moveableObject.Position = new Vector2(moveableObject.PrevPosition.X, moveableObject.Position.Y);
                }
            }
        }
예제 #2
0
파일: Level.cs 프로젝트: Rosthouse/JumpNRun
        public void MoveToEnd(LevelBlock levelBlock, List<LevelBlock> list)
        {
            LevelBlock temp = levelBlock;

            list.Remove(levelBlock);

            temp.Position = new Vector2(list.Last().Position.X + temp.Texture.Width, temp.Position.Y);

            list.Add(temp);
        }
예제 #3
0
        private void WriteLevelBlock(XmlNode node, LevelBlock levelBlock, XmlDocument xmlDocument)
        {
            XmlNode textureAsset = xmlDocument.CreateNode(XmlNodeType.Element, "TextureAsset", null);
            textureAsset.InnerText = levelBlock.TextureAsset;

            XmlNode isVisible = WriteBool(xmlDocument, "isVisible", levelBlock.IsVisible);

            XmlNode position = WriteVector2(xmlDocument, "Position", levelBlock.Position);

            node.AppendChild(textureAsset);
            node.AppendChild(isVisible);
            node.AppendChild(position);
        }
예제 #4
0
        private void ReadLevelBlock(XmlNodeList nodes, List<LevelBlock> blocks)
        {
            foreach (XmlNode node in nodes)
            {
                string textureAsset = node["TextureAsset"].InnerText;
                Vector2 position = ReadVector2(node["Position"]);

                LevelBlock currentBlock = new LevelBlock(textureAsset, position);
                blocks.Add(currentBlock);
            }
        }
예제 #5
0
 private void HitWall(MovingObject collider, LevelBlock levelBlock)
 {
 }