private void initializeClouds() { List <Vector3> cloudPositions = new List <Vector3>(); // Create 20 "clusters" of clouds for (int i = 0; i < 30; i++) { Vector3 cloudLoc = new Vector3( r.Next(-Constants.FIELD_MAX_X_Z, Constants.FIELD_MAX_X_Z), r.Next(Constants.TERRAIN_HEIGHT * 9 / 10, Constants.TERRAIN_HEIGHT * 3 / 2), r.Next(-Constants.FIELD_MAX_X_Z, Constants.FIELD_MAX_X_Z)); // Add 10 cloud billboards around each cluster point for (int j = 0; j < 10; j++) { cloudPositions.Add(cloudLoc + new Vector3( r.Next(-Constants.FIELD_MAX_X_Z / 4, Constants.FIELD_MAX_X_Z / 4), r.Next(-Constants.TERRAIN_HEIGHT / 15, Constants.TERRAIN_HEIGHT / 5), r.Next(-Constants.FIELD_MAX_X_Z / 4, Constants.FIELD_MAX_X_Z / 4))); } } clouds = new BillboardSystem(this, Content.Load <Texture2D>("cloud2"), new Vector2(200), cloudPositions.ToArray()); clouds.Mode = BillboardSystem.BillboardMode.Spherical; clouds.EnsureOcclusion = false; }
// Called when the game should load its content protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); models.Add(new CModel(Content.Load <Model>("Content/grass_ground"), Vector3.Zero, Vector3.Zero, Vector3.One, GraphicsDevice, false)); Effect effect = Content.Load <Effect>("Content/LightingEffect"); LightingMaterial mat = new LightingMaterial(); mat.SpecularColor = Color.Black.ToVector3(); //models[0].SetModelEffect(effect, true); //models[0].Material = mat; camera = new FreeCamera(new Vector3(0, 700, 3000), MathHelper.ToRadians(0), MathHelper.ToRadians(5), GraphicsDevice); // Generate random tree positions Random r = new Random(); Vector3[] positions = new Vector3[200]; for (int i = 0; i < positions.Length; i++) { positions[i] = new Vector3( (float)r.NextDouble() * 20000 - 10000, 400, (float)r.NextDouble() * 20000 - 10000 ); } trees = new BillboardCross(GraphicsDevice, Content, Content.Load <Texture2D>("Content/tree_billboard"), new Vector2(800), positions); //trees.Mode = BillboardSystem.BillboardMode.Cylindrical; Vector3[] cloudPositions = new Vector3[350]; for (int i = 0; i < cloudPositions.Length; i++) { cloudPositions[i] = new Vector3( r.Next(-6000, 6000), r.Next(2000, 3000), r.Next(-6000, 6000)); } clouds = new BillboardSystem(GraphicsDevice, Content, Content.Load <Texture2D>("Content/cloud2"), new Vector2(1000), cloudPositions); clouds.EnsureOcclusion = false; lastMouseState = Mouse.GetState(); }
private BillboardSystem initializeBillBoard(int numOfBillBoards, String tex, Boolean EnsureOcclusion, Vector2 size, bool flag) { BillboardSystem billboard = new BillboardSystem(this, Content.Load <Texture2D>(tex), size, initializePositions(numOfBillBoards, size).ToArray()); billboard.Mode = BillboardSystem.BillboardMode.Cylindrical; billboard.EnsureOcclusion = EnsureOcclusion; return(billboard); }
private void initializeGame1() { switch (StartScreen.Difficulty) { case Constants.Difficulties.Novice: difficultyConstants = new NoviceConstants(); break; case Constants.Difficulties.Advanced: difficultyConstants = new AdvancedConstants(); break; case Constants.Difficulties.Xtreme: difficultyConstants = new XtremeConstants(); break; } //camera = new FreeCamera(this, new Vector3(0, 0, 0), 0, 0, 0 , 0); //camera = new FreeCamera(new Vector3(400, 600, 400), MathHelper.ToRadians(45), MathHelper.ToRadians(-30), GraphicsDevice); camera = new ChaseCamera(this, Constants.CAMERA_POSITION_THIRD_PERSON, Constants.CAMERA_TARGET_THIRD_PERSON, Vector3.Zero); //for (int i = 0; i < Constants.NUM_OF_TERRAINS; i++) //{ terrain = new Terrain(this, camera, Content.Load <Texture2D>("terrain" + currentLevel), Constants.TERRAIN_CELL_SIZE, Constants.TERRAIN_HEIGHT, Content.Load <Texture2D>("grass"), Constants.TERRAIN_TEXTURE_TILING, new Vector3(1, -1, 0) /*,new Vector2(i%2*-1,i/2*-1)*/); terrain.WeightMap = Content.Load <Texture2D>("weightMap" + currentLevel); terrain.RTexture = Content.Load <Texture2D>("sand"); terrain.GTexture = Content.Load <Texture2D>("rock"); terrain.BTexture = Content.Load <Texture2D>("snow"); terrain.DetailTexture = Content.Load <Texture2D>("noise_texture"); //} player = initializePlayer(); sky = intitializeSky(); initializeClouds(); initializeTrees(); //trees = initializeBillBoard(100, "tree_billboard", true, Constants.TREE_SIZE,true); grass = initializeBillBoard(300, "grass_billboard", false, Constants.GRASS_SIZE, false); weapon = new Weapon(this, player, Content.Load <Model>("model//WeaponMachineGun"), new Unit(this, Vector3.Zero, Vector3.Zero, Vector3.One)); bullets = new BulletsManager(this); scoreBoard = new ScoreBoard(this); monsters = new MonstersManager(this); firstAidManger = new FirstAidManager(this); //testing = new CDrawableComponent(this, new Unit(this, new Vector3(0,terrain.GetHeightAtPosition(0,0),0), // Vector3.Zero,new Vector3(5f)), // new CModel(this, Content.Load<Model>("firtree1"))); //waterMesh = new CModel(game.Content.Load<Model>("plane"), position, // Vector3.Zero, new Vector3(size.X, 1, size.Y), game.GraphicsDevice); water = new Water(this, Content.Load <Model>("plane"), new WaterUnit(this, new Vector3(0, Constants.WATER_HEIGHT, 0), Vector3.Zero, new Vector3(10240, 1, 10240))); ((WaterUnit)water.unit).Objects.Add(sky); //((WaterUnit)water.unit).Objects.Add(terrain); stateManager = new StateManager(this); audioManager = new AudioManager(this); frameRateCounter = new FrameRateCounter(this); kinectManager = new KinectManager(this); //CDrawableComponent test = new CDrawableComponent(this, // new Unit(this, new Vector3(0, 80, 0), Vector3.Zero, Vector3.One * .5f), // new CModel(this, Content.Load<Model>(@"model/First Aid Kit2"))); //mediator.fireEvent(MyEvent.G_StartGame); }
private void initializeGame1() { switch (StartScreen.Difficulty) { case Constants.Difficulties.Novice: difficultyConstants = new NoviceConstants(); break; case Constants.Difficulties.Advanced: difficultyConstants = new AdvancedConstants(); break; case Constants.Difficulties.Xtreme: difficultyConstants = new XtremeConstants(); break; } //camera = new FreeCamera(this, new Vector3(0, 0, 0), 0, 0, 0 , 0); //camera = new FreeCamera(new Vector3(400, 600, 400), MathHelper.ToRadians(45), MathHelper.ToRadians(-30), GraphicsDevice); camera = new ChaseCamera(this, Constants.CAMERA_POSITION_THIRD_PERSON, Constants.CAMERA_TARGET_THIRD_PERSON, Vector3.Zero); //for (int i = 0; i < Constants.NUM_OF_TERRAINS; i++) //{ terrain = new Terrain(this, camera, Content.Load<Texture2D>("terrain"+currentLevel), Constants.TERRAIN_CELL_SIZE, Constants.TERRAIN_HEIGHT, Content.Load<Texture2D>("grass"), Constants.TERRAIN_TEXTURE_TILING, new Vector3(1, -1, 0)/*,new Vector2(i%2*-1,i/2*-1)*/); terrain.WeightMap = Content.Load<Texture2D>("weightMap"+currentLevel); terrain.RTexture = Content.Load<Texture2D>("sand"); terrain.GTexture = Content.Load<Texture2D>("rock"); terrain.BTexture = Content.Load<Texture2D>("snow"); terrain.DetailTexture = Content.Load<Texture2D>("noise_texture"); //} player = initializePlayer(); sky = intitializeSky(); initializeClouds(); initializeTrees(); //trees = initializeBillBoard(100, "tree_billboard", true, Constants.TREE_SIZE,true); grass = initializeBillBoard(300, "grass_billboard", false, Constants.GRASS_SIZE,false); weapon = new Weapon(this, player, Content.Load<Model>("model//WeaponMachineGun"), new Unit(this, Vector3.Zero, Vector3.Zero, Vector3.One)); bullets = new BulletsManager(this); scoreBoard = new ScoreBoard(this); monsters = new MonstersManager(this); firstAidManger = new FirstAidManager(this); //testing = new CDrawableComponent(this, new Unit(this, new Vector3(0,terrain.GetHeightAtPosition(0,0),0), // Vector3.Zero,new Vector3(5f)), // new CModel(this, Content.Load<Model>("firtree1"))); //waterMesh = new CModel(game.Content.Load<Model>("plane"), position, // Vector3.Zero, new Vector3(size.X, 1, size.Y), game.GraphicsDevice); water = new Water(this,Content.Load<Model>("plane"), new WaterUnit(this, new Vector3(0,Constants.WATER_HEIGHT,0), Vector3.Zero, new Vector3(10240,1,10240))); ((WaterUnit)water.unit).Objects.Add(sky); //((WaterUnit)water.unit).Objects.Add(terrain); stateManager = new StateManager(this); audioManager = new AudioManager(this); frameRateCounter = new FrameRateCounter(this); kinectManager = new KinectManager(this); //CDrawableComponent test = new CDrawableComponent(this, // new Unit(this, new Vector3(0, 80, 0), Vector3.Zero, Vector3.One * .5f), // new CModel(this, Content.Load<Model>(@"model/First Aid Kit2"))); //mediator.fireEvent(MyEvent.G_StartGame); }
private void initializeClouds() { List<Vector3> cloudPositions = new List<Vector3>(); // Create 20 "clusters" of clouds for (int i = 0; i < 30; i++) { Vector3 cloudLoc = new Vector3( r.Next(-Constants.FIELD_MAX_X_Z, Constants.FIELD_MAX_X_Z), r.Next(Constants.TERRAIN_HEIGHT*9/10, Constants.TERRAIN_HEIGHT*3/2), r.Next(-Constants.FIELD_MAX_X_Z, Constants.FIELD_MAX_X_Z)); // Add 10 cloud billboards around each cluster point for (int j = 0; j < 10; j++) { cloudPositions.Add(cloudLoc + new Vector3( r.Next(-Constants.FIELD_MAX_X_Z / 4, Constants.FIELD_MAX_X_Z/4), r.Next(-Constants.TERRAIN_HEIGHT / 15, Constants.TERRAIN_HEIGHT / 5), r.Next(-Constants.FIELD_MAX_X_Z / 4, Constants.FIELD_MAX_X_Z/4))); } } clouds = new BillboardSystem(this, Content.Load<Texture2D>("cloud2"), new Vector2(200), cloudPositions.ToArray()); clouds.Mode = BillboardSystem.BillboardMode.Spherical; clouds.EnsureOcclusion = false; }
private BillboardSystem initializeBillBoard(int numOfBillBoards, String tex, Boolean EnsureOcclusion, Vector2 size,bool flag) { BillboardSystem billboard = new BillboardSystem(this, Content.Load<Texture2D>(tex), size, initializePositions(numOfBillBoards, size).ToArray()); billboard.Mode = BillboardSystem.BillboardMode.Cylindrical; billboard.EnsureOcclusion = EnsureOcclusion; return billboard; }
// Called when the game should load its content protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); camera = new FreeCamera(new Vector3(8000, 6000, 8000), MathHelper.ToRadians(45), MathHelper.ToRadians(-30), GraphicsDevice); terrain = new Terrain(Content.Load <Texture2D>("terrain"), 30, 4800, Content.Load <Texture2D>("grass"), 6, new Vector3(1, -1, 0), GraphicsDevice, Content); terrain.WeightMap = Content.Load <Texture2D>("weightMap"); terrain.RTexture = Content.Load <Texture2D>("sand"); terrain.GTexture = Content.Load <Texture2D>("rock"); terrain.BTexture = Content.Load <Texture2D>("snow"); terrain.DetailTexture = Content.Load <Texture2D>("noise_texture"); // Positions where trees should be drawn List <Vector3> treePositions = new List <Vector3>(); // Continue until we get 500 trees on the terrain for (int i = 0; i < 500; i++) // 500 { // Get X and Z coordinates from the random generator, between // [-(terrain width) / 2 * (cell size), (terrain width) / 2 * (cell size)] float x = r.Next(-256 * 30, 256 * 30); float z = r.Next(-256 * 30, 256 * 30); // Get the height and steepness of this position on the terrain, // taking the height of the billboard into account float steepness; float y = terrain.GetHeightAtPosition(x, z, out steepness) + 100; // Reject this position if it is too low, high, or steep. Otherwise // add it to the list if (steepness < MathHelper.ToRadians(15) && y > 2300 && y < 3200) { treePositions.Add(new Vector3(x, y, z)); } else { i--; } } trees = new BillboardSystem(GraphicsDevice, Content, Content.Load <Texture2D>("tree_billboard"), new Vector2(200), treePositions.ToArray()); trees.Mode = BillboardSystem.BillboardMode.Cylindrical; trees.EnsureOcclusion = true; // List of positions to place grass billboards List <Vector3> grassPositions = new List <Vector3>(); // Retrieve pixel grid from grass map Texture2D grassMap = Content.Load <Texture2D>("grass_map"); Color[] grassPixels = new Color[grassMap.Width * grassMap.Height]; grassMap.GetData <Color>(grassPixels); // Loop until 1000 billboards have been placed for (int i = 0; i < 300; i++) { // Get X and Z coordinates from the random generator, between // [-(terrain width) / 2 * (cell size), (terrain width) / 2 * (cell size)] float x = r.Next(-256 * 30, 256 * 30); float z = r.Next(-256 * 30, 256 * 30); // Get corresponding coordinates in grass map int xCoord = (int)(x / 30) + 256; int zCoord = (int)(z / 30) + 256; // Get value between 0 and 1 from grass map float texVal = grassPixels[zCoord * 512 + xCoord].R / 255f; // Retrieve height float steepness; float y = terrain.GetHeightAtPosition(x, z, out steepness) + 50; // Randomly place a billboard here based on pixel color in grass // map if ((int)((float)r.NextDouble() * texVal * 10) == 1) { grassPositions.Add(new Vector3(x, y, z)); } else { i--; } } // Create grass billboard system grass = new BillboardSystem(GraphicsDevice, Content, Content.Load <Texture2D>("grass_billboard"), new Vector2(100), grassPositions.ToArray()); grass.Mode = BillboardSystem.BillboardMode.Cylindrical; grass.EnsureOcclusion = false; List <Vector3> cloudPositions = new List <Vector3>(); // Create 20 "clusters" of clouds for (int i = 0; i < 20; i++) { Vector3 cloudLoc = new Vector3( r.Next(-8000, 8000), r.Next(4000, 6000), r.Next(-8000, 8000)); // Add 10 cloud billboards around each cluster point for (int j = 0; j < 10; j++) { cloudPositions.Add(cloudLoc + new Vector3( r.Next(-3000, 3000), r.Next(-300, 900), r.Next(-1500, 1500))); } } clouds = new BillboardSystem(GraphicsDevice, Content, Content.Load <Texture2D>("cloud2"), new Vector2(2000), cloudPositions.ToArray()); clouds.Mode = BillboardSystem.BillboardMode.Spherical; clouds.EnsureOcclusion = false; sky = new SkySphere(Content, GraphicsDevice, Content.Load <TextureCube>("clouds")); water = new Water(Content, GraphicsDevice, new Vector3(0, 1600, 0), new Vector2(256 * 30)); water.Objects.Add(sky); water.Objects.Add(terrain); lastMouseState = Mouse.GetState(); }