fix rotation
This commit is contained in:
parent
7d5062afab
commit
f7bf91f085
|
|
@ -174,9 +174,7 @@ export function update(_delta: number, input: InputState) {
|
|||
const keys = input.pressed
|
||||
|
||||
if (input.justPressed.has(" ")) {
|
||||
player.rotation += 1
|
||||
if (player.rotation === SHAPES[player.shape]!.length)
|
||||
player.rotation = 0
|
||||
rotateShape()
|
||||
}
|
||||
|
||||
// tetris animation
|
||||
|
|
@ -455,4 +453,26 @@ function drawPreview(game: GameContext) {
|
|||
drawBlock(game, previewX + col + offsetX, previewY + row + offsetY, COLORS[nextShape.shape]!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rotateShape() {
|
||||
const oldRot = player.rotation
|
||||
const newRot = (oldRot + 1) % SHAPES[player.shape]!.length
|
||||
|
||||
if (!collision(player.x, player.y, newRot)) {
|
||||
player.rotation = newRot
|
||||
return
|
||||
}
|
||||
|
||||
if (!collision(player.x + 1, player.y, newRot)) {
|
||||
player.x += 1
|
||||
player.rotation = newRot
|
||||
return
|
||||
}
|
||||
|
||||
if (!collision(player.x - 1, player.y, newRot)) {
|
||||
player.x -= 1
|
||||
player.rotation = newRot
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user