Esempio n. 1
0
        private void UpdateGameObjects()
        {
            if (currentObject != null)
            {
                Vector2 translationVector = new Vector2();

                // TODO: replace with A* pathfinding
                if (currentObject.Position.X < tileToMoveTo.Position.X)
                {
                    translationVector += new Vector2(1.0f, 0.0f);
                }
                else if (currentObject.Position.X > tileToMoveTo.Position.X)
                {
                    translationVector += new Vector2(-1.0f, 0.0f);
                }
                else if (currentObject.Position.Y < tileToMoveTo.Position.Y)
                {
                    translationVector += new Vector2(0.0f, 1.0f);
                }
                else if (currentObject.Position.Y > tileToMoveTo.Position.Y)
                {
                    translationVector += new Vector2(0.0f, -1.0f);
                }

                currentObject.Translate(translationVector);

                if (currentObject.Position == tileToMoveTo.Position)
                {
                    currentObject.ReachedDestination();
                    currentObject  = null;
                    performingMove = false;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Place the object at the tile by passed position and set the tile properties
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="position"></param>
        public void SetObjectToTilePosition(BattleSceneGameObject gameObject, Vector2 position)
        {
            Tile newTile = GetTileAtPosition(position);

            newTile.Occupied       = true;
            gameObject.CurrentTile = newTile;
            gameObject.Position    = newTile.Position;
        }
Esempio n. 3
0
        /// <summary>
        ///  Find the tile at the position clicked and move the object to that position
        ///  This has to take a character object right now. Not sure if they will ever have to
        ///  to take anything other than a character
        /// </summary>
        /// <param name="character"></param>
        /// <param name="position"></param>
        public void MoveObjectToTileAtPosition(Character character, Vector2 position)
        {
            int tileX = (int)(position.X / (TILE_WIDTH));
            int tileY = (int)(position.Y / (TILE_HEIGHT));

            tileToMoveTo = tileset[tileX, tileY];

            if (!tileToMoveTo.Occupied &&
                tileX >= 0 && tileX <= tilesetWidth &&
                tileY >= 0 && tileY <= tilesetHeight && !performingMove)
            {
                performingMove          = true;
                character.ActionPoints -= 2;

                Tile previousTile = character.CurrentTile;
                previousTile.Occupied = false;

                tileToMoveTo.CurrentObject = character;
                tileToMoveTo.Occupied      = true;

                currentObject             = character;
                currentObject.CurrentTile = tileToMoveTo;
            }
        }