Exemplo n.º 1
0
        public override void LoadLevel(LevelFormat level)
        {
            foreach(DecorationInfo d in level.decoration)
            {
                Decoration decoration = new Decoration(d.ImagePath);
                decoration.Position = d.position;

                for (int i = 0; i < decorationImages.Count; i++)
                {
                    if (decorationImages[i].Item1 == d.ImagePath)
                    {
                        decoration.Image = decorationImages[i].Item2;
                        break;
                    }
                }

                tiles.Add(decoration);
            }

            base.LoadLevel(level);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public override void Update(GameTime time)
        {
            if (InputHelper.Instance.IsKeyPressed(Keys.A) && currentTile > 0)
                currentTile--;
            else if (InputHelper.Instance.IsKeyPressed(Keys.D) && currentTile < decorationImages.Count - 1)
                currentTile++;
            else if (InputHelper.Instance.IsKeyPressed(Keys.Q))
                snapTile = !snapTile;

            Vector2 mpos = InputHelper.Instance.MousePos();
            if (snapTile)
            {
                // the while loops will place the tile at the right position
                while ((int)mpos.X % 80 != 0)
                {
                    mpos.X--;
                }

                while ((int)mpos.Y % 80 != 0)
                {
                    mpos.Y--;
                }

                snapcol = (int)mpos.X / 80;
                snaprow = (int)mpos.Y / 80;
            }

            if(InputHelper.Instance.IsLeftMousePressed())
            {
                Decoration deco = new Decoration(decorationImages[currentTile].Item1);
                deco.Image = decorationImages[currentTile].Item2;

                if(snapTile)
                {
                    deco.Position = new Vector2(snapcol * 80, snaprow * 80);
                }
                else
                {
                    deco.Position = mpos;
                }
                tiles.Add(deco);
            }
            else if(InputHelper.Instance.IsRightMousePressed())
            {
                for(int i = 0; i < tiles.Count; i++)
                {
                    if(tiles[i].Bounds.Contains(InputHelper.Instance.MousePos().toPoint()))
                    {
                        tiles.RemoveAt(i);
                    }
                }
            }

            base.Update(time);
        }