Esempio n. 1
0
        /// <summary>
        /// Call this to initialize a Behaviour with data supplied in a file.
        /// </summary>
        /// <param name="fileName">The file to load from.</param>
        public override void LoadContent(String fileName)
        {
            base.LoadContent(fileName);

            ObjectPlacementDefinition def = GameObjectManager.pInstance.pContentManager.Load <ObjectPlacementDefinition>(fileName);

            mCursor           = new GameObject("GameObjects\\Interface\\PlacementCursor\\PlacementCursor");
            mCursor.pPosition = mParentGOH.pPosition;
            GameObjectManager.pInstance.Add(mCursor);

            mCursorOffset = Vector2.Zero;

            mItemOffset     = new Vector2(-4, -4);
            mItemSourceRect = new Rectangle(0, 0, 8, 8);
            mItemColor      = new Color(255, 255, 255, 200);

            mAbsOffsetRange = def.mAbsOffsetRange;

            mRemoveClassifications = new List <MBHEngineContentDefs.GameObjectDefinition.Classifications>(1);
            mRemoveClassifications.Add(MBHEngineContentDefs.GameObjectDefinition.Classifications.WALL);

            mGetTileAtPositionMsg     = new Level.GetTileAtPositionMessage();
            mGetMapInfoMsg            = new Level.GetMapInfoMessage();
            mSetTileTypeAtPositionMsg = new Level.SetTileTypeAtPositionMessage();
            mGetCurrentObjectMsg      = new Inventory.GetCurrentObjectMessage();
            mOnPlaceObjectMsg         = new OnPlaceObjectMessage();
            mAddObjectMsg             = new Inventory.AddObjectMessage();
            mSelectNextItemMsg        = new Inventory.SelectNextItemMessage();
            mGetTexture2DMsg          = new SpriteRender.GetTexture2DMessage();
            mPeekCurrentObjectMsg     = new Inventory.PeekCurrentObjectMessage();
        }
Esempio n. 2
0
        /// <summary>
        /// The main interface for communicating between behaviours.  Using polymorphism, we
        /// define a bunch of different messages deriving from BehaviourMessage.  Each behaviour
        /// can then check for particular upcasted messahe types, and either grab some data
        /// from it (set message) or store some data in it (get message).
        /// </summary>
        /// <param name="msg">The message being communicated to the behaviour.</param>
        public override void OnMessage(ref BehaviourMessage msg)
        {
            if (msg is ObjectPlacement.OnPlaceObjectMessage)
            {
                ObjectPlacement.OnPlaceObjectMessage temp = (ObjectPlacement.OnPlaceObjectMessage)msg;

                // By default assume the object could not be placed.
                temp.mObjectPlaced_Out = false;

                // The level needs to have this tile set to be Solid.
                mSetTileTypeAtPositionMsg.mType_In     = Level.Tile.TileTypes.Solid;
                mSetTileTypeAtPositionMsg.mPosition_In = temp.mPosition_In;
                WorldManager.pInstance.pCurrentLevel.OnMessage(mSetTileTypeAtPositionMsg, mParentGOH);

                // Only spawn a tile if we actually changed the tile type.
                if (mSetTileTypeAtPositionMsg.mType_In != mSetTileTypeAtPositionMsg.mPreviousType_Out)
                {
                    mParentGOH.pPosition = temp.mPosition_In;

                    temp.mObjectPlaced_Out = true;

                    // Note: We don't need to add this object to the GameObjectManager; the default
                    //       ObjectPlacement will handle that when it sees that mOutObjectPlaced is
                    //       true.
                }
            }
        }