Added putting cards in hand/play

This commit is contained in:
Hamcha 2019-05-05 21:19:39 +02:00
parent c2318a92d1
commit 7c56dc1088
Signed by: hamcha
GPG key ID: A40413D21021EAEE
7 changed files with 134 additions and 24 deletions

View file

@ -2,13 +2,13 @@
[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://MLPAssets/Background/boardbg.jpg" type="Texture" id=3]
[ext_resource path="res://Scenes/BoardUI.tscn" type="PackedScene" id=4]
[ext_resource path="res://Scenes/Components/Card.tscn" type="PackedScene" id=5]
[ext_resource path="res://Scenes/Components/Card.tscn" type="PackedScene" id=3]
[ext_resource path="res://MLPAssets/Background/boardbg.jpg" type="Texture" id=4]
[ext_resource path="res://Scenes/BoardUI.tscn" type="PackedScene" id=5]
[sub_resource type="SpatialMaterial" id=1]
flags_unshaded = true
albedo_texture = ExtResource( 3 )
albedo_texture = ExtResource( 4 )
[sub_resource type="PlaneMesh" id=2]
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 )
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="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.001, 0 )
mesh = SubResource( 2 )
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 )
[connection signal="card_selected" from="Card" to="BoardUI" method="_card_selected" binds= [ "ff6" ]]
[connection signal="card_unselected" from="Card" to="BoardUI" method="_card_unselected"]
[connection signal="mouse_exited" from="Card" to="." method="_mouse_blur"]
[connection signal="card_dropped" from="Camera/Hand/Card4" to="." method="_card_dropped"]
[connection signal="card_picked" from="Camera/Hand/Card4" to="." method="_card_picked"]
[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"]

View file

@ -57,6 +57,7 @@ margin_left = 40.0
margin_right = 384.0
margin_bottom = 520.0
rect_scale = Vector2( 0.8, 0.8 )
mouse_filter = 2
texture = ExtResource( 2 )
stretch_mode = 5

View file

@ -2,15 +2,22 @@ extends Spatial
signal card_selected()
signal card_unselected()
signal card_picked()
signal card_dropped()
var lifted := false
export var inHand := false
onready var animation := $Border/AnimationPlayer
func _mouse_hover():
if inHand:
animation.play("focus")
emit_signal("card_selected")
func _mouse_blur():
if inHand:
animation.play("blur")
emit_signal("card_unselected")
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:
lifted = true
animation.play("lift")
emit_signal("card_picked")
else:
lifted = false
animation.play_backwards("lift")
emit_signal("card_dropped")
if lifted and event is InputEventMouseMotion:
var origin: Vector3 = camera.project_ray_origin(event.position)
var direction: Vector3 = camera.project_ray_normal(event.position)
var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
transform.origin = origin + direction * t
if inHand:
transform.origin = Vector3.ZERO + Vector3.RIGHT * direction * 3.0
else:
var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
transform.origin = origin + direction * t

View file

@ -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://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
@ -8,6 +8,21 @@
[sub_resource type="BoxShape" id=1]
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]
length = 0.3
tracks/0/type = "value"
@ -23,7 +38,22 @@ tracks/0/keys = {
"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"
length = 0.3
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 ) ]
}
[sub_resource type="Animation" id=3]
[sub_resource type="Animation" id=5]
length = 0.5
step = 0.05
tracks/0/type = "value"
@ -80,9 +110,9 @@ tracks/1/keys = {
"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
albedo_texture = ExtResource( 4 )
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 )
[node name="Border" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mesh = ExtResource( 2 )
material/0 = ExtResource( 3 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="Border"]
anims/blur = SubResource( 8 )
anims/flip = SubResource( 2 )
anims/lift = SubResource( 6 )
anims/tap = SubResource( 3 )
anims/focus = SubResource( 3 )
anims/lift = SubResource( 4 )
anims/tap = SubResource( 5 )
[node name="CardImage" type="MeshInstance" parent="Border"]
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 )
mesh = SubResource( 4 )
material/0 = SubResource( 5 )
mesh = SubResource( 6 )
material/0 = SubResource( 7 )
[connection signal="input_event" from="." to="." method="_input_event"]
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
[connection signal="mouse_exited" from="." to="." method="_mouse_blur"]

View file

@ -1,6 +1,13 @@
extends Spatial
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 lastCameraTransform: Transform
@ -17,8 +24,31 @@ func _input(event: InputEvent):
lastCameraTransform = camera.transform
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 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
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
View 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=""

View file

@ -16,6 +16,7 @@ _global_script_class_icons={
[application]
config/name="MLP CARD GAME"
run/main_scene="res://Scenes/Board.tscn"
config/icon="res://icon.png"
[display]