public void UpdateStarField(GameTime gameTime, VoxelWorld gameWorld, float scrollSpeed) { 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 * scrollSpeed; if (Position.Z > 20f) { Active = false; } if (Time >= Life && scrollSpeed > 0f) { 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; } }
void CheckCollisions(VoxelWorld world, Camera gameCamera) { float checkRadius = 3.5f; float radiusSweep = 0.1f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (tempSpeed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y/2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) tempSpeed.Y = 0; } } if (tempSpeed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) tempSpeed.Y = 0; } } if (tempSpeed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } if (tempSpeed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } }
public virtual void CheckCollisions(VoxelWorld world, 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; if (gameHero.CollisionBox.Intersects(boundingSphere)) { gameHero.DoHit(Position, null); } 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, gameHero, world, false); } } } 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, gameHero, world, false); } //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(false, true, false, checkPos, currentRoom, gameHero, true); 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, gameHero, world, false); } //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); 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, gameHero, world, false); } //if (gameHero.boundingSphere.Contains(checkPos) == ContainmentType.Contains) { DoCollide(true, false, false, checkPos, currentRoom, gameHero, true); break;} } } }
void CheckCollisions(VoxelWorld world, Camera gameCamera) { float checkRadius = 3.5f; float radiusSweep = 0.1f; Vector2 v2Pos = new Vector2(Position.X, Position.Y); float checkHeight = Position.Z - 1f; Voxel checkVoxel; Vector3 checkPos; if (tempSpeed.Y < 0f) { for (float a = -MathHelper.PiOver2 - radiusSweep; a < -MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.Y = 0; } } } if (tempSpeed.Y > 0f) { for (float a = MathHelper.PiOver2 - radiusSweep; a < MathHelper.PiOver2 + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.Y / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.Y = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.Y = 0; } } } if (tempSpeed.X < 0f) { for (float a = -MathHelper.Pi - radiusSweep; a < -MathHelper.Pi + radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } if (tempSpeed.X > 0f) { for (float a = -radiusSweep; a < radiusSweep; a += 0.02f) { checkPos = new Vector3(Helper.PointOnCircle(ref v2Pos, collisionBoxSize.X / 2, a), checkHeight); checkVoxel = world.GetVoxel(checkPos); if ((checkVoxel.Active && world.CanCollideWith(checkVoxel.Type))) { tempSpeed.X = 0f; } if (gameCamera.boundingFrustum.Contains(checkPos) == ContainmentType.Disjoint) { tempSpeed.X -= Speed.X; break; } } } }