コード例 #1
0
ファイル: Malaria.cs プロジェクト: frank44/pewpew
        /// <summary>
        /// Returns a copy of the current object.
        /// </summary>
        public override Enemy Clone()
        {
            Malaria clone = new Malaria(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;
        }
コード例 #2
0
ファイル: Malaria.cs プロジェクト: frank44/pewpew
        /// <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;
            diffX = Math.Abs(diffX);

            if (diffX < Level.window.Width / 2)
                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)
                    {
                        Malaria child = new Malaria(lev,
                        new Vector2(position.X + (float)(30 * r.NextDouble() - 15),
                            position.Y + (float)(30 * r.NextDouble() - 15)));

                        child = new Malaria(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;
                }
            }
        }