Ejemplo n.º 1
0
        //-----------------------------------------------------------------------------
        // Initialization
        //-----------------------------------------------------------------------------

        public void Initialize(RoomControl control)
        {
            this.roomControl = control;
            this.isAlive     = true;

            if (!isInitialized)
            {
                isInitialized = true;
                hasMoved      = false;
                velocity      = Vector2F.Zero;

                graphics.ImageVariant = roomControl.Room.Zone.ImageVariantID;

                // Begin a path if there is one.
                string   pathString = properties.GetString("path", "");
                TilePath p          = TilePath.Parse(pathString);
                BeginPath(p);

                // Set the solid state.
                isSolid = (SolidType != TileSolidType.NotSolid);

                // Setup default drop list.
                if (IsDigable && !IsSolid)
                {
                    dropList = RoomControl.GameControl.DropManager.GetDropList("dig");
                }
                else
                {
                    dropList = RoomControl.GameControl.DropManager.GetDropList("default");
                }

                // Call the virtual initialization method.
                OnInitialize();
            }
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------
        // Static Methods
        //-----------------------------------------------------------------------------

        public static TilePath Parse(string str)
        {
            string[] commands = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (commands.Length == 0)
            {
                return(null);
            }

            TilePath path  = new TilePath();
            float    speed = 1.0f;
            int      delay = 0;

            for (int i = 0; i < commands.Length; i++)
            {
                string[] tokens = commands[i].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length == 0)
                {
                    continue;
                }

                if (tokens[0] == "right")
                {
                    path.AddMove(Directions.Right, Int32.Parse(tokens[1]), speed, delay);
                    delay = 0;
                }
                else if (tokens[0] == "left")
                {
                    path.AddMove(Directions.Left, Int32.Parse(tokens[1]), speed, delay);
                    delay = 0;
                }
                else if (tokens[0] == "up")
                {
                    path.AddMove(Directions.Up, Int32.Parse(tokens[1]), speed, delay);
                    delay = 0;
                }
                else if (tokens[0] == "down")
                {
                    path.AddMove(Directions.Down, Int32.Parse(tokens[1]), speed, delay);
                    delay = 0;
                }
                else if (tokens[0] == "speed")
                {
                    speed = Single.Parse(tokens[1]);
                }
                else if (tokens[0] == "pause")
                {
                    delay += Int32.Parse(tokens[1]);
                }
                else if (tokens[0] == "repeat")
                {
                    path.repeats = true;
                }
            }

            if (path.moves.Count == 0)
            {
                return(null);
            }
            return(path);
        }
Ejemplo n.º 3
0
        }                                           // This is to make sure tiles are only updated once per frame.


        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------

        // Use Tile.CreateTile() instead of this constructor.
        protected Tile()
        {
            tileGridArea     = Rectangle2I.Zero;
            isAlive          = false;
            isInitialized    = false;
            location         = Point2I.Zero;
            layer            = 0;
            offset           = Point2I.Zero;
            size             = Point2I.One;
            spriteAsObject   = new SpriteAnimation();
            isSolid          = false;
            isMoving         = false;
            pushDelay        = 20;
            properties       = new Properties(this);
            tileData         = null;
            moveDirection    = Point2I.Zero;
            dropList         = null;
            hasMoved         = false;
            path             = null;
            pathTimer        = 0;
            pathMoveIndex    = 0;
            fallsInHoles     = true;
            soundMove        = GameData.SOUND_BLOCK_PUSH;
            conveyorVelocity = Vector2F.Zero;
            surfaceTile      = null;
            collisionStyle   = CollisionStyle.Rectangular;
            graphics         = new TileGraphicsComponent(this);
        }
Ejemplo n.º 4
0
        //-----------------------------------------------------------------------------
        // Static Methods
        //-----------------------------------------------------------------------------
        public static TilePath Parse(string str)
        {
            string[] commands = str.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
            if (commands.Length == 0)
                return null;

            TilePath path = new TilePath();
            float speed = 1.0f;
            int delay = 0;

            for (int i = 0; i < commands.Length; i++) {
                string[] tokens = commands[i].Split(new char[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length == 0)
                    continue;

                if (tokens[0] == "right") {
                    path.AddMove(Directions.Right, Int32.Parse(tokens[1]), speed, delay);
             					delay = 0;
                }
                else if (tokens[0] == "left") {
                    path.AddMove(Directions.Left, Int32.Parse(tokens[1]), speed, delay);
             					delay = 0;
                }
                else if (tokens[0] == "up") {
                    path.AddMove(Directions.Up, Int32.Parse(tokens[1]), speed, delay);
             					delay = 0;
                }
                else if (tokens[0] == "down") {
                    path.AddMove(Directions.Down, Int32.Parse(tokens[1]), speed, delay);
             					delay = 0;
                }
                else if (tokens[0] == "speed")
                    speed = Single.Parse(tokens[1]);
                else if (tokens[0] == "pause")
                    delay += Int32.Parse(tokens[1]);
                else if (tokens[0] == "repeat")
                    path.repeats = true;
            }

            if (path.moves.Count == 0)
                return null;
            return path;
        }
Ejemplo n.º 5
0
        private void UpdateMovement()
        {
            // Update movement.
            if (isMoving)
            {
                velocity = (Vector2F)moveDirection * movementSpeed;

                if (offset.Dot(moveDirection) >= 0.0f)
                {
                    currentMoveDistance++;
                    offset -= (Vector2F)(moveDirection * GameSettings.TILE_SIZE);

                    if (currentMoveDistance >= moveDistance)
                    {
                        offset        = Vector2F.Zero;
                        velocity      = Vector2F.Zero;
                        moveDirection = Point2I.Zero;
                        isMoving      = false;
                        CheckSurfaceTile();
                        if (IsDestroyed)
                        {
                            return;
                        }
                        OnCompleteMovement();
                    }
                    else
                    {
                        roomControl.MoveTile(this, location + moveDirection, layer);
                    }
                }
                else if (currentMoveDistance + 1 >= moveDistance)
                {
                    // Don't overshoot the destination.
                    float overshoot = (offset + velocity).Dot(moveDirection);
                    if (overshoot >= 0.0f)
                    {
                        velocity -= overshoot * (Vector2F)moveDirection;
                    }
                }
            }
            // Update path following.
            else if (path != null)
            {
                TilePathMove move = path.Moves[pathMoveIndex];

                // Begin the next move in the path after the delay has been passed.
                if (pathTimer >= move.Delay)
                {
                    Move(move.Direction, move.Distance, move.Speed);
                    pathTimer = 0;
                    pathMoveIndex++;
                    if (pathMoveIndex >= path.Moves.Count)
                    {
                        if (path.Repeats)
                        {
                            pathMoveIndex = 0;
                        }
                        else
                        {
                            path = null;
                        }
                    }
                }

                pathTimer++;
            }

            // Integrate velocity.
            if (isMoving)
            {
                offset += velocity;
            }
            else
            {
                velocity = Vector2F.Zero;
            }
        }
Ejemplo n.º 6
0
        //-----------------------------------------------------------------------------
        // Movement
        //-----------------------------------------------------------------------------

        // Begin following a path.
        public void BeginPath(TilePath path)
        {
            this.path     = path;
            pathMoveIndex = 0;
            pathTimer     = 0;
        }
Ejemplo n.º 7
0
        private void UpdateMovement()
        {
            // Update movement.
            if (isMoving) {
                velocity = (Vector2F) moveDirection * movementSpeed;

                if (offset.Dot(moveDirection) >= 0.0f) {
                    currentMoveDistance++;
                    offset -= (Vector2F) (moveDirection * GameSettings.TILE_SIZE);

                    if (currentMoveDistance >= moveDistance) {
                        offset			= Vector2F.Zero;
                        velocity		= Vector2F.Zero;
                        moveDirection	= Point2I.Zero;
                        isMoving		= false;
                        CheckSurfaceTile();
                        if (IsDestroyed)
                            return;
                        OnCompleteMovement();
                    }
                    else {
                        roomControl.MoveTile(this, location + moveDirection, layer);
                    }
                }
                else if (currentMoveDistance + 1 >= moveDistance) {
                    // Don't overshoot the destination.
                    float overshoot = (offset + velocity).Dot(moveDirection);
                    if (overshoot >= 0.0f) {
                        velocity -= overshoot * (Vector2F) moveDirection;
                    }
                }
            }
            // Update path following.
            else if (path != null) {
                TilePathMove move = path.Moves[pathMoveIndex];

                // Begin the next move in the path after the delay has been passed.
                if (pathTimer >= move.Delay) {
                    Move(move.Direction, move.Distance, move.Speed);
                    pathTimer = 0;
                    pathMoveIndex++;
                    if (pathMoveIndex >= path.Moves.Count) {
                        if (path.Repeats)
                            pathMoveIndex = 0;
                        else
                            path = null;
                    }
                }

                pathTimer++;
            }

            // Integrate velocity.
            if (isMoving)
                offset += velocity;
            else
                velocity = Vector2F.Zero;
        }
Ejemplo n.º 8
0
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 // Use Tile.CreateTile() instead of this constructor.
 protected Tile()
 {
     tileGridArea	= Rectangle2I.Zero;
     isAlive				= false;
     isInitialized		= false;
     location			= Point2I.Zero;
     layer				= 0;
     offset				= Point2I.Zero;
     size				= Point2I.One;
     spriteAsObject		= new SpriteAnimation();
     isSolid				= false;
     isMoving			= false;
     pushDelay			= 20;
     properties			= new Properties(this);
     tileData			= null;
     moveDirection		= Point2I.Zero;
     dropList			= null;
     hasMoved			= false;
     path				= null;
     pathTimer			= 0;
     pathMoveIndex		= 0;
     fallsInHoles		= true;
     soundMove			= GameData.SOUND_BLOCK_PUSH;
     conveyorVelocity	= Vector2F.Zero;
     surfaceTile			= null;
     collisionStyle		= CollisionStyle.Rectangular;
     graphics			= new TileGraphicsComponent(this);
 }
Ejemplo n.º 9
0
 //-----------------------------------------------------------------------------
 // Movement
 //-----------------------------------------------------------------------------
 // Begin following a path.
 public void BeginPath(TilePath path)
 {
     this.path = path;
     pathMoveIndex = 0;
     pathTimer = 0;
 }