void addHouses(int numHouses) { BasicModel tentativeHouse; for (int i = 0; i < numHouses; i++) { switch (random.Next(5)) { case 1: tentativeHouse = new BasicModel(blueHouseModel, new Vector3(random.Next(100 * level * 2) - 100 * level, -2.5f, random.Next(100 * level * 2) - 100 * level)); break; case 2: tentativeHouse = new BasicModel(yellowHouseModel, new Vector3(random.Next(100 * level * 2) - 100 * level, -2.5f, random.Next(100 * level * 2) - 100 * level)); break; case 3: tentativeHouse = new BasicModel(greenHouseModel, new Vector3(random.Next(100 * level * 2) - 100 * level, -2.5f, random.Next(100 * level * 2) - 100 * level)); break; case 4: tentativeHouse = new BasicModel(purpleHouseModel, new Vector3(random.Next(100 * level * 2) - 100 * level, -2.5f, random.Next(100 * level * 2) - 100 * level)); break; default: tentativeHouse = new BasicModel(redHouseModel, new Vector3(random.Next(100 * level * 2) - 100 * level, -2.5f, random.Next(100 * level * 2) - 100 * level)); break; } bool isValid = true; tentativeHouse.scale(8); foreach (BasicModel target in getCollidables()) { if (Vector3.Distance(tentativeHouse.position, target.position) < 30 || Vector3.Distance(tentativeHouse.position, rabbit.position) < 20) { isValid = false; i--; break; } } if (isValid) { houses.Add(tentativeHouse); } } }
// Returns true if model intersects with target, false otherwise public bool CollidesWith(BasicModel target) { // Preliminary check for to see if the objects are even close if (Vector3.Distance(position, target.position) > 10) { return(false); } // Loop through each ModelMesh in both objects and compare // all bounding spheres for collisions foreach (ModelMesh myModelMeshes in model.Meshes) { foreach (ModelMesh otherModelMeshes in target.model.Meshes) { if (myModelMeshes.BoundingSphere.Transform( GetWorld()).Intersects( otherModelMeshes.BoundingSphere.Transform(target.GetWorld()))) { return(true); } } } return(false); }
void addMushrooms(int numMushrooms) { BasicModel mushroom; if (level < 2) { baseNum = 100; } else { baseNum = 150; } for (int i = 0; i < numMushrooms; i++) { switch (random.Next(3)) { case 1: mushroom = new BasicModel(redMushroomModel, new Vector3(random.Next(baseNum * 2) - baseNum, -2.6f, random.Next(baseNum * 2) - baseNum)); break; case 2: mushroom = new BasicModel(blueMushroomModel, new Vector3(random.Next(baseNum * 2) - baseNum, -3f, random.Next(baseNum * 2) - baseNum)); break; default: mushroom = new BasicModel(greenMushroomModel, new Vector3(random.Next(baseNum * 2) - baseNum, -3.5f, random.Next(baseNum * 2) - baseNum)); break; } bool isValid = true; foreach (BasicModel target in getCollidables()) { if (mushroom.CollidesWith(target)) { isValid = false; i--; break; } } if (isValid) { mushrooms.Add(mushroom); } } // add mushrooms outside boundary for (int i = 0; i < (int)(numMushrooms * 3 / 4); i++) { switch (random.Next(3)) { case 1: mushrooms.Add(new BasicModel(redMushroomModel, new Vector3(random.Next(baseNum * 4) - baseNum * 5, -2.6f, random.Next(baseNum * 4) - baseNum * 5))); mushrooms.Add(new BasicModel(redMushroomModel, new Vector3(random.Next(baseNum * 4) + baseNum, -2.6f, random.Next(baseNum * 4) + baseNum))); mushrooms.Add(new BasicModel(redMushroomModel, new Vector3(random.Next(baseNum * 4) - baseNum * 5, -2.6f, random.Next(baseNum * 4) + baseNum))); mushrooms.Add(new BasicModel(redMushroomModel, new Vector3(random.Next(baseNum * 4) + baseNum, -2.6f, random.Next(baseNum * 4) - baseNum * 5))); break; case 2: mushrooms.Add(new BasicModel(blueMushroomModel, new Vector3(random.Next(baseNum * 4) - baseNum * 5, -3f, random.Next(baseNum * 4) - baseNum * 5))); mushrooms.Add(new BasicModel(blueMushroomModel, new Vector3(random.Next(baseNum * 4) + baseNum, -3f, random.Next(baseNum * 4) + baseNum))); mushrooms.Add(new BasicModel(blueMushroomModel, new Vector3(random.Next(baseNum * 4) - baseNum * 5, -3f, random.Next(baseNum * 4) + baseNum))); mushrooms.Add(new BasicModel(blueMushroomModel, new Vector3(random.Next(baseNum * 4) + baseNum, -3f, random.Next(baseNum * 4) - baseNum * 5))); break; default: mushrooms.Add(new BasicModel(greenMushroomModel, new Vector3(random.Next(baseNum * 4) - baseNum * 5, -3.5f, random.Next(baseNum * 4) - baseNum * 5))); mushrooms.Add(new BasicModel(greenMushroomModel, new Vector3(random.Next(baseNum * 4) + baseNum, -3.5f, random.Next(baseNum * 4) + baseNum))); mushrooms.Add(new BasicModel(greenMushroomModel, new Vector3(random.Next(baseNum * 4) - baseNum * 5, -3.5f, random.Next(baseNum * 4) + baseNum))); mushrooms.Add(new BasicModel(greenMushroomModel, new Vector3(random.Next(baseNum * 4) + baseNum, -3.5f, random.Next(baseNum * 4) - baseNum * 5))); break; } } foreach (BasicModel mushroomObject in mushrooms) { mushroomObject.scale(.5f, .5f, .5f); } }
void addTrees(int numTrees) { int treeChoice = 0; // choose green tree or yellow tree // Randomly create trees for the border of the playing area if (level < 2) { baseNum = 100; } else { baseNum = 150; } for (int i = -baseNum; i <= baseNum; i = i + 40) { treeChoice = random.Next(3); if (treeChoice == 0) { trees.Add(new BasicModel(greenTreeModel, new Vector3(i, -3, -baseNum))); } else if (treeChoice == 1) { trees.Add(new BasicModel(yellowTreeModel, new Vector3(i, -3, -baseNum))); } else if (treeChoice == 2) { trees.Add(new BasicModel(redTreeModel, new Vector3(i, -3, -baseNum))); } } for (int i = -baseNum + 40; i < baseNum; i = i + 40) { treeChoice = random.Next(3); if (treeChoice == 0) { trees.Add(new BasicModel(greenTreeModel, new Vector3(-baseNum, -3, i))); } else if (treeChoice == 1) { trees.Add(new BasicModel(yellowTreeModel, new Vector3(-baseNum, -3, i))); } else if (treeChoice == 2) { trees.Add(new BasicModel(redTreeModel, new Vector3(-baseNum, -3, i))); } } for (int i = -baseNum; i <= baseNum; i = i + 40) { treeChoice = random.Next(3); if (treeChoice == 0) { trees.Add(new BasicModel(greenTreeModel, new Vector3(i, -3, baseNum))); } else if (treeChoice == 1) { trees.Add(new BasicModel(yellowTreeModel, new Vector3(i, -3, baseNum))); } else if (treeChoice == 2) { trees.Add(new BasicModel(redTreeModel, new Vector3(i, -3, baseNum))); } } for (int i = -baseNum + 40; i < baseNum; i = i + 40) { treeChoice = random.Next(3); if (treeChoice == 1) { trees.Add(new BasicModel(greenTreeModel, new Vector3(baseNum, -3, i))); } else if (treeChoice == 2) { trees.Add(new BasicModel(yellowTreeModel, new Vector3(baseNum, -3, i))); } else if (treeChoice == 0) { trees.Add(new BasicModel(redTreeModel, new Vector3(baseNum, -3, i))); } } //add some trees in the fight area BasicModel tentativeTree; for (int i = 0; i < numTrees; i++) { switch (random.Next(3)) { case 1: tentativeTree = new BasicModel(greenTreeModel, new Vector3(random.Next(baseNum * 2 - 30) - baseNum, -3, random.Next(baseNum * 2 - 30) - baseNum)); break; case 2: tentativeTree = new BasicModel(yellowTreeModel, new Vector3(random.Next(baseNum * 2 - 30) - baseNum, -3, random.Next(baseNum * 2 - 30) - baseNum)); break; default: tentativeTree = new BasicModel(redTreeModel, new Vector3(random.Next(baseNum * 2 - 30) - baseNum, -3, random.Next(baseNum * 2 - 30) - baseNum)); break; } bool isValid = true; foreach (BasicModel target in getCollidables()) { if (Vector3.Distance(tentativeTree.position, target.position) < 30 || Vector3.Distance(tentativeTree.position, rabbit.position) < 20) { isValid = false; i--; break; } } if (isValid) { trees.Add(tentativeTree); } } // add trees outside boundary for (int i = 0; i < numTrees; i++) { Model modelChoice; switch (random.Next(3)) { case 1: modelChoice = greenTreeModel; break; case 2: modelChoice = yellowTreeModel; break; default: modelChoice = redTreeModel; break; } List <BasicModel> tentativeTrees = new List <BasicModel>(); tentativeTrees.Add(new BasicModel(modelChoice, new Vector3(random.Next(baseNum) - baseNum * 2 - 30, -3, random.Next(baseNum * 3) - baseNum))); tentativeTrees.Add(new BasicModel(modelChoice, new Vector3(random.Next(baseNum * 3) - baseNum, -3, random.Next(baseNum) + baseNum + 30))); tentativeTrees.Add(new BasicModel(modelChoice, new Vector3(random.Next(baseNum) + baseNum + 30, -3, random.Next(baseNum * 3) - baseNum * 2))); tentativeTrees.Add(new BasicModel(modelChoice, new Vector3(random.Next(baseNum * 3) - baseNum * 2, -3, random.Next(baseNum) - baseNum * 2 - 30))); bool isValid = true; foreach (BasicModel tree in tentativeTrees) { foreach (BasicModel target in outOfBoundTrees) { if (Vector3.Distance(tree.position, target.position) < 15) { isValid = false; i--; break; } } } if (isValid) { foreach (BasicModel tree in tentativeTrees) { outOfBoundTrees.Add(tree); } } } foreach (BasicModel tree in trees) { tree.scale(10, 13, 10); } foreach (BasicModel tree in outOfBoundTrees) { tree.scale(20, 25, 20); } }
protected override void LoadContent() { //Stage stage = new Stage1( Game.Content.Load<Model>(@"models\stage")); //Players p1 = new Player1( Game.Content.Load<Model>(@"models\pikachu_final")); ((Player1)p1).setPosition(-25); models.Add(p1); p2 = new Player2( Game.Content.Load<Model>(@"models\pikachu_final")); ((Player1)p2).setPosition(25); models.Add(p2); shield1 = new BasicModel( Game.Content.Load<Model>(@"models\pokeballmodel")); shield2 = new BasicModel( Game.Content.Load<Model>(@"models\pokeballmodel")); //Lives stock = Game.Content.Load<Texture2D>(@"textures\stock"); mediator = new InteractionMediator((Player1)p1, (Player1)p2); //Assign Mediator ((Player1)p1).mediator = mediator; ((Player1)p2).mediator = mediator; //Assign all the models this Model Manager foreach (BasicModel m in models) m.setModelManager(this); player1 = ((Player1)p1); player2 = ((Player1)p2); spriteBatch = new SpriteBatch(GraphicsDevice); percentFont = Game.Content.Load<SpriteFont>(@"fonts\menuFont"); base.LoadContent(); }