public void Draw(GraphicsDevice gd, Camera gameCamera, BasicEffect drawEffect) { drawEffect.DiffuseColor = wallColor.ToVector3(); for (int x = 0; x < 15; x++) { for (int y = 0; y < 9; y++) { if (x == 0 || x == 14 || y == 0 || y == 8) { if (x != 7 && y != 4) { drawEffect.World = Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ(wallRots[x, y]) * Matrix.CreateTranslation(VoxelWorld.ToScreenSpace((x * 16) + 7, (y * 16) + 7, 21) + (Vector3.One * Voxel.HALF_SIZE)) * gameCamera.worldMatrix; foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes) { pass.Apply(); AnimChunk c = objectSheet.AnimChunks[7]; gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2); } } } } } drawEffect.DiffuseColor = Color.White.ToVector3(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); AudioController.LoadContent(Content); tileSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tileSheet); doorSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "door.vxs"), ref doorSheet); objectSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "dynamic.vxs"), ref objectSheet); gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport); particleController = new ParticleController(GraphicsDevice); projectileController = new ProjectileController(GraphicsDevice); bombController = new BombController(GraphicsDevice, objectSheet); enemyController = new EnemyController(GraphicsDevice); projectileController.LoadContent(Content); enemyController.LoadContent(Content); drawEffect = new BasicEffect(GraphicsDevice) { World = gameCamera.worldMatrix, View = gameCamera.viewMatrix, Projection = gameCamera.projectionMatrix, VertexColorEnabled = true, }; gameHero = new Hero(0, 0, Vector3.Zero); gameHero.LoadContent(Content, GraphicsDevice); ThreadPool.QueueUserWorkItem(delegate { CreateRoomsAsync(); }); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 0, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((14 * 16) + 7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 1, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, (8 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 2, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace(7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 3, doorSheet)); roomIcon = Content.Load <Texture2D>("roomicon"); font = Content.Load <SpriteFont>("font"); }
void CreateMap(VoxelSprite tileSheet) { for (int x = 0; x < 15; x++) { for (int y = 0; y < 9; y++) { wallRots[x, y] = MathHelper.PiOver2 * (float)Helper.Random.Next(4); if (x == 0 || x == 14 || y == 0 || y == 8) { if (x != 7 && y != 4) { World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[0], Helper.Random.Next(4), 0); } else { World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[(x == 7 ? 2 : 1)], 0, 0); } } } } for (int i = 0; i < 3; i++) { int rx = 1 + Helper.Random.Next(6); int ry = 1 + Helper.Random.Next(3); int t = 6 + Helper.Random.Next(1); World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite((14 - rx) * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite(rx * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite((14 - rx) * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); if (Helper.Random.Next(5) == 1) { PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace((rx * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (ry * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21)); } if (Helper.Random.Next(5) == 1) { PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace(((14 - rx) * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (ry * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21)); } if (Helper.Random.Next(5) == 1) { PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace((rx * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), ((8 - ry) * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21)); } if (Helper.Random.Next(5) == 1) { PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace(((14 - rx) * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), ((8 - ry) * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21)); } } for (int i = 0; i < 1; i++) { int rx = 2 + Helper.Random.Next(5); int t = 4 + Helper.Random.Next(3); World.CopySprite(rx * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite((14 - rx) * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); } for (int i = 0; i < 1; i++) { int ry = 2 + Helper.Random.Next(2); int t = 4 + Helper.Random.Next(3); World.CopySprite(7 * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite(7 * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); } //if (!((rx == 1 || rx == 14) && ry == 4) && !((ry == 1 || ry == 8) && rx == 7)) //{ // World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[3], 0); //} int enemiesSpawned = 0; bool headSpawned = false; bool oozeSpawned = false; int numEnemies = 0 + Helper.Random.Next(6); while (enemiesSpawned < numEnemies) { for (int x = 1; x < 14; x++) { for (int y = 1; y < 8; y++) { if (!World.GetVoxel((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 23).Active) { // Create an enemy? if (!(x == 7 && y == 4)) { if (enemiesSpawned < numEnemies && Helper.Random.Next(50) == 1) { EnemyType type = (EnemyType)Helper.Random.Next(Enum.GetValues(typeof(EnemyType)).Length); if (type != EnemyType.Head) { if (type == EnemyType.Ooze && oozeSpawned) { continue; } if (type == EnemyType.Ooze) { oozeSpawned = true; } EnemyController.Instance.Spawn(type, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this); enemiesSpawned++; } } } if (x == 7 && y == 4) { if (enemiesSpawned < numEnemies && !headSpawned && Helper.Random.Next(5) == 1) { enemiesSpawned++; EnemyController.Instance.Spawn(EnemyType.Head, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this); headSpawned = true; } } } } } } World.UpdateWorldMeshes(); }
void CreateMap(VoxelSprite tileSheet) { for (int x = 0; x < 15; x++) { for (int y = 0; y < 9; y++) { wallRots[x, y] = MathHelper.PiOver2 * (float)Helper.Random.Next(4); if (x == 0 || x == 14 || y == 0 || y == 8) { if (x != 7 && y != 4) { World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[0], Helper.Random.Next(4), 0); } else { World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[(x == 7 ? 2 : 1)], 0, 0); } } } } for (int i = 0; i < 3; i++) { int rx = 1 + Helper.Random.Next(6); int ry = 1 + Helper.Random.Next(3); int t = 6 + Helper.Random.Next(1); World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite((14 - rx) * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite(rx * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite((14 - rx) * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); } for (int i = 0; i < 1; i++) { int rx = 2 + Helper.Random.Next(5); int t = 4 + Helper.Random.Next(3); World.CopySprite(rx * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite((14 - rx) * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); } for (int i = 0; i < 1; i++) { int ry = 2 + Helper.Random.Next(2); int t = 4 + Helper.Random.Next(3); World.CopySprite(7 * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); World.CopySprite(7 * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1); } //if (!((rx == 1 || rx == 14) && ry == 4) && !((ry == 1 || ry == 8) && rx == 7)) //{ // World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[3], 0); //} int enemiesSpawned = 0; for (int x = 1; x < 14; x++) { for (int y = 1; y < 8; y++) { if (!World.GetVoxel((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21).Active) { // Create an enemy? if (enemiesSpawned < 4 && Helper.Random.Next(50) == 1) { enemiesSpawned++; EnemyType type = (EnemyType)Helper.Random.Next(Enum.GetValues(typeof(EnemyType)).Length); EnemyController.Instance.Spawn(type, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this); } } } } World.UpdateWorldMeshes(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { generatedPercent = 0; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); if (firstRun) { AudioController.LoadContent(Content); tileSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "tiles.vxs"), ref tileSheet); doorSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "door.vxs"), ref doorSheet); objectSheet = new VoxelSprite(16, 16, 16); LoadVoxels.LoadSprite(Path.Combine(Content.RootDirectory, "dynamic.vxs"), ref objectSheet); } else if (AudioController.instances["roomscrape"].State == SoundState.Playing) { AudioController.instances["roomscrape"].Pause(); } gameCamera = new Camera(GraphicsDevice, GraphicsDevice.Viewport); particleController = new ParticleController(GraphicsDevice); projectileController = new ProjectileController(GraphicsDevice); pickupController = new PickupController(GraphicsDevice); bombController = new BombController(GraphicsDevice, objectSheet); enemyController = new EnemyController(GraphicsDevice); projectileController.LoadContent(Content); pickupController.LoadContent(Content); enemyController.LoadContent(Content); drawEffect = new BasicEffect(GraphicsDevice) { World = gameCamera.worldMatrix, View = gameCamera.viewMatrix, Projection = gameCamera.projectionMatrix, VertexColorEnabled = true, }; gameHero = new Hero(0, 0, Vector3.Zero, Vector3.Zero); gameHero.LoadContent(Content, GraphicsDevice); ThreadPool.QueueUserWorkItem(delegate { CreateRoomsAsync(); }); doorCountdown = 10000; roomMovesLeft = 0; roomShift = null; roomState = RoomState.DoorsOpen; deadTime = 0; allRoomsComplete = false; shownComplete = false; showCompleteTime = 0; showCompleteAlpha = 0f; Doors.Clear(); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 0, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((14 * 16) + 7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 1, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace((7 * 16) + 7, (8 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 2, doorSheet)); Doors.Add(new Door(VoxelWorld.ToScreenSpace(7, (4 * 16) + 7, 21) + new Vector3(Voxel.HALF_SIZE, Voxel.HALF_SIZE, Voxel.HALF_SIZE), 3, doorSheet)); if (firstRun) { roomIcon = Content.Load <Texture2D>("roomicon"); texHud = Content.Load <Texture2D>("hud"); texTitle = Content.Load <Texture2D>("titlesheet"); texTitleBG = Content.Load <Texture2D>("title-bg"); texStingers = Content.Load <Texture2D>("stingers"); font = Content.Load <SpriteFont>("font"); timerFontLarge = Content.Load <SpriteFont>("timerfont-large"); timerFontSmall = Content.Load <SpriteFont>("timerfont-small"); } firstRun = false; }