Added putting cards in hand/play
This commit is contained in:
parent
c2318a92d1
commit
7c56dc1088
7 changed files with 134 additions and 24 deletions
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
[ext_resource path="res://Scenes/Scripts/Board.gd" type="Script" id=1]
|
[ext_resource path="res://Scenes/Scripts/Board.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Scenes/Scripts/Camera.gd" type="Script" id=2]
|
[ext_resource path="res://Scenes/Scripts/Camera.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://MLPAssets/Background/boardbg.jpg" type="Texture" id=3]
|
[ext_resource path="res://Scenes/Components/Card.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://Scenes/BoardUI.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://MLPAssets/Background/boardbg.jpg" type="Texture" id=4]
|
||||||
[ext_resource path="res://Scenes/Components/Card.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://Scenes/BoardUI.tscn" type="PackedScene" id=5]
|
||||||
|
|
||||||
[sub_resource type="SpatialMaterial" id=1]
|
[sub_resource type="SpatialMaterial" id=1]
|
||||||
flags_unshaded = true
|
flags_unshaded = true
|
||||||
albedo_texture = ExtResource( 3 )
|
albedo_texture = ExtResource( 4 )
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id=2]
|
[sub_resource type="PlaneMesh" id=2]
|
||||||
material = SubResource( 1 )
|
material = SubResource( 1 )
|
||||||
|
@ -21,15 +21,28 @@ script = ExtResource( 1 )
|
||||||
transform = Transform( 1, 0, 0, 0, 0.367808, 0.929902, 0, -0.929902, 0.367808, -0.232958, 4.94606, 3.11883 )
|
transform = Transform( 1, 0, 0, 0, 0.367808, 0.929902, 0, -0.929902, 0.367808, -0.232958, 4.94606, 3.11883 )
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Hand" type="Spatial" parent="Camera"]
|
||||||
|
transform = Transform( 0.4, 0, 0, 0, 0, -0.4, 0, 0.4, 0, 0, -0.552465, -0.87444 )
|
||||||
|
|
||||||
|
[node name="Card4" parent="Camera/Hand" instance=ExtResource( 3 )]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, -2.98023e-008, 0, 2.98023e-008, 1, 0, 0, 0 )
|
||||||
|
inHand = true
|
||||||
|
|
||||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.001, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.001, 0 )
|
||||||
mesh = SubResource( 2 )
|
mesh = SubResource( 2 )
|
||||||
material/0 = null
|
material/0 = null
|
||||||
|
|
||||||
[node name="BoardUI" parent="." instance=ExtResource( 4 )]
|
[node name="BoardUI" parent="." instance=ExtResource( 5 )]
|
||||||
|
|
||||||
[node name="Card" parent="." instance=ExtResource( 5 )]
|
[node name="Cards" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
[node name="Card" parent="Cards" instance=ExtResource( 3 )]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.55435, -0.001, 1.13711 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.55435, -0.001, 1.13711 )
|
||||||
[connection signal="card_selected" from="Card" to="BoardUI" method="_card_selected" binds= [ "ff6" ]]
|
[connection signal="card_dropped" from="Camera/Hand/Card4" to="." method="_card_dropped"]
|
||||||
[connection signal="card_unselected" from="Card" to="BoardUI" method="_card_unselected"]
|
[connection signal="card_picked" from="Camera/Hand/Card4" to="." method="_card_picked"]
|
||||||
[connection signal="mouse_exited" from="Card" to="." method="_mouse_blur"]
|
[connection signal="card_selected" from="Camera/Hand/Card4" to="BoardUI" method="_card_selected" binds= [ "ff6" ]]
|
||||||
|
[connection signal="card_unselected" from="Camera/Hand/Card4" to="BoardUI" method="_card_unselected"]
|
||||||
|
[connection signal="card_selected" from="Cards/Card" to="BoardUI" method="_card_selected" binds= [ "ff6" ]]
|
||||||
|
[connection signal="card_unselected" from="Cards/Card" to="BoardUI" method="_card_unselected"]
|
||||||
|
[connection signal="mouse_exited" from="Cards/Card" to="." method="_mouse_blur"]
|
||||||
|
|
|
@ -57,6 +57,7 @@ margin_left = 40.0
|
||||||
margin_right = 384.0
|
margin_right = 384.0
|
||||||
margin_bottom = 520.0
|
margin_bottom = 520.0
|
||||||
rect_scale = Vector2( 0.8, 0.8 )
|
rect_scale = Vector2( 0.8, 0.8 )
|
||||||
|
mouse_filter = 2
|
||||||
texture = ExtResource( 2 )
|
texture = ExtResource( 2 )
|
||||||
stretch_mode = 5
|
stretch_mode = 5
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,22 @@ extends Spatial
|
||||||
|
|
||||||
signal card_selected()
|
signal card_selected()
|
||||||
signal card_unselected()
|
signal card_unselected()
|
||||||
|
signal card_picked()
|
||||||
|
signal card_dropped()
|
||||||
|
|
||||||
var lifted := false
|
var lifted := false
|
||||||
|
export var inHand := false
|
||||||
|
|
||||||
onready var animation := $Border/AnimationPlayer
|
onready var animation := $Border/AnimationPlayer
|
||||||
|
|
||||||
func _mouse_hover():
|
func _mouse_hover():
|
||||||
|
if inHand:
|
||||||
|
animation.play("focus")
|
||||||
emit_signal("card_selected")
|
emit_signal("card_selected")
|
||||||
|
|
||||||
func _mouse_blur():
|
func _mouse_blur():
|
||||||
|
if inHand:
|
||||||
|
animation.play("blur")
|
||||||
emit_signal("card_unselected")
|
emit_signal("card_unselected")
|
||||||
|
|
||||||
func _input_event(camera, event, click_position, click_normal, shape_idx):
|
func _input_event(camera, event, click_position, click_normal, shape_idx):
|
||||||
|
@ -18,12 +25,17 @@ func _input_event(camera, event, click_position, click_normal, shape_idx):
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
lifted = true
|
lifted = true
|
||||||
animation.play("lift")
|
animation.play("lift")
|
||||||
|
emit_signal("card_picked")
|
||||||
else:
|
else:
|
||||||
lifted = false
|
lifted = false
|
||||||
animation.play_backwards("lift")
|
animation.play_backwards("lift")
|
||||||
|
emit_signal("card_dropped")
|
||||||
if lifted and event is InputEventMouseMotion:
|
if lifted and event is InputEventMouseMotion:
|
||||||
var origin: Vector3 = camera.project_ray_origin(event.position)
|
var origin: Vector3 = camera.project_ray_origin(event.position)
|
||||||
var direction: Vector3 = camera.project_ray_normal(event.position)
|
var direction: Vector3 = camera.project_ray_normal(event.position)
|
||||||
|
if inHand:
|
||||||
|
transform.origin = Vector3.ZERO + Vector3.RIGHT * direction * 3.0
|
||||||
|
else:
|
||||||
var denom := Vector3.UP.dot(direction)
|
var denom := Vector3.UP.dot(direction)
|
||||||
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
|
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
|
||||||
transform.origin = origin + direction * t
|
transform.origin = origin + direction * t
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=11 format=2]
|
[gd_scene load_steps=13 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1]
|
[ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
|
[ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
|
||||||
|
@ -8,6 +8,21 @@
|
||||||
[sub_resource type="BoxShape" id=1]
|
[sub_resource type="BoxShape" id=1]
|
||||||
extents = Vector3( 0.367502, 0.0309108, 0.49861 )
|
extents = Vector3( 0.367502, 0.0309108, 0.49861 )
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=8]
|
||||||
|
resource_name = "blur"
|
||||||
|
length = 0.1
|
||||||
|
step = 0.01
|
||||||
|
tracks/0/type = "bezier"
|
||||||
|
tracks/0/path = NodePath(".:translation:z")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"points": PoolRealArray( -0.2, -0.0265325, 0.00965191, 0.0265325, -0.00965191, 0, -0.0730773, 0.0262065, 0.0730773, -0.0262065 ),
|
||||||
|
"times": PoolRealArray( 0, 0.1 )
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=2]
|
[sub_resource type="Animation" id=2]
|
||||||
length = 0.3
|
length = 0.3
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
|
@ -23,7 +38,22 @@ tracks/0/keys = {
|
||||||
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ]
|
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=6]
|
[sub_resource type="Animation" id=3]
|
||||||
|
resource_name = "focus"
|
||||||
|
length = 0.1
|
||||||
|
step = 0.01
|
||||||
|
tracks/0/type = "bezier"
|
||||||
|
tracks/0/path = NodePath(".:translation:z")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"points": PoolRealArray( 0, -0.0120957, 0.235858, 0.0120957, -0.235858, -0.2, -0.0266453, -0.000916421, 0.0266453, 0.000916421 ),
|
||||||
|
"times": PoolRealArray( 0, 0.1 )
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=4]
|
||||||
resource_name = "lift"
|
resource_name = "lift"
|
||||||
length = 0.3
|
length = 0.3
|
||||||
step = 0.05
|
step = 0.05
|
||||||
|
@ -52,7 +82,7 @@ tracks/1/keys = {
|
||||||
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 9.73853 ), Vector3( 0, 0, 0 ) ]
|
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 9.73853 ), Vector3( 0, 0, 0 ) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id=3]
|
[sub_resource type="Animation" id=5]
|
||||||
length = 0.5
|
length = 0.5
|
||||||
step = 0.05
|
step = 0.05
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
|
@ -80,9 +110,9 @@ tracks/1/keys = {
|
||||||
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ]
|
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id=4]
|
[sub_resource type="PlaneMesh" id=6]
|
||||||
|
|
||||||
[sub_resource type="SpatialMaterial" id=5]
|
[sub_resource type="SpatialMaterial" id=7]
|
||||||
flags_unshaded = true
|
flags_unshaded = true
|
||||||
albedo_texture = ExtResource( 4 )
|
albedo_texture = ExtResource( 4 )
|
||||||
uv1_scale = Vector3( 0.9, 0.9, 1 )
|
uv1_scale = Vector3( 0.9, 0.9, 1 )
|
||||||
|
@ -97,19 +127,20 @@ transform = Transform( 1, 0, 0, 0, 1.17955, 0, 0, 0, 1, 0, 0, 0 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="Border" type="MeshInstance" parent="."]
|
[node name="Border" type="MeshInstance" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
|
|
||||||
mesh = ExtResource( 2 )
|
mesh = ExtResource( 2 )
|
||||||
material/0 = ExtResource( 3 )
|
material/0 = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="Border"]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="Border"]
|
||||||
|
anims/blur = SubResource( 8 )
|
||||||
anims/flip = SubResource( 2 )
|
anims/flip = SubResource( 2 )
|
||||||
anims/lift = SubResource( 6 )
|
anims/focus = SubResource( 3 )
|
||||||
anims/tap = SubResource( 3 )
|
anims/lift = SubResource( 4 )
|
||||||
|
anims/tap = SubResource( 5 )
|
||||||
|
|
||||||
[node name="CardImage" type="MeshInstance" parent="Border"]
|
[node name="CardImage" type="MeshInstance" parent="Border"]
|
||||||
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 )
|
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 )
|
||||||
mesh = SubResource( 4 )
|
mesh = SubResource( 6 )
|
||||||
material/0 = SubResource( 5 )
|
material/0 = SubResource( 7 )
|
||||||
[connection signal="input_event" from="." to="." method="_input_event"]
|
[connection signal="input_event" from="." to="." method="_input_event"]
|
||||||
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
|
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
|
||||||
[connection signal="mouse_exited" from="." to="." method="_mouse_blur"]
|
[connection signal="mouse_exited" from="." to="." method="_mouse_blur"]
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
onready var camera := $Camera
|
onready var camera := $Camera
|
||||||
|
onready var hand := $Camera/Hand
|
||||||
|
onready var cards := $Cards
|
||||||
|
onready var handCard := $Camera/Hand/Card4
|
||||||
|
|
||||||
|
export var mouseHandThreshold = 0.9
|
||||||
|
|
||||||
|
var holdingCard: bool
|
||||||
|
|
||||||
var mouseOrigin: Vector2
|
var mouseOrigin: Vector2
|
||||||
var lastCameraTransform: Transform
|
var lastCameraTransform: Transform
|
||||||
|
@ -17,8 +24,31 @@ func _input(event: InputEvent):
|
||||||
lastCameraTransform = camera.transform
|
lastCameraTransform = camera.transform
|
||||||
|
|
||||||
func _process(delta: float):
|
func _process(delta: float):
|
||||||
|
# If mouse is under a certain area then we're managing our hand
|
||||||
|
var absMousePos := get_viewport().get_mouse_position()
|
||||||
# If panning, translate mouse delta to camera delta
|
# If panning, translate mouse delta to camera delta
|
||||||
if Input.is_action_pressed("pan"):
|
if Input.is_action_pressed("pan"):
|
||||||
var mouseDelta := get_viewport().get_mouse_position() - mouseOrigin
|
var mouseDelta := absMousePos - mouseOrigin
|
||||||
var mousePos: Vector2 = mouseDelta * 0.0096 * (1-camera.getZoomLevel()/5) # Magic numbers everywhere
|
var mousePos: Vector2 = mouseDelta * 0.0096 * (1-camera.getZoomLevel()/5) # Magic numbers everywhere
|
||||||
camera.transform.origin = lastCameraTransform.origin - Vector3(mousePos.x, 0, mousePos.y)
|
camera.transform.origin = lastCameraTransform.origin - Vector3(mousePos.x, 0, mousePos.y)
|
||||||
|
# If holding a card, move it between board/hand
|
||||||
|
if holdingCard:
|
||||||
|
var relPos: float = absMousePos.y / get_viewport().size.y
|
||||||
|
var selectingHand: bool = relPos > mouseHandThreshold
|
||||||
|
if selectingHand and not handCard.inHand:
|
||||||
|
call_deferred("reparent", handCard, cards, hand)
|
||||||
|
handCard.inHand = true
|
||||||
|
elif not selectingHand and handCard.inHand:
|
||||||
|
call_deferred("reparent", handCard, hand, cards)
|
||||||
|
handCard.inHand = false
|
||||||
|
|
||||||
|
func _card_picked():
|
||||||
|
holdingCard = true
|
||||||
|
|
||||||
|
func _card_dropped():
|
||||||
|
holdingCard = false
|
||||||
|
|
||||||
|
func reparent(object: Node, from: Node, to: Node):
|
||||||
|
from.remove_child(object)
|
||||||
|
to.add_child(object)
|
||||||
|
object.set_owner(to)
|
22
export_presets.cfg
Normal file
22
export_presets.cfg
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
[preset.0]
|
||||||
|
|
||||||
|
name="HTML5"
|
||||||
|
platform="HTML5"
|
||||||
|
runnable=true
|
||||||
|
custom_features=""
|
||||||
|
export_filter="all_resources"
|
||||||
|
include_filter=""
|
||||||
|
exclude_filter=""
|
||||||
|
export_path="B:/OneDrive/Documenti/VC/mlpcardgame-html/index.html"
|
||||||
|
patch_list=PoolStringArray( )
|
||||||
|
script_export_mode=1
|
||||||
|
script_encryption_key=""
|
||||||
|
|
||||||
|
[preset.0.options]
|
||||||
|
|
||||||
|
vram_texture_compression/for_desktop=true
|
||||||
|
vram_texture_compression/for_mobile=false
|
||||||
|
html/custom_html_shell=""
|
||||||
|
html/head_include=""
|
||||||
|
custom_template/release=""
|
||||||
|
custom_template/debug=""
|
|
@ -16,6 +16,7 @@ _global_script_class_icons={
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="MLP CARD GAME"
|
config/name="MLP CARD GAME"
|
||||||
|
run/main_scene="res://Scenes/Board.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
Loading…
Reference in a new issue