public override void LoadContent(ContentManager content)
        {
            next = new Button();
            next.LoadImage("buttons/next");
            next.Position = new Vector2(Game1.Instance.ScreenRect.Width - 200, Game1.Instance.ScreenRect.Height - 75);
            next.OnClick += Buttons_OnClick;

            prev = new Button();
            prev.LoadImage("buttons/prev");
            prev.Position = new Vector2(100, Game1.Instance.ScreenRect.Height - 75);
            prev.OnClick += Buttons_OnClick;

            LevelManager.Instance.LoadData();
            LevelManager.Instance.UnlockLevel(1);

            // You start on the first page
            showPrev = false;
            // if there are more then 8 there will be an extra page
            showNext = LevelManager.Instance.LevelCount > 8;

            // load preview buttons
            previews = new List<LevelPreview>();

            if (LevelManager.Instance.LevelCount % 8 == 0)
            {
                totalPages = LevelManager.Instance.LevelCount / 8;
                totalPages = totalPages > 0 ? totalPages : 1;
            }
            else
            {
                totalPages = (int)Math.Floor((double)LevelManager.Instance.LevelCount / 8);
                totalPages++;
            }

            int id = 0;
            for (int page = 0; page < totalPages; page++)
            {
                for (int row = 0; row < 2; row++)
                {
                    for (int col = 0; col < 4; col++)
                    {
                        if (id >= LevelManager.Instance.LevelCount)
                            continue;

                        LevelPreview preview = new LevelPreview(LevelManager.Instance.GetLevel(id));
                        preview.LoadContent(content);
                        preview.button.OnClick += button_OnClick;
                        preview.Position = new Vector2(page * Game1.Instance.ScreenRect.Width + (75 + (col * (preview.Hitbox.Width + 25))), 10 + (row * (preview.Hitbox.Height + 50)));
                        preview.button.Tag = preview.LevelID;
                        previews.Add(preview);
                        id++;
                    }
                }
            }

            base.LoadContent(content);
        }
Example #2
0
        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);
        }
Example #3
0
 public MenuScreen()
 {
     start = new Button();
     help = new Button();
 }