Game-Design / Sprint3_actual / Blocks / MovableBlock.cs
MovableBlock.cs
Raw
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System;
using System.Collections.Generic;
using System.Text;
using Sprint3_actual.SpriteFactories;
using Sprint3_actual.Collision_Detection;
using Sprint3_actual.StateFiles;

namespace Sprint3_actual.Blocks
{
    class MovableBlock : IBlock
    {

        private ISprite sprite;
        private Rectangle posRectangle;
        private bool canMove;
        private int pushTimer;
        private bool removed;
        private const int blockWH = 48;
        private Vector2 MoveDirection;

        public MovableBlock(int xPos, int yPos, int blockType)
        {
            this.removed = false;
            this.posRectangle = new Rectangle(xPos, yPos, blockWH, blockWH);
            this.sprite = BlockSpriteFactory.Instance.CreateBlock(1, this);
            this.canMove = true;
            this.pushTimer = 48;
            if(blockType == 1)
            {
                //Block can move up
                MoveDirection = -Vector2.UnitY;
            } 
            else if (blockType == 2)
            {
                //Block can move Left
                MoveDirection = -Vector2.UnitX;
            }
            else if (blockType == 3)
            {
                //Block can move right
                MoveDirection = Vector2.UnitX;
            }
            else
            {
                //Block can move left
                MoveDirection = Vector2.UnitY;
            }
        }

        public Rectangle getPos()
        {
            return posRectangle;

        }

        public void DrawBlock()
        {
            sprite.draw();

        }

        public void UpdateBlock()
        {
            if (!canMove && pushTimer > 0)
            {
                posRectangle.X += (int)MoveDirection.X;
                posRectangle.Y += (int)MoveDirection.Y;
                pushTimer--;
            }
        }


        public void Collide()
        {
            this.canMove = false;
        }

        public bool IsRemoved()
        {
            return removed;
        }

        public bool isMovable()
        {
            return this.canMove;
        }

        public bool isExit()
        {
            return false;
        }

    }
}