Created
September 28, 2021 02:47
-
-
Save DeerTears/bc11abd3e93e8154e8ee274a467b968b to your computer and use it in GitHub Desktop.
something witness-y but not really
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Area | |
# Has a bunch of collisionshape children to check different squares against. | |
# Not the most optimized system since it's multiple objects vs contained in one plane. | |
# Z clipping in picking is also an issue | |
class_name PuzzlePanel | |
const HALF_PI := 1.570796 | |
enum DIRECTIONS { | |
UP, | |
RIGHT, | |
DOWN, | |
LEFT | |
} | |
var tile_grid := {} | |
var _current_moving_tiles := {} | |
onready var tween: Tween = $Tween | |
func _ready() -> void: | |
connect("input_event", self, "_on_input_event") | |
tween.connect("tween_completed", self, "_on_tween_completed") | |
func _on_input_event(_camera: Node, event: InputEvent, _click_position: Vector3, _click_normal: Vector3, shape_idx: int) -> void: | |
if event is InputEventMouseButton: | |
if event.pressed: | |
var tile: CollisionShape = get_child(shape_idx) | |
if tile.name in _current_moving_tiles.keys(): | |
return | |
rotate_tile(tile, "left" if event.button_index == 1 else "right") | |
func rotate_tile(tile: Node, direction: String) -> void: | |
var rotation_amount: Vector3 = Vector3.BACK * (PI if direction == "left" else -PI) | |
rotation_amount.z = stepify(rotation_amount.z, HALF_PI) | |
_current_moving_tiles[tile.name] = tween.interpolate_property( | |
tile, "rotation", | |
tile.rotation, tile.rotation + rotation_amount, | |
0.5, Tween.TRANS_BACK, Tween.EASE_OUT | |
) | |
tween.start() | |
print_debug(_current_moving_tiles) | |
func _on_tween_completed(object: Object, _key: NodePath) -> void: | |
_current_moving_tiles.erase(object.name) | |
print_debug(_current_moving_tiles) | |
func interact() -> void: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment