GameState FrontendState::Update(float deltaTime) { mCursor.Update(deltaTime); mStartButton.Update(deltaTime); //mStartButton2.Update(deltaTime); //mStartButton3.Update(deltaTime); GameState nextState = GameState::Invalid; if (mStartButton.IsPressed()) { mGameContext.SetLevel(0); nextState = GameState::Gameplay; } //else if (mStartButton2.IsPressed()) //{ // mGameContext.SetLevel(1); // nextState = GameState::Gameplay; //} //else if (mStartButton3.IsPressed()) //{ // mGameContext.SetLevel(2); // nextState = GameState::Gameplay; //} else if (Input_IsKeyPressed(Keys::ESCAPE)) { nextState = GameState::Quit; } return nextState; }
GameState FrontendState::Update(float deltaTime) { mCursor.Update(deltaTime); mStartButton.Update(deltaTime); GameState nextState = GameState::Invalid; if (mStartButton.IsPressed()) { mClick.Play(); mGameContext.SetLevel(0); nextState = GameState::LevelSelect; } else if (Input_IsKeyPressed(Keys::ESCAPE)) { nextState = GameState::Quit; } return nextState; }
bool CharacterCombat::Update(float fSeconds) { // Update sprite mSprite.Update(fSeconds); // Switch to walk state if arrow keys are pressed if (Input_IsKeyDown(Keys::RIGHT) || Input_IsKeyDown(Keys::LEFT) || Input_IsKeyDown(Keys::UP) || Input_IsKeyDown(Keys::DOWN)) { mpOwner->ChangeState(AS_Walk); } // Switch to action state if control is pressed if (Input_IsKeyPressed(Keys::LCONTROL) && !mAnimation.GetIsAnimating()) { //mpOwner->ChangeState(AS_Action); } Graphics_DebugText("Current State: Combat", 0, 150, 0xFFFFFF); return false; }
void Character::Update(float deltaTime, const Map& map) { const float kSpeed = 500.0f; //Check horizontal movement if (Input_IsKeyDown(Keys::RIGHT)) { mVelocity.x = kSpeed * deltaTime; } else if (Input_IsKeyDown(Keys::LEFT)) { mVelocity.x = -kSpeed * deltaTime; } else { mVelocity.x = 0.0f; } // Check collision SRect bb = GetBoundingBox(); SRect newbb = bb + SVector2(mVelocity.x, 0.0f); SRect rightbb = map.GetBoundingBoxFromSegment(newbb.GetRightSegment()); SRect leftbb = map.GetBoundingBoxFromSegment(newbb.GetLeftSegment()); // Right collision if (mVelocity.x > 0.0f && rightbb.IsValid()) { mPosition.x += (int)(rightbb.min.x - bb.max.x) - 1.0f; } // Left collision else if (mVelocity.x < 0.0f && leftbb.IsValid()) { mPosition.x += (int)(leftbb.max.x - bb.min.x) + 1.0f; } else { mPosition.x += (int)mVelocity.x; } //Check vertical movement //if (Input_IsKeyDown(Keys::DOWN)) //{ // mVelocity.y = kSpeed * deltaTime; //} //else if (Input_IsKeyDown(Keys::UP)) //{ // mVelocity.y = -kSpeed * deltaTime; //} //else //{ // mVelocity.y = 0.0f; //} if(!mJumping && Input_IsKeyPressed(Keys::UP)) { mVelocity.y = -30.0f; mJumping = true; } else { mVelocity.y += 100.0f * deltaTime; } mVelocity.y = Min(mVelocity.y, 30.0f); // Check collision newbb = bb + SVector2(0.0f, mVelocity.y); SRect bottombb = map.GetBoundingBoxFromSegment(newbb.GetBottomSegment()); SRect topbb = map.GetBoundingBoxFromSegment(newbb.GetTopSegment()); // Bottom collision if(mVelocity.y > 0.0f && bottombb.IsValid()) { mPosition.y += (int)(bottombb.min.y - bb.max.y) - 1.0f; mVelocity.y = 0.0f; mJumping = false; } // Top collision else if(mVelocity.y < 0.0f && topbb.IsValid()) { mPosition.y += (int)(topbb.max.y - bb.min.y) + 1.0f; mVelocity.y = 0.0f; } else { mPosition.y += (int)mVelocity.y; } }
void InputBox::Update(float deltaTime) { mSprite.Update(deltaTime); // Update caret info mCaret += deltaTime; if (mCaret > CARET_BLINK_RATE_SECONDS) { mCaret -= CARET_BLINK_RATE_SECONDS; } SVector2 mouse((float) Input_GetMouseScreenX(), (float) Input_GetMouseScreenY()); // If a mouse click is detected this box is no longer selected. Below it checks if it is the one being clicked on if(Input_IsMousePressed(Mouse::LBUTTON)) { mActive = mouse.x > (mPosition.x - 25) && mouse.x < mPosition.x + mWidth && mouse.y > (mPosition.y - 25) && mouse.y < mPosition.y + mHeight; } // If Active Capture Text if(mActive) { // Dont go over max length if(mTextPosition < mMaxLength) { if (Input_IsKeyDown(Keys::LSHIFT) || Input_IsKeyDown(Keys::RSHIFT) ) { if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'A'; } if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'B'; } if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'C'; } if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'D'; } if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'E'; } if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'F'; } if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'G'; } if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'H'; } if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'I'; } if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'J'; } if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'K'; } if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'L'; } if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'M'; } if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'N'; } if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'O'; } if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'P'; } if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'Q'; } if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'R'; } if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 'S'; } if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 'T'; } if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'U'; } if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'V'; } if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'W'; } if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'X'; } if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'Y'; } if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'Z'; } if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ':'; } if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '!'; } if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '@'; } if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '#'; } if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '$'; } if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '%'; } if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '^'; } if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '&'; } if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '*'; } if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '('; } if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = ')'; } if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '?'; } if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '>'; } if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = '<'; } if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '"'; } if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '~'; } if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '{'; } if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = '}'; } } else { if(Input_IsKeyPressed(Keys::A)) { mText[mTextPosition++] = 'a'; } if(Input_IsKeyPressed(Keys::B)) { mText[mTextPosition++] = 'b'; } if(Input_IsKeyPressed(Keys::C)) { mText[mTextPosition++] = 'c'; } if(Input_IsKeyPressed(Keys::D)) { mText[mTextPosition++] = 'd'; } if(Input_IsKeyPressed(Keys::E)) { mText[mTextPosition++] = 'e'; } if(Input_IsKeyPressed(Keys::F)) { mText[mTextPosition++] = 'f'; } if(Input_IsKeyPressed(Keys::G)) { mText[mTextPosition++] = 'g'; } if(Input_IsKeyPressed(Keys::H)) { mText[mTextPosition++] = 'h'; } if(Input_IsKeyPressed(Keys::I)) { mText[mTextPosition++] = 'i'; } if(Input_IsKeyPressed(Keys::J)) { mText[mTextPosition++] = 'j'; } if(Input_IsKeyPressed(Keys::K)) { mText[mTextPosition++] = 'k'; } if(Input_IsKeyPressed(Keys::L)) { mText[mTextPosition++] = 'l'; } if(Input_IsKeyPressed(Keys::M)) { mText[mTextPosition++] = 'm'; } if(Input_IsKeyPressed(Keys::N)) { mText[mTextPosition++] = 'n'; } if(Input_IsKeyPressed(Keys::O)) { mText[mTextPosition++] = 'o'; } if(Input_IsKeyPressed(Keys::P)) { mText[mTextPosition++] = 'p'; } if(Input_IsKeyPressed(Keys::Q)) { mText[mTextPosition++] = 'q'; } if(Input_IsKeyPressed(Keys::R)) { mText[mTextPosition++] = 'r'; } if(Input_IsKeyPressed(Keys::S)) { mText[mTextPosition++] = 's'; } if(Input_IsKeyPressed(Keys::T)) { mText[mTextPosition++] = 't'; } if(Input_IsKeyPressed(Keys::U)) { mText[mTextPosition++] = 'u'; } if(Input_IsKeyPressed(Keys::V)) { mText[mTextPosition++] = 'v'; } if(Input_IsKeyPressed(Keys::W)) { mText[mTextPosition++] = 'w'; } if(Input_IsKeyPressed(Keys::X)) { mText[mTextPosition++] = 'x'; } if(Input_IsKeyPressed(Keys::Y)) { mText[mTextPosition++] = 'y'; } if(Input_IsKeyPressed(Keys::Z)) { mText[mTextPosition++] = 'z'; } if(Input_IsKeyPressed(Keys::ZERO)) { mText[mTextPosition++] = '0'; } if(Input_IsKeyPressed(Keys::ONE)) { mText[mTextPosition++] = '1'; } if(Input_IsKeyPressed(Keys::TWO)) { mText[mTextPosition++] = '2'; } if(Input_IsKeyPressed(Keys::THREE)) { mText[mTextPosition++] = '3'; } if(Input_IsKeyPressed(Keys::FOUR)) { mText[mTextPosition++] = '4'; } if(Input_IsKeyPressed(Keys::FIVE)) { mText[mTextPosition++] = '5'; } if(Input_IsKeyPressed(Keys::SIX)) { mText[mTextPosition++] = '6'; } if(Input_IsKeyPressed(Keys::SEVEN)) { mText[mTextPosition++] = '7'; } if(Input_IsKeyPressed(Keys::EIGHT)) { mText[mTextPosition++] = '8'; } if(Input_IsKeyPressed(Keys::NINE)) { mText[mTextPosition++] = '9'; } if(Input_IsKeyPressed(Keys::SLASH)) { mText[mTextPosition++] = '/'; } if(Input_IsKeyPressed(Keys::PERIOD)) { mText[mTextPosition++] = '.'; } if(Input_IsKeyPressed(Keys::APOSTROPHE)) { mText[mTextPosition++] = '\''; } if(Input_IsKeyPressed(Keys::COMMA)) { mText[mTextPosition++] = ','; } if(Input_IsKeyPressed(Keys::MINUS)) { mText[mTextPosition++] = '-'; } if(Input_IsKeyPressed(Keys::EQUALS)) { mText[mTextPosition++] = '='; } if(Input_IsKeyPressed(Keys::SEMICOLON)) { mText[mTextPosition++] = ';'; } if(Input_IsKeyPressed(Keys::GRAVE)) { mText[mTextPosition++] = '`'; } if(Input_IsKeyPressed(Keys::LBRACKET)) { mText[mTextPosition++] = '['; } if(Input_IsKeyPressed(Keys::RBRACKET)) { mText[mTextPosition++] = ']'; } } if(Input_IsKeyPressed(Keys::SPACE)) { mText[mTextPosition++] = ' '; } } // Backspace if(mTextPosition > 0 && Input_IsKeyPressed(Keys::BACKSPACE)) { mText[--mTextPosition] = '\0'; } } }