//------------------------------------------------------------ //updates Mario's movement info when a button is pushed void Mario::updateKeyDown(unsigned char button) { if (button == 'a') { leftKey_ = true; //set Mario's Velocity if (sprintKey_ == true) { this->setXVelocity(-2.0); } else { this->setXVelocity(-1.0); } } if (button == 'd') { rightKey_ = true; //set Mario's velocity if (sprintKey_ == true) { this->setXVelocity(2.0); } else { this->setXVelocity(1.0); } } if (button == 'w') { jumpKey_ = true; if (jumpCount_ == 0 && this->getYVelocity() == 0.0) { jumpCount_ = 50; //set Mario's velocity this->setYVelocity(2.0); } } if (button == 'j') { sprintKey_ = true; if (this->state_ == FIRE_STATE) { MarioFireball *fb = new MarioFireball; fb->setTop(this->top()); fb->setLeft(this->right()); fb->setBottom(this->top() - 10); fb->setRight(this->right() + 10); fb->setXVelocity(1.0); fb->setYVelocity(0.0); Level::sharedLevel()->addMovable(fb); } } }
//------------------------------------------------------------ //updates Mario's movement info when a button is pushed void Mario::updateKeyDown(unsigned char button) { // if the key to move left is pushed // set Mario's direction and X velocity // to move left if (button == 'a') { leftKey_ = true; direction_ = 0; //set Mario's Velocity if (sprintKey_ == true) { this->setXVelocity(-2.0); } else { this->setXVelocity(-1.0); } } // if the key to move right is pushed // set Mario's direction and X velocity // to move right if (button == 'd') { rightKey_ = true; direction_ = 1; //set Mario's velocity if (sprintKey_ == true) { this->setXVelocity(2.0); } else { this->setXVelocity(1.0); } } // if the jump key is pushed and Mario // is not already jumping, set jump count // and Mario's Y velocity if (button == 'w') { jumpKey_ = true; if (jumpCount_ == 0 && this->getYVelocity() == 0.0) { jumpCount_ = 50; //set Mario's velocity this->setYVelocity(2.0); } } // if the sprint/fireball key is pushed, // and if Mario is in FIRE_STATE, create // a MarioFireball and set coordinates // and velocity if (button == 'j') { sprintKey_ = true; if (this->state_ == FIRE_STATE) { MarioFireball *fb = new MarioFireball; fb->setTop(this->top()); fb->setBottom(this->top() - 8); if (this->direction_ == 0) { fb->setLeft(this->left()); fb->setRight(this->left() - 8); } else { fb->setLeft(this->right()); fb->setRight(this->right() + 8); } if (direction_ == 1) { fb->setXVelocity(1.0); } else { fb->setXVelocity(-1.0); } fb->setYVelocity(-0.5); Level::sharedLevel()->addMovable(fb); } } }