| 119 | } |
| 120 | |
| 121 | void Playing::editBlockInput() |
| 122 | { |
| 123 | constexpr static float delay = 0.15f; |
| 124 | static sf::Clock timer; |
| 125 | |
| 126 | Ray raycast (m_player.rotation.y + 90, |
| 127 | m_player.rotation.x, |
| 128 | m_player.position); |
| 129 | |
| 130 | Vector3 lastPosition; |
| 131 | |
| 132 | m_hitInfo.isHit = false; |
| 133 | |
| 134 | for(;raycast.getLength() < 6 * BLOCK_SIZE; raycast.step(0.1)) |
| 135 | { |
| 136 | if (raycast.getEndPoint().x < 0 || |
| 137 | raycast.getEndPoint().z < 0 || |
| 138 | raycast.getEndPoint().y < 1 ) return; |
| 139 | |
| 140 | auto block = m_world.getBlock(raycast.getEndPoint()); |
| 141 | |
| 142 | if (!(block == Block::ID::Air || |
| 143 | block == Block::ID::Water)) |
| 144 | { |
| 145 | m_hitInfo.isHit = true; |
| 146 | m_hitInfo.location = {(int)raycast.getEndPoint().x, |
| 147 | (int)raycast.getEndPoint().y, |
| 148 | (int)raycast.getEndPoint().z}; |
| 149 | |
| 150 | |
| 151 | |
| 152 | if (timer.getElapsedTime().asSeconds() > delay) |
| 153 | { |
| 154 | if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) |
| 155 | { |
| 156 | timer.restart(); |
| 157 | m_world.setBlock(raycast.getEndPoint(), Block::ID::Air); |
| 158 | break; |
| 159 | } |
| 160 | else if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) |
| 161 | { |
| 162 | timer.restart(); |
| 163 | m_world.setBlock(lastPosition, Block::ID::Stone); |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | break; |
| 168 | } |
| 169 | lastPosition = raycast.getEndPoint(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | |
| 174 | Vector3 Playing::getCenterPosition() |