public void Update(GameTime gameTime, VoxelWorld gameWorld) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) { Speed.Z += GRAVITY; if (Speed.Z > 0f) { Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f, 0f, Scale)); if (v.Active && gameWorld.CanCollideWith(v.Type)) { Speed = new Vector3(Speed.X / 2, Speed.Y / 2, -(Speed.Z / 2f)); } } Speed.Z = (float)Math.Round(Speed.Z, 3); } Position += Speed; if (Position.Z > 20f) { Active = false; } if (Time >= Life) { Scale -= 0.01f; if (Scale <= 0f) { Active = false; } } }
public void Update(GameTime gameTime, VoxelWorld gameWorld) { Time += gameTime.ElapsedGameTime.TotalMilliseconds; if (affectedByGravity) { Speed.Z += GRAVITY; if (Speed.Z > 0f) { Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f,0f,Scale)); if (v.Active && gameWorld.CanCollideWith(v.Type)) Speed = new Vector3(Speed.X/2,Speed.Y/2,-(Speed.Z / 2f)); } Speed.Z = (float)Math.Round(Speed.Z, 3); } Position += Speed; if (Position.Z > 20f) Active = false; if (Time >= Life) { Scale -= 0.01f; if(Scale<=0f) Active = false; } }
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(); }
public Room(VoxelSprite tileSheet, VoxelSprite objects, bool isGap) { IsGap = isGap; if (!isGap) { World = new VoxelWorld(15, 9, 1, true); CreateMap(tileSheet); } objectSheet = objects; }
public void Update(GameTime gameTime, VoxelWorld gameWorld, Vector3 shake) { Offset = new Vector3(0, 60, -50);// -(new Vector3(0, Position.Z, -Position.Z) * 0.3f); //Offset = new Vector3(0, 20, -10);// - (new Vector3(0,Position.Z,-Position.Z) * 0.3f); //Position = Vector3.Clamp(Position, gameWorld.ToScreenSpace(140, 115, 0), gameWorld.ToScreenSpace(gameWorld.X_SIZE - 140, gameWorld.Y_SIZE - 90, 20)); //Position = Vector3.Clamp(Position, new Vector3(70, 60, 0), gameWorld.ToScreenSpace(gameWorld.X_SIZE, gameWorld.Y_SIZE, 0) - new Vector3(100, 60, 50)); //Target = Vector3.Clamp(Target, gameWorld.ToScreenSpace(140, 115, 0), gameWorld.ToScreenSpace(gameWorld.X_SIZE - 140, gameWorld.Y_SIZE - 90, 20)); Position = Vector3.Lerp(Position, Target, moveSpeed); //worldMatrix = Matrix.CreateWorld(Position, Vector3.Forward, Vector3.Up); viewMatrix = Matrix.CreateLookAt(Position + Offset, Position + new Vector3(0, 20, 0) + shake, Vector3.Down); //viewMatrix = Matrix.CreateLookAt(Position + Offset, Position + new Vector3(0, 0, 0), Vector3.Down); boundingFrustum.Matrix = viewMatrix * projectionMatrix; }
public Room(VoxelSprite tileSheet, VoxelSprite objects, bool isGap) { IsGap = isGap; if (!isGap) { World = new VoxelWorld(15, 9, 1, true); CreateMap(tileSheet); } else IsComplete = true; //IsComplete = true; objectSheet = objects; }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld) { int parts = 0; foreach (Particle p in Particles.Where(part => part.Active)) { p.Update(gameTime, gameWorld); ParticleCube.Create(ref verts, ref indexes, p.Position, parts, p.Scale/2, p.Color); parts++; } currentParticleCount = Particles.Count(part => part.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
/// <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"); }
public void Update(GameTime gameTime, Camera gameCamera, VoxelWorld gameWorld) { int parts = 0; foreach (Particle p in Particles.Where(part => part.Active)) { p.Update(gameTime, gameWorld); ParticleCube.Create(ref verts, ref indexes, p.Position, parts, p.Scale / 2, p.Color); parts++; } currentParticleCount = Particles.Count(part => part.Active); drawEffect.World = gameCamera.worldMatrix; drawEffect.View = gameCamera.viewMatrix; drawEffect.Projection = gameCamera.projectionMatrix; }
public Chunk(VoxelWorld world, int wx, int wy, int wz, bool createGround) { parentWorld = world; worldX = wx; worldY = wy; worldZ = wz; boundingSphere = new BoundingSphere(new Vector3(worldX * (X_SIZE * Voxel.SIZE), worldY * (Y_SIZE * Voxel.SIZE), worldZ * (Z_SIZE * Voxel.SIZE)) + (new Vector3(X_SIZE * Voxel.SIZE, Y_SIZE * Voxel.SIZE, Z_SIZE * Voxel.SIZE) / 2f), (X_SIZE * Voxel.SIZE)); if (createGround) { for (int y = 0; y < Y_SIZE; y++) for (int x = 0; x < X_SIZE; x++) { for (int z = Chunk.Z_SIZE - 1; z >= Chunk.Z_SIZE - 2; z--) { SetVoxel(x, y, z, true, 0, VoxelType.Ground, new Color(0.3f, 0.3f,0.3f), new Color(0.2f,0.2f,0.2f)); } } } }
public Chunk(VoxelWorld world, int wx, int wy, int wz, bool createGround) { parentWorld = world; worldX = wx; worldY = wy; worldZ = wz; boundingSphere = new BoundingSphere(new Vector3(worldX * (X_SIZE * Voxel.SIZE), worldY * (Y_SIZE * Voxel.SIZE), worldZ * (Z_SIZE * Voxel.SIZE)) + (new Vector3(X_SIZE * Voxel.SIZE, Y_SIZE * Voxel.SIZE, Z_SIZE * Voxel.SIZE) / 2f), (X_SIZE * Voxel.SIZE)); if (createGround) { for (int y = 0; y < Y_SIZE; y++) { for (int x = 0; x < X_SIZE; x++) { for (int z = Chunk.Z_SIZE - 1; z >= Chunk.Z_SIZE - 2; z--) { SetVoxel(x, y, z, true, 0, VoxelType.Ground, new Color(0.3f, 0.3f, 0.3f), new Color(0.2f, 0.2f, 0.2f)); } } } } }
public override void DoCollide(bool x, bool y, bool z, Vector3 checkPosition, Room currentRoom, Hero gameHero, bool withPlayer) { if (withPlayer) { if (!gameHero.DoHit(checkPosition, Speed, 0.5f)) { if (x) { Speed.X = (Speed.X * -0.9f); } if (y) { Speed.Y = (Speed.Y * -0.9f); } if (z) { Speed.Z = (Speed.Z * -0.9f); } } else { if (x) { Speed.X = 0f; } if (y) { Speed.Y = 0f; } if (z) { Speed.Z = 0f; } } } else { if (x) { Speed.X = (Speed.X * -0.9f); } if (y) { Speed.Y = (Speed.Y * -0.9f); } if (z) { Speed.Z = (Speed.Z * -0.9f); } } if (Speed.Length() > 0.2f) { Vector3 worldSpace = VoxelWorld.FromScreenSpace(checkPosition); Voxel v = Room.World.GetVoxel(checkPosition); if (v.Active && Active) { if (v.Destructable == 1) { if (Helper.Random.Next(4) == 1) { Room.World.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false); if (Room == currentRoom) { ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.25f, new Color(v.SR, v.SG, v.SB), 1000, true); } } } //Active = false; } } //base.DoCollide(x, y, z); }
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(); }
public static void LoadWorld(string fn, ref VoxelWorld gameWorld) { byte[] buffer; using (FileStream gstr = new FileStream(fn, FileMode.Open)) { byte[] lb = new byte[4]; gstr.Position = gstr.Length - 4; gstr.Read(lb, 0,4); int msgLength = BitConverter.ToInt32(lb, 0); buffer = new byte[msgLength]; gstr.Position = 0; using (GZipStream str = new GZipStream(gstr, CompressionMode.Decompress)) { str.Read(buffer, 0, msgLength); } } int pos = 0; int xs = buffer[0]; int ys = buffer[1]; int zs = buffer[2]; gameWorld = new VoxelWorld(xs, ys, zs, false); pos = 3; for (int z = 0; z < gameWorld.Z_CHUNKS; z++) { for (int y = 0; y < gameWorld.Y_CHUNKS; y++) { for (int x = 0; x < gameWorld.X_CHUNKS; x++) { Chunk c = gameWorld.Chunks[x, y, z]; while (pos < buffer.Length) { if (Convert.ToChar(buffer[pos]) != 'c') { int vx = buffer[pos]; int vy = buffer[pos + 1]; int vz = buffer[pos + 2]; VoxelType type = (VoxelType)buffer[pos + 3]; byte destruct = buffer[pos + 4]; Color top = new Color(buffer[pos + 5], buffer[pos + 6], buffer[pos + 7]); Color side = new Color(buffer[pos + 8], buffer[pos + 9], buffer[pos + 10]); c.SetVoxel(vx, vy, vz, true, destruct, type, top, side); pos += 11; } else { pos++; break; } } } } } gameWorld.UpdateWorldMeshes(); GC.Collect(); }
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(); }
void CheckCollisions(Room currentRoom, Hero gameHero) { Vector3 worldSpace; switch (Type) { case ProjectileType.Laserbolt: case ProjectileType.Gatling: for (float d = 0f; d < 1f; d += 0.25f) { worldSpace = VoxelWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = Room.World.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { if (v.Destructable == 1) { Room.World.SetVoxelActive((int)worldSpace.X, (int)worldSpace.Y, (int)worldSpace.Z, false); if (Room == currentRoom) { for (int i = 0; i < 4; i++) { ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.25f, new Color(v.SR, v.SG, v.SB), 1000, true); } } } Active = false; } if (!gameHero.Dead && gameHero.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { if (!gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 2f)) { Speed = -Speed; float rot = Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y)); if (Type == ProjectileType.Gatling) { rot = (rot - 0.2f) + ((float)Helper.Random.NextDouble() * 0.4f); } Speed = new Vector3(Helper.AngleToVector(rot, 1f), 0f); Deflected = true; Rotation = Matrix.CreateRotationZ(rot); AudioController.PlaySFX(Type == ProjectileType.Laserbolt?"deflect":"gatling_deflect", Type == ProjectileType.Laserbolt?0.5f:1f, -0.1f, 0.1f); } else { Active = false; } } if (Deflected) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 5f); Active = false; } } } } break; case ProjectileType.Rocket: for (float d = 0f; d < 1f; d += 0.25f) { worldSpace = VoxelWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = Room.World.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) { ParticleController.Instance.SpawnExplosion(Position); } gameHero.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); if (Deflected) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) { e.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) { ParticleController.Instance.SpawnExplosion(Position); } } } Active = false; AudioController.PlaySFX("explosion2", 1f, -0.1f, 0.1f); } if (!gameHero.Dead && gameHero.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { if (!gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 0f)) { Speed = -Speed; Deflected = true; Rotation = Matrix.CreateRotationZ(Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y))); AudioController.PlaySFX("deflect", 0.5f, -0.1f, 0.1f); } else { gameHero.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) { ParticleController.Instance.SpawnExplosion(Position); } Active = false; AudioController.PlaySFX("explosion2", 1f, -0.1f, 0.1f); } } if (Deflected) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoExplosionHit(Position + (d * ((Position + Speed) - Position)), 5f); Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 5f, Room == currentRoom); if (Room == currentRoom) { ParticleController.Instance.SpawnExplosion(Position); } Active = false; AudioController.PlaySFX("explosion2", 1f, -0.1f, 0.1f); } } } } break; case ProjectileType.Acid: for (float d = 0f; d < 1f; d += 0.25f) { worldSpace = VoxelWorld.FromScreenSpace(Position + (d * ((Position + Speed) - Position))); Voxel v = Room.World.GetVoxel(Position + (d * ((Position + Speed) - Position))); if (v.Active && Active) { Room.World.Explode(Position + (d * ((Position + Speed) - Position)), 2f, Room == currentRoom); for (int i = 0; i < 4; i++) { ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.5f, new Color(0f, 0.5f + ((float)Helper.Random.NextDouble() * 0.5f), 0f), 1000, true); } Active = false; AudioController.PlaySFX("acid_hit", 1f, -0.1f, 0.1f); } if (!gameHero.Dead && gameHero.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { if (!gameHero.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 5f)) { Speed = -Speed; float rot = Helper.V2ToAngle(new Vector2(Speed.X, Speed.Y)); if (Type == ProjectileType.Gatling) { rot = (rot - 0.2f) + ((float)Helper.Random.NextDouble() * 0.4f); } Speed = new Vector3(Helper.AngleToVector(rot, 0.2f), Speed.Z); Deflected = true; Rotation = Matrix.CreateRotationZ(rot); } else { Active = false; AudioController.PlaySFX("acid_hit", 1f, -0.1f, 0.1f); for (int i = 0; i < 4; i++) { ParticleController.Instance.Spawn(Position, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 0.5f)), 0.5f, new Color(0f, 0.5f + ((float)Helper.Random.NextDouble() * 0.5f), 0f), 1000, true); } } } //if (Deflected) // foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room)) // { if (e.boundingSphere.Contains(Position + (d * ((Position + Speed) - Position))) == ContainmentType.Contains) { e.DoHit(Position + (d * ((Position + Speed) - Position)), Speed, 5f); Active = false; } } } break; //case ProjectileType.Grenade: // float checkRadius = 1f; // float radiusSweep = 0.5f; // Vector2 v2Pos = new Vector2(Position.X,Position.Y); // Voxel checkVoxel; // Vector3 checkPos; // if (Speed.Z > 0f) // { // for (float z = 0f; z < 2f; z+=1f) // { // Voxel v = gameWorld.GetVoxel(Position + new Vector3(0f, 0f, z)); // if (v.Active && gameWorld.CanCollideWith(v.Type)) Speed = new Vector3(Speed.X * 0.6f, Speed.Y * 0.6f, -(Speed.Z / 2f)); // } // } // if (Speed.Y < 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.Y = 0f; // } // } // } // } // if (Speed.Y > 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.Y = 0f; // } // } // } // } // if (Speed.X < 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.X = 0f; // } // } // } // } // if (Speed.X > 0f) // { // for (float r = checkRadius; r > 0f; r -= 1f) // { // for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) // { // checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, r, a), Position.Z); // checkVoxel = gameWorld.GetVoxel(checkPos); // if ((checkVoxel.Active && gameWorld.CanCollideWith(checkVoxel.Type))) // { // Speed.X = 0f; // } // } // } // } // break; } }
public virtual void CheckCollisions(VoxelWorld world, List<Door> doors, Room currentRoom, Hero gameHero) { float checkRadius = 3.5f; float radiusSweep = 0.75f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; Vector3 mapBoundsMin = new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f); Vector3 mapBoundsMax = new Vector3(world.X_SIZE * Voxel.SIZE, world.Y_SIZE * Voxel.SIZE, world.Z_SIZE) - new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f); if (Speed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en!=this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (knockbackTime <= 0) foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;} if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } } } }
void CheckCollisions(VoxelWorld world, List<Door> doors, Room currentRoom) { float checkRadius = 3.5f; float radiusSweep = 0.75f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (Speed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.Y = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos)==ContainmentType.Contains) Speed.Y = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f,0f,-5f)) == ContainmentType.Contains) Speed.Y = 0f; } } } if (Speed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.Y = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.Y = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.Y = 0f; } } } if (Speed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.X = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.X = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.X = 0f; } } } if (Speed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.X = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) Speed.X = 0f; } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) Speed.X = 0f; } } } }
public static void LoadWorld(string fn, ref VoxelWorld gameWorld) { byte[] buffer; using (FileStream gstr = new FileStream(fn, FileMode.Open)) { byte[] lb = new byte[4]; gstr.Position = gstr.Length - 4; gstr.Read(lb, 0, 4); int msgLength = BitConverter.ToInt32(lb, 0); buffer = new byte[msgLength]; gstr.Position = 0; using (GZipStream str = new GZipStream(gstr, CompressionMode.Decompress)) { str.Read(buffer, 0, msgLength); } } int pos = 0; int xs = buffer[0]; int ys = buffer[1]; int zs = buffer[2]; gameWorld = new VoxelWorld(xs, ys, zs, false); pos = 3; for (int z = 0; z < gameWorld.Z_CHUNKS; z++) { for (int y = 0; y < gameWorld.Y_CHUNKS; y++) { for (int x = 0; x < gameWorld.X_CHUNKS; x++) { Chunk c = gameWorld.Chunks[x, y, z]; while (pos < buffer.Length) { if (Convert.ToChar(buffer[pos]) != 'c') { int vx = buffer[pos]; int vy = buffer[pos + 1]; int vz = buffer[pos + 2]; VoxelType type = (VoxelType)buffer[pos + 3]; byte destruct = buffer[pos + 4]; Color top = new Color(buffer[pos + 5], buffer[pos + 6], buffer[pos + 7]); Color side = new Color(buffer[pos + 8], buffer[pos + 9], buffer[pos + 10]); c.SetVoxel(vx, vy, vz, true, destruct, type, top, side); pos += 11; } else { pos++; break; } } } } } gameWorld.UpdateWorldMeshes(); GC.Collect(); }
/// <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; }
public virtual void CheckCollisions(VoxelWorld world, List <Door> doors, Room currentRoom, Hero gameHero) { float checkRadius = 3.5f; float radiusSweep = 0.75f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; Vector3 mapBoundsMin = new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f); Vector3 mapBoundsMax = new Vector3(world.X_SIZE * Voxel.SIZE, world.Y_SIZE * Voxel.SIZE, world.Z_SIZE) - new Vector3(Chunk.X_SIZE * Voxel.SIZE, Chunk.Y_SIZE * Voxel.SIZE, 0f); if (Speed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } break; } if (knockbackTime <= 0) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } break; } } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } break; } if (knockbackTime <= 0) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); } break; } } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.Y < mapBoundsMin.Y || checkPos.Y > mapBoundsMax.Y) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } break; } if (knockbackTime <= 0) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } break; } } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } } } if (Speed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } foreach (Door d in doors) { if (d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } break; } if (knockbackTime <= 0) { foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == Room && en != this)) { if (e.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); } break; } } if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break; } if (checkPos.X < mapBoundsMin.X || checkPos.X > mapBoundsMax.X) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, false); break; } } } }
void CheckCollisions(VoxelWorld world, List <Door> doors, Room currentRoom) { float checkRadius = 3.5f; float radiusSweep = 0.75f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (Speed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.Y = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { Speed.Y = 0f; } } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) { Speed.Y = 0f; } } } } if (Speed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.Y = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { Speed.Y = 0f; } } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) { Speed.Y = 0f; } } } } if (Speed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.X = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { Speed.X = 0f; } } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) { Speed.X = 0f; } } } } if (Speed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, checkRadius, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { Speed.X = 0f; } foreach (Door d in doors) { if (d.IsBlocked && d.CollisionBox.Contains(checkPos) == ContainmentType.Contains) { Speed.X = 0f; } } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (e.boundingSphere.Contains(checkPos + new Vector3(0f, 0f, -5f)) == ContainmentType.Contains) { Speed.X = 0f; } } } } }