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 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 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; } } } } }