fix lock bug
This commit is contained in:
		| @ -46,7 +46,7 @@ func new_piece(): | |||||||
| 	current_piece.turn_light(true) | 	current_piece.turn_light(true) | ||||||
| 	next_piece = random_piece() | 	next_piece = random_piece() | ||||||
| 	next_piece.translation = $Next/Position3D.translation | 	next_piece.translation = $Next/Position3D.translation | ||||||
| 	if current_piece.move(THERE): | 	if $Matrix/GridMap.possible_positions(current_piece.get_translations(), THERE): | ||||||
| 		$DropTimer.start() | 		$DropTimer.start() | ||||||
| 		current_piece_held = false | 		current_piece_held = false | ||||||
| 	else: | 	else: | ||||||
| @ -138,7 +138,7 @@ func _on_DropTimer_timeout(): | |||||||
| 	current_piece.move(movements["soft_drop"]) | 	current_piece.move(movements["soft_drop"]) | ||||||
| 	 | 	 | ||||||
| func _on_LockDelay_timeout(): | func _on_LockDelay_timeout(): | ||||||
| 	if not current_piece.move(movements["soft_drop"]): | 	if not $Matrix/GridMap.possible_positions(current_piece.get_translations(), movements["soft_drop"]): | ||||||
| 		lock() | 		lock() | ||||||
|  |  | ||||||
| func lock(): | func lock(): | ||||||
| @ -160,6 +160,8 @@ func hold(): | |||||||
| 		current_piece = held_piece | 		current_piece = held_piece | ||||||
| 		held_piece = swap | 		held_piece = swap | ||||||
| 		held_piece.turn_light(false) | 		held_piece.turn_light(false) | ||||||
|  | 		for mino in held_piece.minoes: | ||||||
|  | 			mino.get_node("LockingMesh").visible = false | ||||||
| 		held_piece.translation = $Hold/Position3D.translation | 		held_piece.translation = $Hold/Position3D.translation | ||||||
| 		if current_piece: | 		if current_piece: | ||||||
| 			current_piece.translation = $Matrix/Position3D.translation | 			current_piece.translation = $Matrix/Position3D.translation | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ | |||||||
| [ext_resource path="res://controls.tscn" type="PackedScene" id=11] | [ext_resource path="res://controls.tscn" type="PackedScene" id=11] | ||||||
| [ext_resource path="res://Start.tscn" type="PackedScene" id=12] | [ext_resource path="res://Start.tscn" type="PackedScene" id=12] | ||||||
| [ext_resource path="res://fonts/Gamer.ttf" type="DynamicFontData" id=13] | [ext_resource path="res://fonts/Gamer.ttf" type="DynamicFontData" id=13] | ||||||
| [ext_resource path="res://Tetrominos/drop_trail.png" type="Texture" id=14] | [ext_resource path="res://Tetrominos/Mino/drop_trail.png" type="Texture" id=14] | ||||||
|  |  | ||||||
| [sub_resource type="SpatialMaterial" id=1] | [sub_resource type="SpatialMaterial" id=1] | ||||||
|  |  | ||||||
|  | |||||||
| Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB | 
| @ -99,14 +99,12 @@ func move(movement): | |||||||
| 	if grid_map.possible_positions(get_translations(), movement): | 	if grid_map.possible_positions(get_translations(), movement): | ||||||
| 		translate(movement) | 		translate(movement) | ||||||
| 		if movement == DROP_MOVEMENT: | 		if movement == DROP_MOVEMENT: | ||||||
| 			locking(false) | 			unlocking() | ||||||
| 			lock_delay.stop() |  | ||||||
| 		rotated_last = false | 		rotated_last = false | ||||||
| 		return true | 		return true | ||||||
| 	else: | 	else: | ||||||
| 		if movement == DROP_MOVEMENT: | 		if movement == DROP_MOVEMENT: | ||||||
| 			locking(true) | 			locking() | ||||||
| 			lock_delay.start() |  | ||||||
| 		return false | 		return false | ||||||
| 	 | 	 | ||||||
| func turn(direction): | func turn(direction): | ||||||
| @ -124,8 +122,7 @@ func turn(direction): | |||||||
| 			orientation = (orientation - direction) % NB_MINOES | 			orientation = (orientation - direction) % NB_MINOES | ||||||
| 			set_translations(rotated_translations) | 			set_translations(rotated_translations) | ||||||
| 			translate(movements[i]) | 			translate(movements[i]) | ||||||
| 			lock_delay.stop() | 			unlocking() | ||||||
| 			locking(false) |  | ||||||
| 			rotated_last = true | 			rotated_last = true | ||||||
| 			if i == 4: | 			if i == 4: | ||||||
| 				rotation_point_5_used = true | 				rotation_point_5_used = true | ||||||
| @ -139,6 +136,12 @@ func turn_light(on): | |||||||
| 	for mino in minoes: | 	for mino in minoes: | ||||||
| 		mino.get_node("SpotLight").visible = on | 		mino.get_node("SpotLight").visible = on | ||||||
| 		 | 		 | ||||||
| func locking(visible): | func locking(): | ||||||
|  | 	if lock_delay.is_stopped(): | ||||||
|  | 		lock_delay.start() | ||||||
| 	for mino in minoes: | 	for mino in minoes: | ||||||
| 		mino.get_node("LockingMesh").visible = visible | 		mino.get_node("LockingMesh").visible = true | ||||||
|  |  | ||||||
|  | func unlocking(): | ||||||
|  | 	if not lock_delay.is_stopped(): | ||||||
|  | 		lock_delay.start() | ||||||
		Reference in New Issue
	
	Block a user