add android export with swipe gestures

This commit is contained in:
Fabien Freling 2020-01-03 14:22:50 +01:00
parent 84d6354f35
commit df97221788
5 changed files with 239 additions and 0 deletions

20
game/src/MainMobile.tscn Normal file
View file

@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/Main.gd" type="Script" id=1]
[ext_resource path="res://src/Taquin.tscn" type="PackedScene" id=2]
[node name="Main" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="Taquin" parent="." instance=ExtResource( 2 )]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -270.0
margin_top = -280.0
margin_right = 270.0
margin_bottom = 280.0
[connection signal="solved" from="Taquin" to="." method="_on_Taquin_solved"]

View file

@ -21,6 +21,8 @@ var rng = RandomNumberGenerator.new()
var current_animation_path: String = "AnimationPlayer/MockPiece:position"
var swipe = Vector2(0, 0)
func position_for_index(index: Vector2, size: int) -> Vector2:
return Vector2(padding + index.x * (size + interpiece), padding + index.y * (size + interpiece))
@ -76,6 +78,20 @@ func _input(event):
if event.is_action_pressed("ui_right"):
move_piece(Direction.LEFT)
if event is InputEventScreenDrag:
swipe = event.relative
if event is InputEventScreenTouch:
if not event.pressed: # Touch released
var angle = swipe.angle()
if angle < PI / 4 and angle >= - PI / 4:
move_piece(Direction.LEFT)
if angle >= PI / 4 and angle < PI - PI / 4:
move_piece(Direction.UP)
if angle >= - PI + PI / 4 and angle < - PI / 4:
move_piece(Direction.DOWN)
if angle >= PI - PI / 4 or angle < -PI + PI / 4:
move_piece(Direction.RIGHT)
enum Direction { UP, DOWN, LEFT, RIGHT }
func move_piece(direction) -> bool: