Ejemplo n.º 1
0
 /// <summary>
 /// End and clear components of this scene.
 /// </summary>
 public virtual void Restart()
 {
     End();
     GameObjects.Clear();
     Components.Clear();
     DrawableComponents.Clear();
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
        public Lab(Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale,
                   List <Polygon> polygons, List <AABB> axisAlignedBoxes, float depthPosition, string name)
        {
            Components.Add("CollisionComponent", new CollisionComponent(this, polygons, axisAlignedBoxes));
            Components.Add("DepthComponent", new DepthComponent(this, depthPosition));
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, -1.0f));

            this.name = name;
        }
Ejemplo n.º 4
0
        public BackgroundObject(Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale,
                                List <Polygon> polygons, List <AABB> axisAlignedBoxes, string name)
        {
            Components.Add("CollisionComponent", new CollisionComponent(this, polygons, axisAlignedBoxes));
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, 1.0f));

            Name = name;
            interactionDistance = 100.0f;
            mouseIsHovering     = false;
        }
Ejemplo n.º 5
0
        public InventorySlotHud(ESlotType slotType, Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale)
        {
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, 1.0f));


            //We just initialize these at default values
            // DrawableComponents.Add("RenderComponent2", new RenderComponent(this, null, new Vector2(), 0.0f, new Vector2(), new Vector2(), 1.0f));
            containsItem  = false;
            this.slotType = slotType;
            item          = null;
            numberOfItems = 0;
        }
Ejemplo n.º 6
0
        public SnakeGame()
            : base(new ConsoleRenderer(60, 30), new CmdInputManager())
        {
            var screenManager = new ScreenManager(InputManager);

            var screen = new GameScreen(screenManager, GameRenderer.Width, GameRenderer.Height);

            screenManager.AddScreen(screen);

            screen.Show();

            DrawableComponents.Add(new FpsCounter());
            DrawableComponents.Add(screenManager);
        }
Ejemplo n.º 7
0
        public MiddleObject(Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale,
                            List <Polygon> polygons, List <AABB> axisAlignedBoxes, float depthPosition, string name)
        {
            Components.Add("CollisionComponent", new CollisionComponent(this, polygons, axisAlignedBoxes));
            Components.Add("DepthComponent", new DepthComponent(this, depthPosition));
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, -1.0f));

            Name = name;
            interactionDistance = 150.0f;
            mouseIsHovering     = false;

            Random r = new Random();

            dRand = r.Next(0, 5);
        }
Ejemplo n.º 8
0
        public MiddleObject(Texture2D[] textures, Vector2 position, float rotation, Vector2 origin, Vector2 scale,
                            List <Polygon> polygons, List <AABB> axisAlignedBoxes, int numberOfAnimations, int[] animationSpeeds, int[] numberOfFrames,
                            int[] numberOfRows, float depthPosition, string name)
        {
            Components.Add("CollisionComponent", new CollisionComponent(this, polygons, axisAlignedBoxes));
            Components.Add("DepthComponent", new DepthComponent(this, depthPosition));
            DrawableComponents.Add("AnimationComponent", new AnimationComponent(this, textures, position, rotation, origin, scale,
                                                                                numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows));

            Name = name;
            interactionDistance = 200.0f;
            mouseIsHovering     = false;

            Random r = new Random();

            dRand = r.Next(0, 5);
        }
Ejemplo n.º 9
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);
                }
            }
        }
Ejemplo n.º 10
0
        public Character(Texture2D[] textures, Vector2 position, Vector2 acceleration, float rotation, Vector2 origin,
                         Vector2 scale, List <Polygon> polygons, List <AABB> axisAlignedBoxes, int numberOfAnimations, int[] animationSpeeds, int[] numberOfFrames,
                         int[] numberOfRows, float depthPosition, string name)
        {
            Components.Add("PhysicsComponent", new PhysicsComponent(this, position, acceleration));
            Components.Add("CollisionComponent", new CollisionComponent(this, polygons, axisAlignedBoxes));
            Components.Add("DepthComponent", new DepthComponent(this, depthPosition));
            DrawableComponents.Add("AnimationComponent", new AnimationComponent(this, textures, position, rotation, origin, scale,
                                                                                numberOfAnimations, animationSpeeds, numberOfFrames, numberOfRows));

            ((PhysicsComponent)Components.ElementAt(0).Value).IsMoveable = true;

            Name               = name;
            inventory          = new Inventory(new ResourceItem());
            fantasyTool        = false;
            shovel             = true;
            openInventory      = true;
            openQuests         = false;
            openCurrentQuests  = false;
            openFinishedQuests = false;

            //Adds the players starting equipment to the inventory
            foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
            {
                if (texture.Key == "HudPickaxe")
                {
                    SceneManager.getInstance.getHudManager().getInventoryHud().insertItem(new ItemHud(EItemType.PICKAXE, texture.Value,
                                                                                                      new Vector2(), 0.0f, new Vector2(texture.Value.Width / 2, texture.Value.Height / 2), new Vector2(1, 1)), 1, ESlotType.MAIN);
                }
            }
            foreach (KeyValuePair <string, Texture2D> texture in ResourceManager.getInstance.getRuntimeTextures())
            {
                if (texture.Key == "HudShovel")
                {
                    SceneManager.getInstance.getHudManager().getInventoryHud().insertItem(new ItemHud(EItemType.SHOVEL, texture.Value,
                                                                                                      new Vector2(), 0.0f, new Vector2(texture.Value.Width / 2, texture.Value.Height / 2), new Vector2(1, 1)), 1, ESlotType.MAIN);
                }
            }
        }
Ejemplo n.º 11
0
 public void startRotation(float degrees, int time)
 {
     ((RenderComponent)DrawableComponents.ElementAt(0).Value).Rotate = true;
 }
Ejemplo n.º 12
0
        public Shadow(Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale, string name)
        {
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, 1.0f));

            Name = name;
        }
Ejemplo n.º 13
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());
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Add component to scene collection.
 /// </summary>
 /// <param name="gameObject">Adds drawable component to collection.</param>
 public void AddComponent(DrawableGameComponent component)
 {
     DrawableComponents.Add(component);
 }
Ejemplo n.º 15
0
        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);
             *         }
             *     }
             * }
             * }
             * */
        }
Ejemplo n.º 16
0
        public ItemHud(EItemType itemType, Texture2D texture2D, Vector2 position, float rotation, Vector2 origin, Vector2 scale)
        {
            DrawableComponents.Add("RenderComponent", new RenderComponent(this, texture2D, position, rotation, origin, scale, 1.0f));

            this.itemType = itemType;
        }