예제 #1
0
        /// <summary>
        /// Sets up a new basic enemy
        /// </summary>
        /// <param name="health">health</param>
        /// <param name="damage">damage</param>
        /// <param name="weak">weakness</param>
        /// <param name="g">game</param>
        /// <param name="position">position</param>
        public BasicEnemy(Game g, GameState state, Vector2 position)
        {
            game     = g;
            level    = state;
            Position = position;
            Dead     = false;


            flicker = new InterpolationTimer(TimeSpan.FromSeconds(0.25), 0.0f, 1.0f);
            fade    = new InterpolationTimer(TimeSpan.FromSeconds(2), 1.0f, 0.0f);

            SetUpEnemy(state);
        }
예제 #2
0
        public void Initialize()
        {
            // For testing purposes
            Position      = new Vector2(40, 450); // Start position could change with preference
            Health        = 200;                  // Could also change with preference
            direction     = Direction.Idle;
            verticalState = VerticalMovementState.OnGround;
            Bounds.Width  = FRAME_WIDTH;
            Bounds.Height = FRAME_HEIGHT;

            IsDead = false;
            IsHit  = false;

            flicker  = new InterpolationTimer(TimeSpan.FromSeconds(0.25), 0.0f, 1.0f);
            fade     = new InterpolationTimer(TimeSpan.FromSeconds(2), 1.0f, 0.0f);
            multiple = 1;

            Element = Element.None;
            elementalOrb.Initialize();
        }
예제 #3
0
        public void Update(GameTime gameTime)
        {
            //Movement
            KeyboardState keyboard = Keyboard.GetState();
            float         delta    = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Bounds.X = Position.X;
            Bounds.Y = Position.Y;

            // So the player can't go backwards, would need to change as they
            // progress through the levels
            if (Position.X < 40)
            {
                Position.X = 40;
            }

            // Vertical movement
            switch (verticalState)
            {
            case VerticalMovementState.OnGround:
                if (keyboard.IsKeyDown(Keys.Up))
                {
                    verticalState = VerticalMovementState.Jumping;
                    jumpTimer     = new TimeSpan(0);
                }
                if (keyboard.IsKeyDown(Keys.Up) && oldState.IsKeyUp(Keys.Up))
                {
                    verticalState = VerticalMovementState.DoubleJump;
                    jumpTimer     = new TimeSpan(0);
                }
                break;

            case VerticalMovementState.Jumping:
                jumpTimer += gameTime.ElapsedGameTime;
                // Simple jumping and start fallings right after
                Position.Y -= (600 / (float)jumpTimer.TotalMilliseconds);
                if (jumpTimer.TotalMilliseconds >= JUMP_TIME)
                {
                    verticalState = VerticalMovementState.Falling;
                }
                break;

            case VerticalMovementState.DoubleJump:
                jumpTimer += gameTime.ElapsedGameTime;
                // Simple jumping and start fallings right after
                Position.Y -= (900 / (float)jumpTimer.TotalMilliseconds);
                if (jumpTimer.TotalMilliseconds >= JUMP_TIME)
                {
                    verticalState = VerticalMovementState.Falling;
                }
                break;

            case VerticalMovementState.Falling:
                Position.Y += delta * FALL_SPEED;
                // Come back to the ground
                if (Position.Y > 450)
                {
                    Position.Y    = 450;
                    verticalState = VerticalMovementState.OnGround;
                }
                break;
            }

            if (IsHit)
            {
                // for when the player collides with the enenmy
                Position.X -= 200 * delta;
                direction   = Direction.East;

                if (flicker.TimeElapsed.TotalSeconds >= 0.20)
                {
                    flicker.Stop();
                    flicker  = new InterpolationTimer(TimeSpan.FromSeconds(0.25), 0.0f, 1.0f);
                    IsHit    = false;
                    multiple = 1.0f;
                }
                else
                {
                    if (!flicker.IsRunning)
                    {
                        flicker.Start();
                    }

                    if (flicker.IsRunning)
                    {
                        flicker.Update(gameTime.ElapsedGameTime);
                    }

                    multiple = flicker.CurrentValue;
                }
            }

            if (IsDead)
            {
                if (fade.TimeElapsed.TotalSeconds >= 1.75)
                {
                    fade.Stop();
                    multiple = 0;
                }

                if (!fade.IsRunning && multiple != 0)
                {
                    fade.Start();
                }
                else if (multiple != 0)
                {
                    if (fade.IsRunning)
                    {
                        fade.Update(gameTime.ElapsedGameTime);
                    }

                    multiple = fade.CurrentValue;
                }
            }

            if (keyboard.IsKeyDown(Keys.Left))
            {
                if (verticalState == VerticalMovementState.Jumping || verticalState == VerticalMovementState.Falling)
                {
                    direction = Direction.West;
                }
                else
                {
                    direction = Direction.West;
                }
                Position.X -= delta * PLAYER_SPEED;
            }
            else if (keyboard.IsKeyDown(Keys.Right))
            {
                if (verticalState == VerticalMovementState.Jumping || verticalState == VerticalMovementState.Falling)
                {
                    direction = Direction.East;
                }
                else
                {
                    direction = Direction.East;
                }
                Position.X += delta * PLAYER_SPEED;
            }
            else
            {
                direction = Direction.Idle;
            }

            if (keyboard.IsKeyDown(Keys.K) && !oldState.IsKeyDown(Keys.K))
            {
                UpdateHealth(Health);
            }

            // Elemental Orb Activate and Update
            if (keyboard.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space) && elementalOrb.State == ElementalOrb.ActiveState.Idle)
            {
                Vector2 orbVelocity = new Vector2(1, 0);
                switch (direction)
                {
                case Direction.East:
                    orbVelocity = new Vector2(1, 0);
                    break;

                case Direction.West:
                    orbVelocity = new Vector2(-1, 0);
                    break;

                case Direction.Idle:
                    orbVelocity = new Vector2(1, 0);
                    break;
                }

                elementalOrb.Attack(Position, orbVelocity, Element);
                SetDamage(game.GameState, Element);
            }
            elementalOrb.Update(gameTime);
            if (keyboard.IsKeyDown(Keys.LeftAlt) && !oldState.IsKeyDown(Keys.LeftAlt) && elementalOrb.State == ElementalOrb.ActiveState.Idle)
            {
                CycleElement();
            }
            oldState = keyboard;
        }