Created
March 2, 2025 16:46
-
-
Save lamarmarshall/aa1ed37cc3db814eed31d983df37e6f3 to your computer and use it in GitHub Desktop.
godot, random, swipe, different random
This file contains hidden or 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 Control | |
var pressed_position: Vector2 | |
var release_position: Vector2 | |
func _input(event: InputEvent) -> void: | |
if Input.is_action_just_pressed("click"): | |
pressed_position = event.position | |
if Input.is_action_just_released("click"): | |
release_position = event.position | |
calculate_swipe() | |
func calculate_swipe() -> void: | |
var difference: Vector2 = release_position - pressed_position | |
if abs(difference.x) > abs(difference.y): | |
if difference.x > 0: | |
print("Right") | |
correct_swipe() | |
else: | |
print("Left") | |
correct_swipe() | |
else: | |
if difference.y > 0: | |
print("Down") | |
correct_swipe() | |
else: | |
print("UP") | |
correct_swipe() | |
func correct_swipe() -> void: | |
set_arrow_rotation() | |
func set_arrow_rotation() -> void: | |
var random_arrow_rotation: int = $Arrow.rotation_degrees / 90 | |
var new_rotation: int | |
while true: | |
new_rotation = randi() % 4 | |
if new_rotation != random_arrow_rotation: | |
break | |
$Arrow.rotation_degrees = new_rotation * 90 | |
#var random_arrow_rotation: int = randi() % 4 | |
#$Arrow.rotation_degrees = random_arrow_rotation * 90 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment