//Generates a new portion if none exists inte the given bounds. public void CheckNewPortion(BoundingBox bounds) { if (!IsGenerated(bounds)) { Portion newPortion = new Portion(bounds); newPortion.AddPortion(generatedPortions, engine.Entities); } }
/* Generates initial portions around the player. */ public void initPortions(Player player) { BoundingBox portionBounds = new BoundingBox(new Vector3(0, 0, 0), new Vector3(Portion.PORTION_WIDTH, Portion.PORTION_HEIGHT, 0)); Portion portion = new Portion(portionBounds); portion.AddPortion(generatedPortions, engine.Entities); entityObserver.CheckPortions(player); }
private void LoadGame(EventArgs e) { engine.ClearEntities(); engine.ClearViewPositions(); currentState = GameState.Game; backgroundSound = new SoundEntity(2.0F, 10.0F); //TODO: Add Menus //MenuController menuController = new MenuController (new StartMenu(), new OptionMenu(), new PlayGameMenu()); //Defines all keybindings InitializeKeyBinds(); BoundingBox portionBounds = new BoundingBox(new Vector3(0, 0, 0), new Vector3(Portion.PORTION_WIDTH, Portion.PORTION_HEIGHT, 0)); Portion portion = new Portion(portionBounds); portion.AddPortion(generatedPortions, engine.Entities); InitializePlayers(); InitializeViewports(); }
//Identifies which portion the player is currently in and generates new portions //next to the current one as necessary. public void CheckPortions(Player player) { BoundingBox bounds; Portion curPortion = null; for (int i = 0; i < generatedPortions.Count; i++) { if (player.HitBox.Intersects(generatedPortions[i].Bounds)) { curPortion = generatedPortions[i]; break; } } if (curPortion == null) { return; } bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X - Portion.PORTION_WIDTH - Portion.TILE_WIDTH, curPortion.Bounds.Min.Y - Portion.PORTION_HEIGHT - Portion.TILE_HEIGHT, 0), new Vector3(curPortion.Bounds.Max.X - Portion.PORTION_WIDTH - Portion.TILE_WIDTH, curPortion.Bounds.Max.Y - Portion.PORTION_HEIGHT - Portion.TILE_HEIGHT, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X, curPortion.Bounds.Min.Y - Portion.PORTION_HEIGHT - Portion.TILE_HEIGHT, 0), new Vector3(curPortion.Bounds.Max.X, curPortion.Bounds.Max.Y - Portion.PORTION_HEIGHT - Portion.TILE_HEIGHT, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X + Portion.PORTION_WIDTH + Portion.TILE_WIDTH, curPortion.Bounds.Min.Y - Portion.PORTION_HEIGHT - Portion.TILE_HEIGHT, 0), new Vector3(curPortion.Bounds.Max.X + Portion.PORTION_WIDTH + Portion.TILE_WIDTH, curPortion.Bounds.Max.Y - Portion.PORTION_HEIGHT - Portion.TILE_HEIGHT, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X + Portion.PORTION_WIDTH + Portion.TILE_WIDTH, curPortion.Bounds.Min.Y, 0), new Vector3(curPortion.Bounds.Max.X + Portion.PORTION_WIDTH + Portion.TILE_WIDTH, curPortion.Bounds.Max.Y, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X + Portion.PORTION_WIDTH + Portion.TILE_WIDTH, curPortion.Bounds.Min.Y + Portion.PORTION_HEIGHT + Portion.TILE_HEIGHT, 0), new Vector3(curPortion.Bounds.Max.X + Portion.PORTION_WIDTH + Portion.TILE_WIDTH, curPortion.Bounds.Max.Y + Portion.PORTION_HEIGHT + Portion.TILE_HEIGHT, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X, curPortion.Bounds.Min.Y + Portion.PORTION_HEIGHT + Portion.TILE_HEIGHT, 0), new Vector3(curPortion.Bounds.Max.X, curPortion.Bounds.Max.Y + Portion.PORTION_HEIGHT + Portion.TILE_HEIGHT, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X - Portion.PORTION_WIDTH - Portion.TILE_WIDTH, curPortion.Bounds.Min.Y + Portion.PORTION_HEIGHT + Portion.TILE_HEIGHT, 0), new Vector3(curPortion.Bounds.Max.X - Portion.PORTION_WIDTH - Portion.TILE_WIDTH, curPortion.Bounds.Max.Y + Portion.PORTION_HEIGHT + Portion.TILE_HEIGHT, 0)); CheckNewPortion(bounds); bounds = new BoundingBox(new Vector3(curPortion.Bounds.Min.X - Portion.PORTION_WIDTH - Portion.TILE_WIDTH, curPortion.Bounds.Min.Y, 0), new Vector3(curPortion.Bounds.Max.X - Portion.PORTION_WIDTH - Portion.TILE_WIDTH, curPortion.Bounds.Max.Y, 0)); CheckNewPortion(bounds); }