public void Update(GameTime gameTime, Hero gameHero, ref Room[,] Rooms) { float dist = 4f - Vector3.Distance(new Vector3(gameHero.RoomX, gameHero.RoomY, 0f), new Vector3(RoomX, RoomY, 0f)); dist = MathHelper.Clamp(dist, 0f, 3f); Vector3 dir = new Vector3(RoomX, RoomY, 0f) - new Vector3(gameHero.RoomX, gameHero.RoomY, 0f); scrapeSound.Pan = (1f / 3f) * dir.X; scrapeSound.Volume = (1f / 3f) * dist; shiftTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (shiftTime >= targetShiftTime) { scrapeSound.Pause(); AudioController.PlaySFX("roomclunk", (1f / 3f) * dist, 0f, (1f / 3f) * dir.X); Complete = true; Room tempRoom = Rooms[RoomX, RoomY]; Rooms[RoomX, RoomY] = Rooms[RoomTargetX, RoomTargetY]; Rooms[RoomTargetX, RoomTargetY] = tempRoom; if (gameHero.RoomX == RoomX && gameHero.RoomY == RoomY) { gameHero.RoomX = RoomTargetX; gameHero.RoomY = RoomTargetY; } } dist = 3f - Vector3.Distance(new Vector3(gameHero.RoomX, gameHero.RoomY, 0f), new Vector3(RoomX, RoomY, 0f)); dist = MathHelper.Clamp(dist, 0f, 3f); if (Helper.Random.Next(2) == 1) { dist = -dist; } cameraShake = new Vector3(((float)Helper.Random.NextDouble() * dist), 0f, ((float)Helper.Random.NextDouble() * dist)) * 0.1f; }
public void Update(GameTime gameTime, Room currentRoom, Hero gameHero) { explodeTime -= gameTime.ElapsedGameTime.TotalMilliseconds; animTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (animTime >= animTargetTime) { animTargetTime = animTargetTime / 1.3; animTime = 0; CurrentFrame = 1 - CurrentFrame; } if (explodeTime <= 0) { Active = false; Room.World.Explode(Position, 8f, (currentRoom == Room)); if (Room == currentRoom) { ParticleController.Instance.SpawnExplosion(Position); } foreach (Enemy e in EnemyController.Instance.Enemies.Where(en => en.Room == currentRoom)) { if (Vector3.Distance(Position, e.Position) < 10f) { float dam = (100f / 10f) * Vector3.Distance(Position, e.Position); Vector3 speed = (Position - e.Position); speed.Normalize(); e.DoHit(e.Position, speed * 0.5f, dam); } } gameHero.DoExplosionHit(Position, 10f); AudioController.PlaySFX("explosion1", 1f, -0.1f, 0.1f); } }
internal bool DoHit(Vector3 pos, Vector3 speed, float damage) { if (Dead || !introTargetReached) { return(true); } if (defending) { Vector2 v2pos = new Vector2(Position.X, Position.Y); BoundingSphere shieldSphere = new BoundingSphere(new Vector3(Helper.PointOnCircle(ref v2pos, 3f, Rotation), Position.Z - 5f), 4f); if (shieldSphere.Contains(pos) == ContainmentType.Contains) { return(false); } } if (timeSinceLastHit <= 0) { for (int i = 0; i < 4; i++) { ParticleController.Instance.Spawn(pos, speed + new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f)), 0.5f, new Color(0.5f + ((float)Helper.Random.NextDouble() * 0.5f), 0f, 0f), 1000, true); } timeSinceLastHit = 100; AudioController.PlaySFX("player_hit", 0.5f, -0.2f, 0.2f); } hitAlpha = 1f; Health -= damage; return(true); }
public void Collect(Hero gameHero) { switch (Type) { case PickupType.Health: gameHero.Health += 100f; AudioController.PlaySFX("collect_health", 1f, 0f, 0f); break; } Active = false; }
public void DoAttack() { if (!introTargetReached || Dead || attacking || defending) { return; } attacking = true; attackFrame = 0; attackTime = 0; attackDir = 1; AudioController.PlaySFX("sword", 0.2f, -0.2f, 0.2f); }
internal void TryPlantBomb(Room currentRoom) { if (Dead || !introTargetReached) { return; } if (numBombs > 0) { BombController.Instance.Spawn(Position + new Vector3(0f, 0f, -3f), currentRoom); numBombs--; if (bombRespawnTime <= 0) { bombRespawnTime = 5000; } AudioController.PlaySFX("bomb_place", 1f, 0f, 0f); } }
public override void Die() { if (Iteration < 2) { AudioController.PlaySFX("ooze_split", 1f, 0f, 0f); for (int i = 0; i < 3; i++) { float height = spriteSheet.Z_SIZE * Voxel.HALF_SIZE; EnemyController.Instance.SpawnOoze(Position + new Vector3(0f, 0f, height * (0.2f * (Iteration + 1))), Room, Iteration + 1, groundHeight); } } else { AudioController.PlaySFX("ooze_die", 1f, 0f, 0f); } base.Die(); }
internal void Open(bool immediate) { if (!IsOpen) { if (immediate) { IsOpen = true; currentFrame = spriteSheet.AnimChunks.Count - 1; closing = false; opening = false; } else { if (!opening) { AudioController.PlaySFX("door", 0.3f, 0f, 0f); } opening = true; } } }
internal void Close(bool immediate) { if (IsOpen) { if (immediate) { IsOpen = false; currentFrame = 0; opening = false; closing = false; } else { if (!closing) { AudioController.PlaySFX("door", 0.3f, 0f, 0f); } closing = true; } } }
public override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List <Door> doors) { if (currentRoom != Room) { return; } Vector3 dir = Target - Position; if (dir.Length() > 0f) { dir.Normalize(); } Speed = dir * 0.05f; if (Vector3.Distance(Position, Target) <= 1f) { Target = Position + (new Vector3(Helper.AngleToVector(((Rotation + MathHelper.Pi) - MathHelper.PiOver2) + ((float)Helper.Random.NextDouble() * MathHelper.Pi), 100f), 0f)); } Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(Position.X, Position.Y) + (new Vector2(Speed.X, Speed.Y) * 50f), Rotation, 1f, 0.5f); boundingSphere = new BoundingSphere(Position, 3f - (1f * Iteration)); if (Helper.Random.Next(300) == 1) { dir = gameHero.Position - Position; dir.Normalize(); ProjectileController.Instance.Spawn(ProjectileType.Acid, Room, Position, Matrix.Identity, new Vector3(dir.X * 0.3f, dir.Y * 0.3f, -(float)Helper.Random.NextDouble()), 5000, true); AudioController.PlaySFX("ooze_spit", 1f, 0f, 0f); } Scale = 1f - (0.2f * (float)Iteration); if (hitAlpha > 0f) { hitAlpha -= 0.1f; } base.Update(gameTime, currentRoom, gameHero, doors); }
public void DoDefend(bool def, Vector2 virtualJoystick) { if (Dead || !introTargetReached) { return; } if (!def) { defending = false; } if (!attacking && def) { if (!defending) { AudioController.PlaySFX("defend", 0.6f, -0.1f, 0.1f); } defending = true; } }
public override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List <Door> doors) { if (currentRoom != Room) { return; } if (Vector3.Distance(Position, gameHero.Position) < 30f) { attacking = true; } if (attacking) { Speed = Vector3.Zero; Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), Rotation, 1f, 0.5f); attackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (attackTime >= attackTargetTime) { attackTime = 0; attackFrame += attackDir; if (attackFrame == numAttackFrames - 1 && attackDir == 1) { ProjectileController.Instance.Spawn(ProjectileType.Laserbolt, Room, Position, Matrix.CreateRotationZ(Rotation), new Vector3(Helper.AngleToVector(Rotation, 0.5f), 0f), 5000, false); AudioController.PlaySFX("sentinel_shoot", 1f, 0f, 0f); } if (attackFrame == numAttackFrames - 1) { attackDir = -1; attackFrame = numAttackFrames - 2; } if (attackFrame == -1) { attackFrame = 0; if (Vector3.Distance(Position, gameHero.Position) >= 30f) { attacking = false; } attackDir = 1; } } } else { Vector3 dir = Target - Position; if (dir.Length() > 0f) { dir.Normalize(); } Speed = dir * 0.2f; if (Vector3.Distance(Position, Target) <= 1f) { Target = Position + (new Vector3(Helper.AngleToVector(((Rotation + MathHelper.Pi) - MathHelper.PiOver2) + ((float)Helper.Random.NextDouble() * MathHelper.Pi), 100f), 0f)); } Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(Position.X, Position.Y) + (new Vector2(Speed.X, Speed.Y) * 50f), Rotation, 1f, 0.5f); base.Update(gameTime, currentRoom, gameHero, doors); } boundingSphere = new BoundingSphere(Position, 3f); for (float z = Position.Z; z < 25f; z += 0.1f) { if (Room.World.GetVoxel(new Vector3(Position.X, Position.Y, z)).Active) { groundHeight = z; break; } } if (hitAlpha > 0f) { hitAlpha -= 0.1f; } if (Health <= 0f) { Die(); } }
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 override void Update(GameTime gameTime, Room currentRoom, Hero gameHero, List <Door> doors) { if (currentRoom != Room) { return; } Rotation = Helper.TurnToFace(new Vector2(Position.X, Position.Y), new Vector2(gameHero.Position.X, gameHero.Position.Y), Rotation, 1f, 0.5f); Speed.Z += (0.001f * bobDir); if (Speed.Z > 0.05f) { bobDir = -1f; } if (Speed.Z < -0.05f) { bobDir = 1f; } Position += Speed; for (float z = Position.Z; z < 25f; z += 0.1f) { if (Room.World.GetVoxel(new Vector3(Position.X, Position.Y, z)).Active) { groundHeight = z; break; } } //base.Update(gameTime, currentRoom, gameHero, doors); boundingSphere = new BoundingSphere(Position, 4f); if (!attacking && Helper.Random.Next(300) == 1) { attacking = true; attackDir = 1; attackMode = Helper.Random.Next(2); AudioController.PlaySFX("face_open", 1f, 0f, 0f); } if (attacking) { if (attackMode == 0) { offsetFrame = 0; } if (attackMode == 1) { offsetFrame = 7; } attackTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (attackTime >= attackTargetTime) { attackTime = 0; if ((attackDir == 1 && attackFrame < numAttackFrames - 1) || attackDir == -1) { attackFrame += attackDir; } } if (attackFrame == numAttackFrames - 1 && attackDir == 1) { switch (attackMode) { case 0: missileDelay += gameTime.ElapsedGameTime.TotalMilliseconds; if (missileDelay >= 500) { missileDelay = 0; float rot = (Rotation - 0.5f) + ((float)Helper.Random.NextDouble() * 1f); ProjectileController.Instance.Spawn(ProjectileType.Rocket, Room, Position + new Vector3(0f, 0f, -2f), Matrix.CreateRotationZ(rot), new Vector3(Helper.AngleToVector(rot, 0.5f), 0.2f), 7000, false); missilesLaunched++; AudioController.PlaySFX("face_missile", 1f, 0f, 0f); } if (missilesLaunched == 3) { attackDir = -1; missilesLaunched = 0; } break; case 1: if (!gunSoundPlayed) { AudioController.PlaySFX("face_gun", 1f, 0f, 0f); gunSoundPlayed = true; } missileDelay += gameTime.ElapsedGameTime.TotalMilliseconds; if (missileDelay >= 50) { missileDelay = 0; float rot = (Rotation - 0.1f) + ((float)Helper.Random.NextDouble() * 0.2f); ProjectileController.Instance.Spawn(ProjectileType.Gatling, Room, Position + new Vector3(0f, 0f, 2f), Matrix.CreateRotationZ(rot), new Vector3(Helper.AngleToVector(rot, 1f), 0.1f), 5000, false); missilesLaunched++; } if (missilesLaunched == 20) { attackDir = -1; missilesLaunched = 0; } break; } } if (attackFrame == -1) { attackFrame = 0; attacking = false; offsetFrame = 0; attackDir = 1; gunSoundPlayed = false; } } if (hitAlpha > 0f) { hitAlpha -= 0.1f; } if (Health <= 0f) { Die(); } }
public override void Die() { AudioController.PlaySFX("face_die", 1f, 0f, 0f); base.Die(); }