Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rotate #2

Open
finalbytes opened this issue May 23, 2020 · 2 comments
Open

rotate #2

finalbytes opened this issue May 23, 2020 · 2 comments

Comments

@finalbytes
Copy link

Hi Ania,

i love your projects, really simple, elegant, and created with ease... :-) well done!

But i found a issue in the rotate function, i a iTetromino is dropping, i move him againt the right side, and i want to rotate the block. I'll see 2 blocks on the right side and 2 blocks on the left side, 1 line below them. I think they need an extra validation if we can rotate this shape, or you need to shift the shape 2 squares to the left. I think the same is happening on the left side. Probably other shapes will have the same issue.

@mavima
Copy link

mavima commented Jun 4, 2021

Thanks a lot for the nice project Ania, it was a pleasure to practice with it!

I solved the rotation issue with adding "nextRotation" to the function and checking that it doesn't touch both first and last square of the lines:

function rotate() {
// check if there is room also after the rotate
let nextCurrent = []
if (currentRotation <= 2) {
nextCurrent = tetrominoes[random][currentRotation + 1]
} else {
nextCurrent = tetrominoes[random][0]
}
let Edge = nextCurrent.some(index => (currentPosition + index) % width === width - 1) && nextCurrent.some(index => (currentPosition + index) % width === 0)

if(!Edge) {
undraw()
currentRotation ++
if (currentRotation === current.length) {
currentRotation = 0
}
current = tetrominoes[random][currentRotation]
draw()
}
}

@loulou1994
Copy link

Great! This actually fixes the issue better than what's proposed in the pull request section. Thanks @mavima !.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants