Exemple #1
0
        public void Collide(ICollidAble collider)
        {
            if (collider is ClickableObject)
            {
                ClickableObject obj = collider as ClickableObject;

                if (obj.Info.texturePath.Contains("puddle") || obj.Info.texturePath.Contains("oil"))
                {
                    obj.ChangeMovement(Player.Movement.Current);
                    hidingObject = obj;
                }
            }
        }
        public override void LoadLevel(LevelFormat level)
        {
            foreach (ClickAbleInfo info in level.clickObjectsInfo)
            {
                ClickableObject clickObj = new ClickableObject();

                bool found = false;
                foreach(Tuple<string,Texture2D> tup in textures)
                {
                    if(tup.Item1 == info.texturePath)
                    {
                        found = true;
                        clickObj.Image = tup.Item2;
                        clickObj.TexturePath = tup.Item1;
                    }
                }

                // Texture not found just drop it
                if (!found)
                    continue;

                if (info.useCustomBounds)
                {
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                }

                clickObj.StartPosition = info.position;
                clickObj.Position = info.position;
                clickObj.moveToPosition = info.moveToPosition;
                clickObj.TexturePath = info.texturePath;

                // Check if the object has an animation
                if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                {
                    AnimationInfo aInfo = JsonConvert.DeserializeObject<AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                    clickObj.Animation = new Animation(Game1.Instance.Content.Load<Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                }

                clickObj.ObjectiveID = info.objectiveID;

                if (info.useCustomBounds)
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                clickables.Add(clickObj);
                clickablesCount++;
            }

            base.LoadLevel(level);
        }
        public override void Update(GameTime time)
        {
            if (InputHelper.Instance.IsKeyPressed(Keys.A) && curObject > 0 && !placing)
            { curObject--; }
            else if (InputHelper.Instance.IsKeyPressed(Keys.D) && curObject < textures.Count - 1 && !placing)
            { curObject++; }

            if (InputHelper.Instance.IsLeftMouseReleased())
            {
                if (placing)
                {
                    moveToPositions.Add(InputHelper.Instance.MousePos());
                }
                else
                {
                    startPos = InputHelper.Instance.MousePos();
                    placing = true;
                }
            }
            else if (InputHelper.Instance.IsRightMousePressed())
            {
                if (placing)
                {
                    ClickableObject obj = new ClickableObject();
                    obj.StartPosition = obj.Position = startPos;
                    obj.TexturePath = textures[curObject].Item1;
                    obj.moveToPosition = moveToPositions;
                    obj.ObjectiveID = clickablesCount;
                    if (!ClickableObjectManager.Instance.NoBoxesLoaded && !ClickableObjectManager.Instance.GetBoundingbox(textures[curObject].Item1).IsEmpty)
                        obj.SetCustomBounds(ClickableObjectManager.Instance.GetBoundingbox(textures[curObject].Item1));

                    if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + obj.TexturePath + ".ani"))
                    {
                        AnimationInfo aInfo = JsonConvert.DeserializeObject<AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + obj.TexturePath + ".ani"));
                        obj.Animation = new Animation(Game1.Instance.Content.Load<Texture2D>(obj.TexturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                    }
                    else
                    {
                        obj.Image = textures[curObject].Item2;
                    }

                    clickables.Add(obj);
                    clickablesCount++;
                    moveToPositions = new List<Vector2>();
                    placing = false;
                }
                else
                {

                    bool reset = false;

                    for (int i = 0; i < clickables.Count; i++)
                    {
                        ClickableObject o = clickables[i];

                        if (o.Boundingbox.Contains(InputHelper.Instance.MousePos().toPoint()))
                        {
                            clickables.Remove(o);
                            clickablesCount--;
                            reset = true;
                        }
                    }

                    if (reset)
                        ResetIDs();
                }
            }

            if (placing)
                blockLayerChange = true;
            else
                blockLayerChange = false;

            base.Update(time);
        }
Exemple #4
0
        private void Plank_onClick(object sender)
        {
            delta = Vector2.One * 5;

            if (hidingObject != null)
            {
                hidingObject.ChangeMovement(Player.Movement.Dead);
                hidingObject = null;
            }
        }
Exemple #5
0
        public void Collide(ICollidAble collider)
        {
            if (collider is ClickableObject)
            {
                ClickableObject obj = collider as ClickableObject;

                if (obj.Info.texturePath.Contains("puddle") || obj.Info.texturePath.Contains("oil"))
                {
                    obj.ChangeMovement(Player.Movement.Current);
                    hidingObject = obj;
                }

            }
        }
        public override void LoadContent(ContentManager content)
        {
            loader.Load();
            // Is the level loading succesfull
            if (loader.LevelLoaded)
            {
                backgroundGrid = new Grid();
                backgroundGrid.LoadFromLevelInfo(loader.level);

                drawAbleItems.Add(backgroundGrid);
                GameObjects.Add(backgroundGrid);

                List<ClickAbleInfo> click = loader.level.clickObjectsInfo;

                foreach (ClickAbleInfo info in click)
                {

                    if (info.texturePath.Contains("car"))
                    {
                        Car clickObj = new Car();
                        // Check if the object has an custom bounds
                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        if (info.texturePath.Contains("blue"))
                        {
                            clickObj.Position = info.position - new Vector2(400, 0);
                            clickObj.StartPosition = clickObj.Position;
                        }
                        else
                        {
                            clickObj.StartPosition = info.position;
                            clickObj.Position = info.position;
                        }
                        clickObj.moveToPosition = info.moveToPosition;
                        clickObj.TexturePath = info.texturePath;

                        // Check if the object has an animation
                        if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                        {
                            AnimationInfo aInfo = JsonConvert.DeserializeObject<AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                            clickObj.Animation = new Animation(content.Load<Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                        }
                        else
                        {
                            clickObj.Image = content.Load<Texture2D>(info.texturePath);
                        }
                        clickObj.ObjectiveID = info.objectiveID;

                        if (info.useCustomBounds)
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));

                        clickObj.onClick += OnClickHandler;

                        objectives.Add(new Objective("Objective " + info.objectiveID));

                        drawAbleItems.Add(clickObj);
                        GameObjects.Add(clickObj);
                    }
                    else if(info.texturePath.Contains("plank"))
                    {
                        Plank clickObj = new Plank();
                        // Check if the object has an custom bounds
                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.StartPosition = info.position;
                        clickObj.Position = info.position;
                        clickObj.moveToPosition = info.moveToPosition;
                        clickObj.TexturePath = info.texturePath;

                        // Check if the object has an animation
                        if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                        {
                            AnimationInfo aInfo = JsonConvert.DeserializeObject<AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                            clickObj.Animation = new Animation(content.Load<Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                        }
                        else
                        {
                            clickObj.Image = content.Load<Texture2D>(info.texturePath);
                        }
                        clickObj.ObjectiveID = info.objectiveID;

                        if (info.useCustomBounds)
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));

                        clickObj.onClick += OnClickHandler;

                        objectives.Add(new Objective("Objective " + info.objectiveID));

                        drawAbleItems.Add(clickObj);
                        GameObjects.Add(clickObj);
                    }
                    else
                    {
                        ClickableObject clickObj = new ClickableObject();
                        // Check if the object has an custom bounds
                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.StartPosition = info.position;
                        clickObj.Position = info.position;
                        clickObj.moveToPosition = info.moveToPosition;
                        clickObj.TexturePath = info.texturePath;

                        // Check if the object has an animation
                        if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                        {
                            AnimationInfo aInfo = JsonConvert.DeserializeObject<AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                            clickObj.Animation = new Animation(content.Load<Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                        }
                        else
                        {
                            clickObj.Image = content.Load<Texture2D>(info.texturePath);
                        }
                        clickObj.ObjectiveID = info.objectiveID;

                        if (info.useCustomBounds)
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));

                        clickObj.onClick += OnClickHandler;

                        objectives.Add(new Objective("Objective " + info.objectiveID));

                        drawAbleItems.Add(clickObj);
                        GameObjects.Add(clickObj);
                    }
                }

                {// create scope for info
                    PlayerInfo info = loader.level.playerInfo;
                    player = new Player();
                    player.StartPosition = loader.level.playerInfo.position;
                    player.StartMovement = loader.level.playerInfo.startMovement;
                    player.LoadContent(content);
                    player.ChangeMovement(loader.level.playerInfo.startMovement);

                    if (loader.level.playerInfo.useCustomBoundingbox)
                    {
                        player.SetCustomBoundingbox(new Rectangle(info.x, info.y, info.width, info.height));
                    }
                    drawAbleItems.Add(player);
                }

                GameObjects.Add(player);

                foreach (MovementTileInfo info in loader.level.moveTiles)
                {
                    if (info.WinningTile)
                        GameObjects.Add(new WinTile(new Rectangle(info.X, info.Y, info.Width, info.Height)));
                    else
                        GameObjects.Add(new MovementTile(new Rectangle(info.X, info.Y, info.Width, info.Height), info.movement, testing));
                }

                foreach (DecorationInfo info in loader.level.decoration)
                {
                    Decoration decoration = new Decoration();
                    decoration.Position = info.position;
                    decoration.Image = content.Load<Texture2D>(info.ImagePath);
                    drawAbleItems.Add(decoration);
                    GameObjects.Add(decoration);
                }

                drawAbleItems = drawAbleItems.OrderBy(o => o.DrawIndex()).ToList();
            }
            else
            {
                // TODO: show error
                player.Won = true;
            }

            pause = new Button();
            pause.LoadImage(@"buttons\pause");
            pause.Position = new Vector2(Game1.Instance.ScreenRect.Width - pause.Hitbox.Width - 10, 10);
            pause.OnClick += Pause_OnClick;

            pauseBack = new Button();
            pauseBack.LoadImage(@"buttons\menu");
            pauseBack.Position = new Vector2(Game1.Instance.ScreenRect.Width / 2 - pauseBack.Hitbox.Width / 2, Game1.Instance.ScreenRect.Height / 2 - pauseBack.Hitbox.Height / 2);
            pauseBack.OnClick += Pause_OnClick;

            backButton = new ClickableObject();

            backButton.TexturePath = @"buttons\reset";
            backButton.Image = content.Load<Texture2D>(backButton.TexturePath);

            backButton.onClick += OnClickHandler;
            backButton.ObjectiveID = -1;
            backButton.Position = new Vector2(Game1.Instance.ScreenRect.Width - backButton.Image.Width - 20, Game1.Instance.ScreenRect.Height - backButton.Image.Height - 20);

            base.LoadContent(content);
        }