protected override void Death() { Game1.Game.PlaySound("sounds/explode4"); for (int i = 0; i < 10; i++) { var ef = new ogpEffect() { blend = Color.White, tname = "textures/rubble", X = X, Y = Y, rotation = (float)(rand.NextDouble() * Math.PI * 2), VelX = rand.Next(-10, 10), VelY = rand.Next(-10, 10), }; ef.OnUpdate += Enemy.Ef_OnUpdate; Game1.Game.manager.Additions.Add(ef); } Game1.Game.manager.Additions.Add(new Powerup() { X = X, Y = Y, depth = -10, VelX = -2, }); }
protected override void Death() { Game1.Game.PlaySound("sounds/explode3"); for (int i = 0; i < 10; i++) { var dust = new ogpEffect() { X = this.X + bOx, Y = this.Y + bOy, tname = "textures/cloud1", VelX = rand.Next(-5, 5), VelY = rand.Next(-5, 5), type = rand.Next(0, 3) - 1, rotation = (float)(rand.NextDouble() * Math.PI * 2), }; dust.scale.X = (float)(0.5 + rand.NextDouble()); dust.scale.Y = (float)(0.5 + rand.NextDouble()); switch (rand.Next(0, 3)) { case 0: dust.blend = Color.Red.WithA(150); break; case 1: dust.blend = Color.Yellow.WithA(150); break; default: dust.blend = Color.Gray.WithA(150); break; } dust.OnUpdate += (a, b) => { var e = a as ogpEffect; e.rotation += e.type / 10f; e.blend.A -= 1; e.VelX -= 0.1f; e.VelY *= 0.96f; if (e.blend.A < 0) { Game1.Game.manager.Removals.Add(e.Id); } }; Game1.Game.manager.Additions.Add(dust); } }
private void Enemy_OnDeath(object sender, EventArgs e) { Player.Current.kills++; // turn it's components into particles var blends = new Color[] { blend, armBlend, wingBlend, bitBlend }; var texts = new Texture2D[] { texture, arms, wings, bits }; var rots = new float[] { rotation, armRotation, wingRotation, bitRotation }; for (int i = 0; i < blends.Length; i++) { var ef = new ogpEffect(X, Y) { blend = blends[i], texture = texts[i], rotation = rots[i], VelX = rand.Next(-10, 10), VelY = rand.Next(-10, 10), }; ef.OnUpdate += Ef_OnUpdate; Game1.Game.manager.Additions.Add(ef); } Game1.Game.manager.Additions.Add(new Powerup() { X = X, Y = Y, type = 0, VelX = -3, }); if (rand.Next(0, 2) == 0) { Game1.Game.PlaySound("sounds/explode1"); } else { Game1.Game.PlaySound("sounds/explode2"); } }
public override void Update() { distTravelled += speed; speed = 5 + kills / 30 + powerups / 10 + (int)Math.Log(distTravelled / 1000 + 1); var ks = Keyboard.GetState(); if (Game1.Game.IsPlaying) { TryShoot = ks.IsKeyDown(Keys.Space); MoveUp = ks.IsKeyDown(Keys.W); MoveDown = ks.IsKeyDown(Keys.S); MoveLeft = ks.IsKeyDown(Keys.A); MoveRight = ks.IsKeyDown(Keys.D); } if (nextHeal > 0) { nextHeal--; } else if (health < healthMax && dollars > 0) { health++; dollars--; nextHeal = HealTime(); } shootCool -= 1; if (ks.IsKeyDown(Keys.L)) { this.health = 0; } if (TryShoot && shootCool <= 0) { shootCool = ShootTime(); if (rand.Next(0, 2) == 0) { Game1.Game.PlaySound("sounds/laser1"); } else { Game1.Game.PlaySound("sounds/laser2"); } Game1.Game.manager.Additions.Add(new Bullet() { X = this.X + bOx, Y = this.Y + bOy, VelX = 15, blend = Color.Yellow, Owner = this, damage = this.damage, }); var dust = new ogpEffect() { X = this.X + bOx, Y = this.Y + bOy, blend = Color.Gray.WithA(150), tname = "textures/cloud1", VelY = -3, type = rand.Next(0, 3) - 1, rotation = (float)(rand.NextDouble() * Math.PI * 2), }; dust.scale.X = (float)(0.2 + rand.NextDouble() / 3); dust.scale.Y = (float)(0.2 + rand.NextDouble() / 3); dust.OnUpdate += (a, b) => { var e = a as ogpEffect; e.rotation += e.type / 10f; e.blend.A -= 1; e.VelX -= 0.1f; e.VelY *= 0.96f; if (e.blend.A < 0 || e.X < -100) { Game1.Game.manager.Removals.Add(e.Id); } }; Game1.Game.manager.Additions.Add(dust); var dakka = new ogpEffect() { X = this.X + bOx, Y = this.Y + bOy, blend = Color.Red.WithA(150), tname = "textures/dakka", depth = -1000, }; if (rand.Next(0, 2) == 0) { dakka.blend = Color.Yellow.WithA(150); } dakka.OnUpdate += (a, b) => { var e = a as Entity; e.blend.A -= 10; if (e.blend.A <= 10) { Game1.Game.manager.Removals.Add(e.Id); } }; Game1.Game.manager.Additions.Add(dakka); var shell = new ogpEffect() { X = this.X + bOx, Y = this.Y + bOy, VelY = -4, blend = Color.Gold.WithA(150), tname = "textures/bullet", depth = -1000, type = rand.Next(0, 3) - 1, }; shell.OnUpdate += (a, b) => { var e = a as ogpEffect; e.VelY += 0.2f; e.VelX -= 0.01f; e.rotation += e.type / 10f; if (e.Y > 700) { Game1.Game.manager.Removals.Add(e.Id); } }; Game1.Game.manager.Additions.Add(shell); } if (MoveUp) { /*if (horKey < keyMax) * horKey += 1 / KeyRate(); * VelY -= (float)Math.Pow(horKey, keyPow) / keyDiv;*/ VelY -= 1; } else if (MoveDown) { /*if (horKey < keyMax) * horKey += 1 / KeyRate(); * VelY += (float)Math.Pow(horKey, keyPow) / keyDiv;*/ VelY += 1; } else { VelY += -VelY / 10; /*horKey = 0; * if (VelY != 0) { * VelY *= VelDamp; * } * if (Math.Abs(VelY) < 0.1) { * VelY = 0; * }*/ } if (MoveLeft) { /*if (verKey < keyMax) * verKey += 1 / KeyRate(); * VelX -= (float)Math.Pow(verKey, keyPow) / keyDiv;*/ VelX -= 1; } else if (MoveRight) { /*if (verKey < keyMax) * verKey += 1 / KeyRate(); * VelX += (float)Math.Pow(verKey, keyPow) / keyDiv;*/ VelX += 1; } else { VelX += -VelX / 10; /*verKey = 0; * if (VelX != 0) { * VelX *= VelDamp; * } * if (Math.Abs(VelX) < 0.1) { * VelX = 0; * }*/ } if (X < 50) { X = 50; VelX = 0.3f; } else if (X > Game1.WIDTH - 50) { X = Game1.WIDTH - 50; VelX = -0.3f; } if (Y < 50) { Y = 50; VelY = 0.3f; } else if (Y > Game1.HEIGHT - 50) { Y = Game1.HEIGHT - 50; VelY = -0.3f; } }