void ItemSpace::setWorkingArea(const QSizeF& area) { if (workingGeom.isValid()) { // if the working area size changed and alignment includes right or bottom, // the difference is added to all positions to keep items in the same place // relative to the borders of alignment if (((spaceAlignment & Qt::AlignRight) || (spaceAlignment & Qt::AlignBottom)) && (area.width() != workingGeom.width() || area.height() != workingGeom.height())) { offsetPositions(QPointF(area.width()-workingGeom.width(), area.height()-workingGeom.height())); } } QSizeF old = workingGeom; workingGeom = area; if (area.width() < old.width() || area.height() < old.height()) { checkBorders(); } if (area.width() > old.width() || area.height() > old.height()) { checkPreferredPositions(); } }
//------------------------------------------------------------------------------ bool Game::update( float dt ) { const Controller & pad( Engine::instance()->getController() ); HGE * hge( Engine::hge() ); ViewPort * vp( Engine::vp() ); if ( Engine::instance()->isPaused() ) { return false; } if ( m_replaying ) { m_timer += dt; if ( m_timer < 0.2f ) { return false; } if ( m_row == 1 ) { if ( m_num == 0 ) { m_replaying = false; } else { --m_num; m_index = m_replay[m_num][0]; m_rotate = m_replay[m_num][1]; m_col = m_replay[m_num][3]; ++m_row; } } else { ++m_row; } } else if ( pad.isConnected() ) { if ( pad.buttonDown( XPAD_BUTTON_BUTTON_Y ) ) { m_replaying = true; m_row = 1; clearArena(); } if ( pad.buttonDown( XPAD_BUTTON_X ) ) { m_index = ( m_index + 6 ) % 7; } if ( pad.buttonDown( XPAD_BUTTON_B ) ) { m_index = ( m_index + 1 ) % 7; } if ( pad.buttonDown( XPAD_BUTTON_LEFT_SHOULDER ) ) { m_rotate = ( m_rotate + 3 ) % 4; } if ( pad.buttonDown( XPAD_BUTTON_RIGHT_SHOULDER ) ) { m_rotate = ( m_rotate + 1 ) % 4; } if ( pad.buttonDown( XPAD_BUTTON_DPAD_UP ) ) { m_row = ( m_row + 22 ) % 23; } if ( pad.buttonDown( XPAD_BUTTON_DPAD_DOWN ) ) { m_row = ( m_row + 1 ) % 23; } if ( pad.buttonDown( XPAD_BUTTON_DPAD_LEFT ) ) { m_col = ( m_col + 12 ) % 13; } if ( pad.buttonDown( XPAD_BUTTON_DPAD_RIGHT ) ) { m_col = ( m_col + 1 ) % 13; } } else { if ( Engine::hge()->Input_KeyDown( HGEK_R ) ) { m_replaying = true; m_row = 1; clearArena(); } if ( Engine::hge()->Input_KeyDown( HGEK_A ) ) { m_index = ( m_index + 6 ) % 7; } if ( Engine::hge()->Input_KeyDown( HGEK_D ) ) { m_index = ( m_index + 1 ) % 7; } if ( Engine::hge()->Input_KeyDown( HGEK_W ) ) { m_rotate = ( m_rotate + 3 ) % 4; } if ( Engine::hge()->Input_KeyDown( HGEK_S ) ) { m_rotate = ( m_rotate + 1 ) % 4; } if ( Engine::hge()->Input_KeyDown( HGEK_UP ) ) { m_row = ( m_row + 22 ) % 23; } if ( Engine::hge()->Input_KeyDown( HGEK_DOWN ) ) { m_row = ( m_row + 1 ) % 23; } if ( Engine::hge()->Input_KeyDown( HGEK_LEFT ) ) { m_col = ( m_col + 12 ) % 13; } if ( Engine::hge()->Input_KeyDown( HGEK_RIGHT ) ) { m_col = ( m_col + 1 ) % 13; } } clearPiece(); for ( int i = 0; i < 8; i += 2 ) { int x( PIECE[m_index][i] ), y( PIECE[m_index][i+1] + 1 ); for ( int j = 0; j < m_rotate; ++j ) { b2Swap( x, y ); y = 3 - y; } m_piece[x][y]= true; } for ( int x = 0; x < 10; ++x ) { for ( int y = 0; y < 20; ++y ) { m_buffer[x][y] = m_arena[x][y]; } } if ( m_replaying ) { if ( m_row == m_replay[m_num][2] ) { m_row = 1; for ( int y = 0; y < 4; ++y ) { for ( int x = 0; x < 4; ++x ) { if ( ! m_piece[x][y] ) { continue; } m_arena[m_col + x - 3][m_row + y - 3] = true; } } } return false; } checkBorders(); // If the piece has space beneath it, then fall down until we either hit the // bottom or there is something below us. while( ! checkBottom() && blankBelow() ) { m_row += 1; } // Add rows, starting at the bottom, to accomodate the piece addRows(); // If the user presses the button, check if the piece has nothing blocking // it above. If it doesn't, remove it. if ( pad.isConnected() ) { if ( pad.buttonDown( XPAD_BUTTON_A ) ) { removePiece(); } } else { if ( Engine::hge()->Input_KeyDown( HGEK_SPACE ) ) { removePiece(); } } return false; }