public void COLLISION(Enemy enemy, Bullet bullet, Game1 game) { if (bullet.Rectangle.Intersects(enemy.Rectangle)) { if (IntersectPixels(enemy.RectanglePosTransform, enemy.Texture.Width, enemy.Texture.Height, enemy.TextureData, bullet.RectanglePosTransform, bullet.Texture.Width, bullet.Texture.Height, bullet.TextureData)) { bullet.Alive = false; enemy.EnemyShot(bullet, game); } } }
public void EDGECOLLISION(Enemy thing, Rectangle bounds) { if (thing.Position.Y < bounds.Y) { thing.Position += new Vector2(0, bounds.Y - thing.Position.Y); thing.Velocity *= new Vector2(1, -f_EdgeDamper); } else if (thing.Position.Y > bounds.Y + bounds.Height) { thing.Position -= new Vector2(0, thing.Position.Y - (bounds.Y + bounds.Height)); thing.Velocity *= new Vector2(1, -f_EdgeDamper); } if (thing.Position.X < bounds.X) { thing.Position += new Vector2(bounds.X - thing.Position.X, 0); thing.Velocity *= new Vector2(-f_EdgeDamper, 1); } else if (thing.Position.X > bounds.X + bounds.Width) { thing.Position -= new Vector2(thing.Position.X - (bounds.X + bounds.Width), 0); thing.Velocity *= new Vector2(-f_EdgeDamper, 1); } }
public void COLLISION(Enemy enemy, Particle particle) { if (enemy.Rectangle.Intersects(particle.Rectangle)) { if (IntersectPixels(particle.RectanglePosTransform, particle.Texture.Width, particle.Texture.Height, particle.TextureData, enemy.RectanglePosTransform, enemy.Texture.Width, enemy.Texture.Height, enemy.TextureData)) { if (enemy.closestParticle != null) { if (enemy.closestParticle == particle) { particle.BeingAttacked = true; particle.Attacker = enemy; enemy.attacking = true; } } else { Vector2 impactSpeed; Vector2 impulse; float resultantImpulse; impactSpeed = particle.Velocity - enemy.Velocity; impulse = Vector2.Normalize(particle.Position - enemy.Position); resultantImpulse = Vector2.Dot(impulse, impactSpeed); if (resultantImpulse < 0) { resultantImpulse *= -1; } impulse = impulse * (float)Math.Sqrt(resultantImpulse); particle.Velocity += impulse; //enemy.Velocity -= impulse; //enemies aren't affected by particle collisions :P } } } }
public void COLLISION(Enemy enemyA, Enemy enemyB) { if (enemyA.Rectangle.Intersects(enemyB.Rectangle)) { if (IntersectPixels(enemyB.RectanglePosTransform, enemyB.Texture.Width, enemyB.Texture.Height, enemyB.TextureData, enemyA.RectanglePosTransform, enemyA.Texture.Width, enemyA.Texture.Height, enemyA.TextureData)) { Vector2 impactSpeed; Vector2 impulse; float resultantImpulse; impactSpeed = enemyB.Velocity - enemyA.Velocity; impulse = Vector2.Normalize(enemyB.Position - enemyA.Position); resultantImpulse = Vector2.Dot(impulse, impactSpeed); if (resultantImpulse < 0) { resultantImpulse *= -1; } impulse = impulse * (float)Math.Sqrt(resultantImpulse); enemyB.Velocity += impulse * 5; enemyA.Velocity -= impulse * 5; //enemies aren't affected by enemyB collisions :P } } }
public void COLLISION(Ship ship, Enemy enemy, Game1 game) { if (ship.Rectangle.Intersects(enemy.Rectangle)) { if (IntersectPixels(enemy.RectanglePosTransform, enemy.Texture.Width, enemy.Texture.Height, enemy.TextureData, ship.RotationTransform, ship.Texture.Width, ship.Texture.Height, ship.TextureData)) { i_VibrateCounter++; //add to vibration amount enemy.EnemyCollisionPosition = enemy.Position;// -new Vector2(enemy.Texture.Width / 2, enemy.Texture.Height / 2); ship.ShipShield -= 25; if (ship.ShipShield < 0) { //You are Dead game.soundBank.PlayCue("shipExplode"); dead = true; } if (ship.ShipShield == 75) { game.soundBank.PlayCue("75percent"); } else if (ship.ShipShield == 50) { game.soundBank.PlayCue("50percent"); } else if (ship.ShipShield == 25) { game.soundBank.PlayCue("25percent"); } else if (ship.ShipShield == 0) { ship.ShipShield = -1; game.soundBank.PlayCue("shieldsdown"); } else enemy.EnemyCollision = true; ship.Hit = true; enemy.Alive = false; game.soundBank.PlayCue("enemyDie"); game.vibrate = 20; if (enemy.closestParticle != null) { enemy.closestParticle.BeingAttacked = false; enemy.closestParticle.Attacker = null; if (enemy.closestParticle.IsTethered == false) { enemy.closestParticle.Color = Color.White; } } } } }
public void UpdateShieldSpark(Vector2 collision, Enemy enemy) { enemy.ShieldSpark.AddParticles(collision, new Vector2(0, 0), ship.Position, 0, true); }
public void UpdateParticleKill(Vector2 collision, Particle particle, Enemy enemy) { enemy.ParticleKill.AddParticles((collision - new Vector2((particle.Texture.Width / 2), (particle.Texture.Width / 4))), new Vector2(0, 0), ship.Position, 0, true); }
public void Update(GameTime gameTime, SoundBank soundBank, Game1 game) { if (game.gameState != State.Tutorial) { SegmentUpdate(); if (Ambient.IsPlaying == false) { Ambient.Play(); } else if (Ambient.IsPaused == true) { Ambient.Resume(); } if (f_Fusions >= loadedLevel.levelData.i_TargetFusions) { game.i_GameOverSel = 1; game.f_LevelCompleteBonus = 500; game.fd_Fader.BeginFadingToBlack(75, true, game); } if (dt_timer.Minute == 0 && dt_timer.Second == 0) { game.fd_Fader.BeginFadingToBlack(75, true, game); } else { dt_timer -= gameTime.ElapsedGameTime; } offset = ship.OffsetUpdate(offset); if (dead == true) { UpdateExplosion(ship.Position); } #region Enemy Spawn and Update for (int i = 0; i < loadedLevel.levelData.i_MaxNumberEnemies; i++) { if (enemies[i].EnemyCollision == true) { UpdateShieldSpark(enemies[i].EnemyCollisionPosition, enemies[i]); enemies[i].ShieldSparkCounter++; if (enemies[i].ShieldSparkCounter == 40) { enemies[i].EnemyCollision = false; enemies[i].ShieldSparkCounter = 0; } } if (enemies[i].IsParticleKill == true) { UpdateParticleKill(enemies[i].ParticleKillPosition, enemies[i].p_ParticleKilled, enemies[i]); enemies[i].ParticleKillCounter++; if (enemies[i].ParticleKillCounter == 40) { enemies[i].IsParticleKill = false; enemies[i].ParticleKillCounter = 0; } } if (enemies[i].Alive == true) { enemies[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction); } else if (enemies[i].SpawnTimer == loadedLevel.levelData.i_EnemySpawnRate) { enemies[i] = new Enemy(game, loadedLevel); enemies[i].LoadTexture(game.Content); enemies[i].Spawn(offset, loadedLevel.levelBounds); enemies[i].SpawnTimer = 0; enemies[i].Rectangle = new Rectangle(((int)enemies[i].Position.X - (enemies[i].Texture.Width / 2)), ((int)enemies[i].Position.Y - (enemies[i].Texture.Height / 2)), enemies[i].Texture.Width, enemies[i].Texture.Height); enemies[i].TextureData = new Color[enemies[i].Texture.Width * enemies[i].Texture.Height]; enemies[i].Texture.GetData(enemies[i].TextureData); } } for (int i = 0; i < loadedLevel.levelData.i_MaxNumberEnemies; i++) { if (enemies[i].Alive == false) { enemies[i].SpawnTimer++; break; } } #endregion #region Particles Spawning for (int i = 0; i < Photons.Length; i++) { if (Photons[i].ParticleState == Particle.PState.Fusing) { if (Photons[i].i_Fusing > 50) { Photons[i].ParticleState = Particle.PState.Dead; Photons[i].i_Fusing = 0; } else { Photons[i].i_Fusing++; } } else if (Photons[i].ParticleState == Particle.PState.Colliding) { Photons[i].Velocity = new Vector2((((Photons[i].FusionPosition.X - Photons[i].Position.X) / Vector2.Distance(Photons[i].Position, Photons[i].FusionPosition)) * 10), (((Photons[i].FusionPosition.Y - Photons[i].Position.Y) / Vector2.Distance(Photons[i].Position, Photons[i].FusionPosition)) * 10)); Photons[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction); if (Photons[i].Position.X < (Photons[i].FusionPosition.X + 1) && Photons[i].Position.X > (Photons[i].FusionPosition.X - 1) && Photons[i].Position.Y < (Photons[i].FusionPosition.Y + 1) && Photons[i].Position.Y > (Photons[i].FusionPosition.Y - 1)) { for (int j = 0; j < loadedLevel.levelData.i_MaxNumberFused; j++) { if (Fused[j].ParticleState == Particle.PState.Dead) { Fused[j].ParticleState = Particle.PState.Spawning; Photons[i].ParticleState = Particle.PState.Fusing; Fused[j].Position = Photons[i].Position; break; } } } } else if (Photons[i].ParticleState == Particle.PState.Alive) { if (Photons[i].IsTethered) { if (!ship.BoundSphere.Intersects(new BoundingSphere(new Vector3(Photons[i].Position, 0), (Photons[i].Texture.Width / 2)))) { Vector2 distance = ship.Position - Photons[i].Position; Photons[i].Velocity += Vector2.Normalize(distance) * 20; } } else { Photons[i].Position -= new Vector2(0, 0.07f); } Photons[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction); } else if (Photons[i].ParticleState == Particle.PState.Spawning) { if (Photons[i].Scale > 1) { Photons[i].Scale = 1.0f; Photons[i].ParticleState = Particle.PState.Alive; } else { Photons[i].Scale += 0.02f; } } else if (Photons[i].SpawnTimer == loadedLevel.levelData.i_PhotonSpawnRate) { Photons[i] = new Particle(loadedLevel.levelBounds); Photons[i].LoadTex(t_Photon); Photons[i].ParticleState = Particle.PState.Spawning; Photons[i].Spawn(offset, loadedLevel.levelBounds, true); Photons[i].SpawnTimer = 0; soundBank.PlayCue("photonPop"); } } for (int i = 0; i < Chlor.Length; i++) { if (Chlor[i].ParticleState == Particle.PState.Fusing) { if (Chlor[i].i_Fusing > 50) { Chlor[i].ParticleState = Particle.PState.Dead; Chlor[i].i_Fusing = 0; } else { Chlor[i].i_Fusing++; } } else if (Chlor[i].ParticleState == Particle.PState.Colliding) { Chlor[i].Velocity = new Vector2((((Chlor[i].FusionPosition.X - Chlor[i].Position.X) / Vector2.Distance(Chlor[i].Position, Chlor[i].FusionPosition)) * 10), (((Chlor[i].FusionPosition.Y - Chlor[i].Position.Y) / Vector2.Distance(Chlor[i].Position, Chlor[i].FusionPosition)) * 10)); Chlor[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction); if (Chlor[i].Position.X < (Chlor[i].FusionPosition.X + 1) && Chlor[i].Position.X > (Chlor[i].FusionPosition.X - 1) && Chlor[i].Position.Y < (Chlor[i].FusionPosition.Y + 1) && Chlor[i].Position.Y > (Chlor[i].FusionPosition.Y - 1)) { Chlor[i].ParticleState = Particle.PState.Fusing; } } else if (Chlor[i].ParticleState == Particle.PState.Alive) { if (Chlor[i].IsTethered) { if (!ship.BoundSphere.Intersects(new BoundingSphere(new Vector3(Chlor[i].Position, 0), (Chlor[i].Texture.Width / 2)))) { Vector2 distance = ship.Position - Chlor[i].Position; Chlor[i].Velocity += Vector2.Normalize(distance) * 20; } } else { Chlor[i].Position += new Vector2(0, 0.07f); } Chlor[i].updatePosition((float)gameTime.ElapsedGameTime.TotalSeconds, f_Friction); } else if (Chlor[i].ParticleState == Particle.PState.Spawning) { if (Chlor[i].Scale > 1) { Chlor[i].Scale = 1.0f; Chlor[i].ParticleState = Particle.PState.Alive; } else { Chlor[i].Scale += 0.02f; } } else if (Chlor[i].SpawnTimer == loadedLevel.levelData.i_ChloroSpawnRate) { Chlor[i] = new Particle(loadedLevel.levelBounds); Chlor[i].LoadTex(t_Chlor); Chlor[i].ParticleState = Particle.PState.Spawning; Chlor[i].Spawn(offset, loadedLevel.levelBounds, false); Chlor[i].SpawnTimer = 0; soundBank.PlayCue("chlorPop"); } } for (int i = 0; i < loadedLevel.levelData.i_MaxNumberPhotons; i++) { if (Photons[i].ParticleState == Particle.PState.Dead) { Photons[i].SpawnTimer++; break; } } for (int i = 0; i < loadedLevel.levelData.i_MaxNumberChloro; i++) { if (Chlor[i].ParticleState == Particle.PState.Dead) { Chlor[i].SpawnTimer++; break; } } #endregion } GamePlay(gameTime, game); }
public void InitalizeLevel(Level level, Game1 game) { loadedLevel = level; f_Fusions = 0; i_ShieldPulseCounter = 0; i_shipAlpha = 0.5f; i_PulseRate = 60; enemies = new Enemy[loadedLevel.levelData.i_MaxNumberEnemies]; for (int j = 0; j < loadedLevel.levelData.i_MaxNumberEnemies; j++) { enemies[j] = new Enemy(game, loadedLevel); enemies[j].LoadTexture(game.Content); enemies[j].Rectangle = new Rectangle(((int)enemies[j].Position.X - (enemies[j].Texture.Width / 2)), ((int)enemies[j].Position.Y - (enemies[j].Texture.Height / 2)), enemies[j].Texture.Width, enemies[j].Texture.Height); enemies[j].TextureData = new Color[enemies[j].Texture.Width * enemies[j].Texture.Height]; enemies[j].Texture.GetData(enemies[j].TextureData); enemies[j].ShieldSpark = new ShieldSparkParticleSystem(game, 3); game.Components.Add(enemies[j].ShieldSpark); enemies[j].ParticleKill = new ParticleKillParticleSystem(game, 4); game.Components.Add(enemies[j].ParticleKill); } Fused = new Particle[loadedLevel.levelData.i_MaxNumberFused]; for (int j = 0; j < loadedLevel.levelData.i_MaxNumberFused; j++) { Fused[j] = new Particle(loadedLevel.levelBounds); Fused[j].Fusion = new FusionParticleSystem(game, 20); game.Components.Add(Fused[j].Fusion); Fused[j].LoadTex(t_Fused); } Photons = new Particle[loadedLevel.levelData.i_MaxNumberPhotons]; for (int j = 0; j < loadedLevel.levelData.i_MaxNumberPhotons; j++) { Photons[j] = new Particle(loadedLevel.levelBounds); Photons[j].LoadTex(t_Photon); Photons[j].Fusion = new FusionParticleSystem(game, 20); game.Components.Add(Photons[j].Fusion); } Chlor = new Particle[loadedLevel.levelData.i_MaxNumberChloro]; for (int j = 0; j < loadedLevel.levelData.i_MaxNumberChloro; j++) { Chlor[j] = new Particle(loadedLevel.levelBounds); Chlor[j].LoadTex(t_Chlor); Chlor[j].Fusion = new FusionParticleSystem(game, 20); game.Components.Add(Chlor[j].Fusion); } bullets = new Bullet[i_BulletMax]; tethers = new Bullet[i_BulletMax]; for (int j = 0; j < i_BulletMax; j++) { bullets[j] = new Bullet(t_Bullet); tethers[j] = new Bullet(t_Tether); } stupidline = new Bullet[i_StupidLineMax]; for (int j = 0; j < i_StupidLineMax; j++) { stupidline[j] = new Bullet(t_Tether); } ship = new Ship(500, 350, t_Ship); ship.Turret = game.Content.Load<Texture2D>("Ship//turret"); tetherState = TetherState.shooting; offset = ship.OffsetUpdate(offset); engineSmoke = new EngineParticleSystem(game, 9); game.Components.Add(engineSmoke); shipExplosion = new ExplosionParticleSystem(game, 9); game.Components.Add(shipExplosion); }