Example #1
0
        public void onMouseHover(BackgroundObject backgroundObject)
        {
            Character player1  = SceneManager.getInstance.getPlayer1();
            bool      doAction = player1.getDoAction();
            string    name     = backgroundObject.Name;

            hoveringOverThisFrame = true;

            if (name != null)
            {
                Vector2 playerPos       = player1.Properties.getProperty <Vector2>("Position");
                Vector2 staticObjectPos = backgroundObject.Properties.getProperty <Vector2>("Position");

                Vector2 newVector = playerPos - staticObjectPos;
                float   distance  = newVector.Length();

                if (distance <= backgroundObject.getInteractionDistance())
                {
                    if (name == "Field" || name == "FieldWithFood") // || name == "FieldFertilised"
                    {
                        backgroundObject.setMouseIsHovering(true);

                        if (name == "Field")
                        {
                            if (SceneManager.getInstance.getPlayer1().hasShovel())
                            {
                                foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                                {
                                    if (texture.Key == "Pickaxe")
                                    {
                                        Properties.updateProperty <Texture2D>("Texture2D", texture.Value);
                                    }
                                }
                            }
                        }
                        else if (name == "FieldWithFood")
                        {
                            foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                            {
                                if (texture.Key == "Mouse")
                                {
                                    Properties.updateProperty <Texture2D>("Texture2D", texture.Value);
                                }
                            }
                        }

                        if (doAction)
                        {
                            backgroundObject.onInteract();
                        }
                    }
                    else
                    {
                    }
                }
            }
        }