/// <summary> /// Returns a copy of the current object. /// </summary> public override Enemy Clone() { Smog clone = new Smog(Level, Position); clone.dieSound = dieSound; clone.direction = direction; clone.grayAnimation = grayAnimation; clone.idleAnimation = idleAnimation; clone.killIndex = killIndex; clone.localBounds = localBounds; clone.MaxWaitTime = MaxWaitTime; clone.MoveSpeed = MoveSpeed; clone.runAnimation = runAnimation; clone.sprite = sprite; clone.waitTime = waitTime; clone.curTime = curTime; return clone; }
/// <summary> /// Paces back and forth along a platform, waiting at either end. /// </summary> public override void Update(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; float diffX = Level.Player.Position.X - position.X; float diffY = Level.Player.Position.Y - position.Y; diffX = Math.Abs(diffX); diffY = Math.Abs(diffY); if (diffX < Level.window.Width / 2 && diffY < Level.window.Height) curTime = curTime.Subtract(TimeSpan.FromSeconds(1.0 * elapsed)); if (curTime.CompareTo(TimeSpan.Zero) <= 0) { Vector2 newPosition = Position - Level.camera.Position - sprite.Origin; // Do not draw if out of scope of the window. if (newPosition.X + idleAnimation.FrameWidth >= 0 && newPosition.X <= Level.window.Width && newPosition.Y + idleAnimation.FrameHeight >= 0 && newPosition.Y <= Level.window.Height) { Random r = new Random(); if (r.NextDouble() < .99) { Smog child = new Smog(lev, new Vector2(position.X + (float)(30 * r.NextDouble() - 15), position.Y + (float)(30 * r.NextDouble() - 15))); while (child.handleObjectCollisions()) { child = new Smog(lev, new Vector2(position.X + (float)(30 * r.NextDouble() - 15), position.Y + (float)(30 * r.NextDouble() - 15))); } if (child.position.Y > Level.window.Height * .99) child.position.Y = (Level.window.Height * 0.99f); Level.Enemies.Add(child); } } curTime = ReproductionTime; } if (waitTime > 0) { // Wait for some amount of time. waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds); if (waitTime <= 0.0f) { // Then turn around. direction = (FaceDirection)(-(int)direction); } } else { if (handleObjectCollisions()) { waitTime = MaxWaitTime; } else { // Move in the current direction. Vector2 velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f); position = position + velocity; } } }