示例#1
0
 /*
  * Starts and initializes blending for an object
  * blendingTexture: The texture to blend into this objects current texture
  * blendingColor: the blending start color
  * name: The name the finished blended object will have
  * time: The time in seconds it takes for each update to the colors alpha value
  * alpha: how much alpha the color will increase with on each time update
  * */
 public void startBlending(Texture2D blendingTexture, Color blendingColor, string name, float time, byte alpha)
 {
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).BlendingTexture   = blendingTexture;
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).BlendingColor     = blendingColor;
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).BlenderName       = name;
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).BlendingTime      = time;
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).BlendingAlphaByte = alpha;
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).IsBlending        = true;
 }
示例#2
0
        public MouseCursor(Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale, string name)
        {
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, 0.0f));

            position += Input.getInstance.getMousePosRelativeToScreen();

            ((RenderComponent)DrawableComponents.ElementAt(0).Value).IsMouse = true;

            Name = name;
            interactionDistance = 200.0f;

            foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
            {
                if (texture.Key == "Mouse")
                {
                    Properties.updateProperty <Texture2D>("Texture2D", texture.Value);
                }
            }
        }
示例#3
0
 public void startRotation(float degrees, int time)
 {
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).Rotate = true;
 }
示例#4
0
        public void onInteract()
        {
            Character player1   = SceneManager.getInstance.getPlayer1();
            Vector2   playerPos = player1.Properties.getProperty <Vector2>("Position");

            if (Name == "Screw" || Name == "Plank" || Name == "Cement" || Name == "OilCan")
            {
                player1.getInventory().getResources().increaseResource(Name, 1);
                //player1.getInventory().getResources().numberOfResources();
                Active = false;

                AudioManager.getInstance.playSound(new Sound("Pickup"), AudioManager.PICKUP);
            }
            else if (Name == "Instructor")
            {
                SceneManager.getInstance.setGameState(GameState.IN_INGAMEMENU);
                SceneManager.getInstance.getMenuManager().findIndex("MissionMenu");

                AudioManager.getInstance.playSound(new Sound("Convers start"), AudioManager.CONVERS_START);
            }
            else if (Name == "Lab")
            {
                SceneManager.getInstance.setGameState(GameState.IN_INGAMEMENU);
                SceneManager.getInstance.getMenuManager().findIndex("MainLabMenu");

                AudioManager.getInstance.playSound(new Sound("Lab sounds"), AudioManager.LAB_SOUNDS);
            }
            else if (Name == "DeadTree" && SceneManager.getInstance.getPlayer1().hasFantasyTool())
            {
                bool isBlending = ((RenderComponent)DrawableComponents.ElementAt(0).Value).IsBlending;

                if (!isBlending)
                {
                    foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                    {
                        if (texture.Key == "TreeWithFood")
                        {
                            AudioManager.getInstance.playSound(new Sound("Use tool fantasy"), AudioManager.USE_TOOL_FANTASY);

                            startBlending(texture.Value, new Color(255, 255, 255, 100), "TreeWithFood", 0.4f, 20);
                        }
                    }
                }
            }
            else if (Name == "TreeWithFood")
            {
                //Bytte ut treets tekstur
                bool isBlending = ((RenderComponent)DrawableComponents.ElementAt(0).Value).IsBlending;

                if (!isBlending)
                {
                    foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                    {
                        if (texture.Key == "Tree")
                        {
                            startBlending(texture.Value, new Color(255, 255, 255, 100), "Tree", 0.1f, 20);

                            Random r = new Random();
                            int    numberOfApples = r.Next(3, 6);
                            player1.setNumberOfApples(player1.getNumberOfApples() + numberOfApples);

                            SceneManager.getInstance.getFontManager().addFont(
                                new Font(EFontType.STATIC, 8, "FontFetchApples",
                                         ResourceManager.getInstance.Font1, "You picked up " + numberOfApples +
                                         (numberOfApples == 1 ? " apple" : " apples"),
                                         new Vector2(playerPos.X - 355, playerPos.Y + 240), Color.White, 2));

                            foreach (KeyValuePair <string, Texture2D> texture2 in ResourceManager.getInstance.getRuntimeTextures())
                            {
                                if (texture2.Key == "HudApple")
                                {
                                    SceneManager.getInstance.getHudManager().getInventoryHud().insertItem(new ItemHud(EItemType.CORN, texture2.Value, new Vector2(), 0.0f,
                                                                                                                      new Vector2(texture2.Value.Width / 2, texture2.Value.Height / 2), new Vector2(1, 1)), numberOfApples, ESlotType.OTHER);
                                }
                            }
                        }
                    }
                }
            }
            else if (Name == "Granary")
            {
                /*
                 * We loop through the players inventory and removes the food, and adds it to the granary
                 * */
                foreach (InventorySlotHud slotHud in SceneManager.getInstance.getHudManager().getInventoryHud().getItems())
                {
                    // SceneManager.getInstance.getHudManager().getInventoryHud().removeItem(new ItemHud(EItemType.SCREW, texture.Value, new Vector2(), 0.0f,
                    //           new Vector2(texture.Value.Width / 2, texture.Value.Height / 2), new Vector2(1, 1)), 8);

                    if (slotHud.getItemHud() != null)
                    {
                        //Console.WriteLine(slotHud.getItemHud().getItemType());

                        if (slotHud.getItemHud().getItemType() == EItemType.CORN && slotHud.getNumberOfItems() > 0)
                        {
                            Texture2D texture = slotHud.getItemHud().Properties.getProperty <Texture2D>("Texture2D");

                            //Update the corn in the granary
                            LevelHandler.getInstance.setNumberOfCorn(LevelHandler.getInstance.getNumberOfCorn() + slotHud.getNumberOfItems());

                            //Adds a font
                            SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, 13, "FontFoodGranary",
                                                                                       ResourceManager.getInstance.Font1, "You dropped " + slotHud.getNumberOfItems() + " corn into the food house",
                                                                                       new Vector2(playerPos.X - 350, playerPos.Y + 150), Color.Green, 3.0f));

                            //Remove items from the players inventory
                            SceneManager.getInstance.getHudManager().getInventoryHud().removeItem(
                                new ItemHud(slotHud.getItemHud().getItemType(), texture, new Vector2(), 0.0f,
                                            new Vector2(texture.Width / 2, texture.Height / 2), new Vector2(1, 1)), slotHud.getNumberOfItems());
                        }

                        if (slotHud.getItemHud().getItemType() == EItemType.APPLE && slotHud.getNumberOfItems() > 0)
                        {
                            Texture2D texture = slotHud.getItemHud().Properties.getProperty <Texture2D>("Texture2D");

                            //Update the apples in the granary
                            LevelHandler.getInstance.setNumberOfApples(LevelHandler.getInstance.getNumberOfApples() + slotHud.getNumberOfItems());

                            //Adds a font
                            SceneManager.getInstance.getFontManager().addFont(new Font(EFontType.STATIC, 13, "FontFoodGranary",
                                                                                       ResourceManager.getInstance.Font1, "You dropped " + slotHud.getNumberOfItems() + " apples into the food house",
                                                                                       new Vector2(playerPos.X - 350, playerPos.Y + 150), Color.Green, 3.0f));

                            //Remove items from the players inventory
                            SceneManager.getInstance.getHudManager().getInventoryHud().removeItem(
                                new ItemHud(slotHud.getItemHud().getItemType(), texture, new Vector2(), 0.0f,
                                            new Vector2(texture.Width / 2, texture.Height / 2), new Vector2(1, 1)), slotHud.getNumberOfItems());
                        }
                    }
                }
            }
        }
        public void onInteract()
        {
            Character player1   = SceneManager.getInstance.getPlayer1();
            Vector2   playerPos = SceneManager.getInstance.getPlayer1().Properties.getProperty <Vector2>("Position");

            if (Name == "Field")
            {
                Console.WriteLine("Field clicked");

                bool isBlending = ((RenderComponent)DrawableComponents.ElementAt(0).Value).IsBlending;

                if (!isBlending)
                {
                    foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                    {
                        if (texture.Key == "FieldFertilised")
                        {
                            Console.WriteLine("Start blending");
                            AudioManager.getInstance.playSound(new Sound("Use tool pickaxe"), AudioManager.USE_TOOL_PICKAXE);
                            startBlending(texture.Value, new Color(255, 255, 255, 120), "FieldFertilised", 0.2f, 10);
                        }
                    }
                }
            }
            else if (Name == "FieldWithFood")
            {
                foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                {
                    if (texture.Key == "Field")
                    {
                        Properties.updateProperty <Texture2D>("Texture2D", texture.Value);
                        Name = "Field";
                    }
                }
                foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
                {
                    if (texture.Key == "HudCorn")
                    {
                        SceneManager.getInstance.getHudManager().getInventoryHud().insertItem(new ItemHud(EItemType.CORN, texture.Value, new Vector2(), 0.0f,
                                                                                                          new Vector2(texture.Value.Width / 2, texture.Value.Height / 2), new Vector2(1, 1)), 1, ESlotType.OTHER);
                    }
                }

                SceneManager.getInstance.getFontManager().addFont(
                    new Font(EFontType.STATIC, 10, "FontFetchCorn",
                             ResourceManager.getInstance.Font1, "You picked up corn",
                             new Vector2(playerPos.X - 355, playerPos.Y + 240), Color.White, 2));

                AudioManager.getInstance.playSound(new Sound("Fetch apples and corn"), AudioManager.FETCH_APPLES_AND_CORN);
            }

            /*
             * else if (Name == "FieldFertilised")
             * {
             * Console.WriteLine("FieldFertilised clicked");
             * //SceneManager.getInstance.getMouseCursor().startRotation(90, 2);
             *
             * bool isBlending = ((RenderComponent)DrawableComponents.ElementAt(0).Value).IsBlending;
             *
             * if (!isBlending)
             * {
             *     foreach (KeyValuePair<string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
             *     {
             *         if (texture.Key == "FieldWithFood")
             *         {
             *             Console.WriteLine("Start blending");
             *             startBlending(texture.Value, new Color(255, 255, 255, 120), "FieldWithFood", 1.0f, 10);
             *         }
             *     }
             * }
             * }
             * */
        }