public override void HandleCollisions(CollisionBody collider, CollisionType colliderType) { if (collider is Projectile) { Projectile collidingProjectile = collider as Projectile; health -= 1; if (health <= 0) { DropPowerUp(1, new Vector2(Width / 2f, Height / 2f)); SpawnGore(Main.random.Next(6, 7 + 1), Width, Height, 1); GenerateSmoke(Color.Orange, Color.Gray, Width, Height, 16); if (laser != null) { laser.DestroyInstance(laser); laser = null; } DestroyInstance(this); } Explosion.NewExplosion(collidingProjectile.position, Vector2.Zero); collidingProjectile.DestroyInstance(collidingProjectile); } if (collider is Asteroid) { Asteroid collidingAsteroid = collider as Asteroid; collidingAsteroid.health -= 2; Explosion.NewExplosion(collidingAsteroid.position, Vector2.Zero); DropPowerUp(1, new Vector2(Width / 2f, Height / 2f)); SpawnGore(Main.random.Next(6, 7 + 1), Width, Height, 1); GenerateSmoke(Color.Orange, Color.Gray, Width, Height, 16); if (laser != null) { laser.DestroyInstance(laser); laser = null; } DestroyInstance(this); } }
public override void Update() { AnimateShip(); CollisionBody[] bodiesArray = Main.activeProjectiles.ToArray(); DetectCollisions(bodiesArray.ToList()); Vector2 velocity = Vector2.Zero; if (position.Y < 40f) { velocity.Y = 0.3f; } else { if (position.X + Width > Main.desiredResolutionWidth) { direction = -1; } if (position.X <= 1) { direction = 1; } velocity.X = 0.4f * direction; if (shootingLaser) { velocity *= 0.5f; } } position += velocity; hitbox.X = (int)position.X; hitbox.Y = (int)position.Y; center = position + new Vector2(Width / 2f, Height / 2f); if (!shootingLaser) { laserChargeUpTimer++; if (laserChargeUpTimer >= 4 * 60) { shootingLaser = true; laser = ContinuousLaser.NewLaser(position, true, Color.White); } } else { laserDurationTimer++; if (laserDurationTimer >= 5 * 60) { frame = 0; shootingLaser = false; laserDurationTimer = 0; laserChargeUpTimer = 0; laser.DestroyInstance(laser); laser = null; } if (laser != null) { laser.position = position + shootOffset; } } }