public override void LoadContent(ContentManager content) { player = new Player(); player.LoadContent(content); boundingboxEditor = new PlayerBoundingboxEditor(this); base.LoadContent(content); }
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); }