Prevent buggy rotations
This commit is contained in:
parent
d87e5c534f
commit
2dacf54608
11
GameBoard.gd
11
GameBoard.gd
@ -67,7 +67,9 @@ func get_random_shape():
|
|||||||
|
|
||||||
|
|
||||||
func update_board():
|
func update_board():
|
||||||
if player_lost():
|
# The player lost if the active shape is within another shape, since that means that they're
|
||||||
|
# piling up on top
|
||||||
|
if is_shape_stuck():
|
||||||
game_over()
|
game_over()
|
||||||
|
|
||||||
if can_active_move_down():
|
if can_active_move_down():
|
||||||
@ -100,8 +102,7 @@ func can_active_move_right():
|
|||||||
return _can_active_move_towards(Vector2(RASTER_SIZE, 0.0))
|
return _can_active_move_towards(Vector2(RASTER_SIZE, 0.0))
|
||||||
|
|
||||||
|
|
||||||
func player_lost():
|
func is_shape_stuck():
|
||||||
# The player lost if the active shape is within another shape, so it "cannot move towards itself"
|
|
||||||
return not _can_active_move_towards(Vector2.ZERO)
|
return not _can_active_move_towards(Vector2.ZERO)
|
||||||
|
|
||||||
|
|
||||||
@ -189,6 +190,10 @@ func move_right():
|
|||||||
func rotate_shape():
|
func rotate_shape():
|
||||||
active_shape.rotation_degrees += 90
|
active_shape.rotation_degrees += 90
|
||||||
|
|
||||||
|
# Revert the rotation if that would cause it to be stuck inside another
|
||||||
|
if is_shape_stuck():
|
||||||
|
active_shape.rotation_degrees -= 90
|
||||||
|
|
||||||
|
|
||||||
func drop():
|
func drop():
|
||||||
while can_active_move_down():
|
while can_active_move_down():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user