Exemplo n.º 1
0
        public void handleInput(InputHandler ih, float dt)
        {
            if (rechargeBuffer > 0)
            {
                rechargeBuffer -= dt;
            }
            else
            {
                stamina = Math.Min(200, stamina + (STAMINA_REGEN * dt));
            }
            if (iFrames > 0)
            {
                iFrames -= dt;
            }
            if (redFlash > 0)
            {
                redFlash -= dt;
            }
            if (stun > 0)
            {
                stun -= dt;
            }
            if (dashCooldown > 0)
            {
                dashCooldown -= dt;
            }


            if (falling)
            {
                move(0, 1500 * dt, false);
            }
            if (hp <= 0 || dashTime > 0)
            {
                iFrames = 0.2f;
                update(dt);
                return;
            }
            else if (stun > 0)
            {
                return;
            }

            Vector2 direc = Vector2.Zero;

            // movement
            bool moving = false;

            if (ih.isButtonHeld(gamepad, 'u') || (ih.isKeyHeld(Keys.W) && gamepad == 0))
            {
                direc.Y = -1;
                moving  = true;
                move(0, -MOVE_SPEED * dt);
            }
            else if (ih.isButtonHeld(gamepad, 'd') || (ih.isKeyHeld(Keys.S) && gamepad == 0))
            {
                direc.Y = 1;
                moving  = true;
                move(0, MOVE_SPEED * dt);
            }
            if (ih.isButtonHeld(gamepad, 'l') || (ih.isKeyHeld(Keys.A) && gamepad == 0))
            {
                direc.X = -1;
                moving  = true;
                move(-MOVE_SPEED * dt, 0);
                facingRight = false;
            }
            else if (ih.isButtonHeld(gamepad, 'r') || (ih.isKeyHeld(Keys.D) && gamepad == 0))
            {
                direc.X = 1;
                moving  = true;
                move(MOVE_SPEED * dt, 0);
                facingRight = true;
            }

            if (moving)
            {
                update(dt); // walk cycle
            }

            // powers
            if (ih.isButtonHeld(gamepad, 'b') || (ih.isKeyHeld(Keys.J) && gamepad == 0)) // invisibility
            {
                float staminaLoss = INVIS_STAMINA * dt;
                if (stamina - staminaLoss >= 0)
                {
                    invisTimer += dt;
                    if (invisTimer > 0.6)
                    {
                        invisTimer = 0;
                    }
                    else if (invisTimer < 0.55)
                    {
                        sprite.visible = false;
                    }
                    else
                    {
                        sprite.visible = true;
                    }
                    stamina -= staminaLoss;
                    invis    = true;
                }
                else // forced out due to 0 stamina
                {
                    invis          = false;
                    invisTimer     = 0;
                    sprite.visible = true;
                }
            }
            else // not holding button
            {
                invis          = false;
                sprite.visible = true;
                invisTimer     = 0f;
            }

            if ((ih.isButtonPressed(gamepad, 'a') || (ih.isKeyPressed(Keys.K) && gamepad == 0)) && !invis) // dash
            {
                if (dashCooldown <= 0 && stamina - DASH_STAMINA >= 0 && direc != Vector2.Zero)
                {
                    afterimages   = new List <Vector2>();
                    dashTime      = 0.15f;
                    dashDirection = direc;
                    stamina      -= DASH_STAMINA;
                    Game1.Music.playSfx("dashsfx");
                }
            }
            if (ih.isButtonPressed(gamepad, 'x') || (ih.isKeyPressed(Keys.L) && gamepad == 0))
            {
                if (stamina - MISSILE_STAMINA >= 0)
                {
                    Missile cornMissile = new Missile(cm, this);
                    state.createMissile(cornMissile);
                    stamina -= MISSILE_STAMINA;
                }
            }
        }
Exemplo n.º 2
0
 public void createMissile(Missile m)
 {
     missiles.Add(m);
     Game1.Music.playSfx("firesfx");
 }