GS_Return GS_Controls::Move(float secsPassed, const sf::Input& input) { Gamestate::Move(secsPassed, input); if((GS_FOCUS & GetState()) && input.IsJoystickButtonDown(0, 3)) { return GS_POP; } return GS_NOP; }
bool GS_Game::Move(float secsPassed, const sf::Input& input) { #ifdef _WIN32 XBoxCtrl::GetInstance()->Update(secsPassed); #endif _expManager.Update(secsPassed); SoundManager::GetInstance()->Update(); _timePassed += secsPassed; _fallTimer += secsPassed; if(Collision()) { if(_activeBlock.position.y <= 0) { _next = MB_ENTER_SCORE; return false; } _activeBlock.position.y--; AddToField(); DropNewBlock(); } if(input.IsKeyDown(sf::Key::Escape) || input.IsJoystickButtonDown(0, 3)) { _next = MB_MENU; // _next = MB_ENTER_SCORE; return false; } if(_canDrop && _falling) { if(input.IsKeyDown(sf::Key::Down) || input.IsJoystickButtonDown(0, 0)) { #ifdef _WIN32 XBoxCtrl::GetInstance()->Rumble(10000, 20000, 0.3f); #endif while(!Collision()) _activeBlock.position.y++; _activeBlock.position.y--; if(_activeBlock.position.y <= 0) { _next = MB_ENTER_SCORE; return false; } AddToField(); DropNewBlock(); _fallTimer = 0.0f; _canDrop = false; } } if(!_canDrop) { if(!input.IsKeyDown(sf::Key::Down) && !input.IsJoystickButtonDown(0, 0)) _canDrop = true; } if(_canRotate) { if(input.IsKeyDown(sf::Key::Up) || input.IsJoystickButtonDown(0, 1)) { int current = _activeBlock.index; int next = _activeBlock.index + s_blocks[current].next; int px1, py1, px2, py2; for(int i = 0; i < 4; ++i) { for(int j = 0; j < 4; ++j) { if(BLOCK_PIVOT == s_blocks[current].map[MAPSIZE * i + j]) { px1 = i; py1 = j; } if(BLOCK_PIVOT == s_blocks[next].map[MAPSIZE * i + j]) { px2 = i; py2 = j; } } } _activeBlock.index = next; sf::Vector2<int> pos = _activeBlock.position; int x = _activeBlock.position.x += (px2 - px1); int y = _activeBlock.position.y += (py2 - py1); if(OutOfField() || Collision()) { int i; for(i = 1; i < 4; ++i) { _activeBlock.position.x = x - i; if(!OutOfField()) break; _activeBlock.position.x = x + i; if(!OutOfField()) break; } if(3 <= i || Collision()) { _activeBlock.position = pos; _activeBlock.index = current; } } #ifdef _WIN32 XBoxCtrl::GetInstance()->Rumble(10000, 1000, 0.5f); #endif _zoom->Play(); _canRotate = false; } } if(!_canRotate) { if(!input.IsKeyDown(sf::Key::Up) && !input.IsJoystickButtonDown(0, 1)) _canRotate = true; } if(_receivesInput) { if(_falling) { if(50.0f < input.GetJoystickAxis(0, sf::Joy::AxisY)) { _activeBlock.position.y++; if(Collision()) _activeBlock.position.y--; _fallTimer = 0.0f; _delayInput = 0.0f; _receivesInput = false; } if(-50.0f > input.GetJoystickAxis(0, sf::Joy::AxisY)) { for(int i = 0; i < 2; ++i) { _activeBlock.position.y++; if(Collision()) _activeBlock.position.y--; } _fallTimer = 0.0f; _delayInput = 0.0f; _receivesInput = false; } } if(input.IsKeyDown(sf::Key::Left) || -50.0f > input.GetJoystickAxis(0, sf::Joy::AxisX)) { _activeBlock.position.x--; if(OutOfField() || Collision()) _activeBlock.position.x++; _receivesInput = false; _delayInput = 0.0f; } if(input.IsKeyDown(sf::Key::Right) || 50.0f < input.GetJoystickAxis(0, sf::Joy::AxisX)) { _activeBlock.position.x++; if(OutOfField() || Collision()) _activeBlock.position.x--; _receivesInput = false; _delayInput = 0.0f; } } else { _delayInput += secsPassed; if(0.1f < _delayInput) _receivesInput = true; } if(_falling) { if(_fallTimer > 0.5f) { _activeBlock.position.y++; _fallTimer = 0.0f; } } else { _blendTimer += secsPassed; if(2.0f < _blendTimer) { for(int i = 19; i >= 1; --i) { if(_field[i].remFlag) { for(int j = 0; j < i; ++j) { for(int k = 0; k < 16; ++k) { _field[i - j].stack[k] = _field[i - j - 1].stack[k]; _field[i - j].remFlag = _field[i - j - 1].remFlag; } } ++i; } } _falling = true; } } _fieldFrame.Move(secsPassed); return true; }