Exemplo n.º 1
0
        public void LoadContent(ContentManager content, Map map, string mapID)
        {
            layer = new Layer();
            collision = new Collision();
            id = mapID;

            layer.LoadContent(map, "Layer1");
            collision.LoadContent(content, mapID);
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime, InputManager inputManager, Collision col, Layers layer)
        {
            moveAnimation.IsActive = true;
            if (inputManager.KeyDown(Keys.Right, Keys.D))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2);
                position.X += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else if (inputManager.KeyDown(Keys.Left, Keys.A))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
                position.X -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else if (inputManager.KeyDown(Keys.Down, Keys.S))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
                position.Y += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else if (inputManager.KeyDown(Keys.Up, Keys.W))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3);
                position.Y -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else
            {
                moveAnimation.IsActive = false;
            }

            for (int i = 0; i < col.CollisionMap.Count; i++)
            {
                for (int j = 0; j < col.CollisionMap[i].Count; j++)
                {
                    if (col.CollisionMap[i][j] == "x") //check only for obstructed tiles
                    {
                        if (position.X + moveAnimation.FrameWidth < j * layer.TileDimensions.X ||
                            position.X > j * layer.TileDimensions.X + layer.TileDimensions.X ||
                            position.Y + moveAnimation.FrameHeight < i * layer.TileDimensions.Y ||
                            position.Y > i * layer.TileDimensions.Y + layer.TileDimensions.Y)
                        {
                            //no collision
                        }
                        else
                        {
                            position = moveAnimation.Position; //move animation position is last frame position
                        }
                    }
                }
            }

            moveAnimation.Position = position;
            ssAnimation.Update(gameTime, ref moveAnimation);
        }
Exemplo n.º 3
0
 public override void Update(GameTime gameTime, InputManager inputManager, Collision col, Layers layer)
 {
 }
Exemplo n.º 4
0
 public virtual void Update(GameTime gameTime, InputManager inputManager, Collision col, Layers layer)
 {
 }