You can now play cards!

- Fixed invalid scripts
- Added card placement validation

Co-Authored-By: deranonymos <deranonymos@users.noreply.github.com>
This commit is contained in:
2020-04-20 01:06:26 +02:00
parent 32ccb24012
commit 1544bf6feb
8 changed files with 83 additions and 79 deletions

View File

@@ -0,0 +1,3 @@
extends Control
export var ObjectParent:NodePath

View File

@@ -7,19 +7,14 @@
[ext_resource path="res://Objects/Traps/Bear/bear.jpg" type="Texture" id=5]
[ext_resource path="res://Objects/Traps/bear.tscn" type="PackedScene" id=6]
[ext_resource path="res://Objects/Traps/Bear/Animation/0012.png" type="Texture" id=7]
[sub_resource type="GDScript" id=1]
script/source = "extends Control
export var ObjectParent:NodePath
"
[ext_resource path="res://Menus/DragNDrop/DragNDropUI.gd" type="Script" id=8]
[node name="DragNDropUI" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -0.37735
margin_right = -0.37735
script = SubResource( 1 )
script = ExtResource( 8 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@@ -0,0 +1,30 @@
extends Container
const Grid = preload("res://Maps/Grid.gd")
onready var grid = get_tree().current_scene.get_node("Grid")
onready var ysort = get_tree().current_scene.get_node("YSort")
#DropZone
#stuff can be dropped here
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
func get_nearest_grid_pos(position):
return Vector2(round(position.x / 32.0), round(position.y / 32.0))
func get_nearest_global_pos(position):
return Vector2(round(position.x / 32.0) * 32, round(position.y / 32.0) * 32)
#what is to be done when data is dropped
func drop_data(_pos, data:PackedScene):
var new_pos = get_nearest_grid_pos(_pos)
if grid.object_grid[new_pos.x - 1][new_pos.y - 1].back() == Grid.Kind.FIELD:
var child = data.instance()
child.position = get_nearest_global_pos(_pos)
ysort.add_child(child)
grid._update_grid()

View File

@@ -1,31 +1,12 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="GDScript" id=1]
script/source = "extends Container
#DropZone
#stuff can be dropped here
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
func get_nearest_grid_pos(position):
return Vector2(floor(position.x / 32.0) * 32, floor(position.y / 32.0) * 32)
#what is to be done when data is dropped
func drop_data(_pos, data:PackedScene):
var child = data.instance()
child.position = get_nearest_grid_pos(_pos)
get_node(get_parent().ObjectParent).add_child(child)
"
[ext_resource path="res://Menus/DragNDrop/DragSink.gd" type="Script" id=1]
[node name="DragSink" type="Container"]
anchor_right = 1.0
anchor_bottom = 0.789
margin_bottom = -0.0200043
script = SubResource( 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@@ -0,0 +1,36 @@
extends TextureRect
#CardDeck
export var Item:PackedScene
export var PreviewIcon:Texture
export var DeleteOnGrab:bool = false
#if a drag is initiated here
func get_drag_data(_pos):
var ctrl = Control.new()
var TR = TextureRect.new()
TR.texture = get_resized_texture(PreviewIcon,self.rect_size[0],self.rect_size[1])
TR.rect_size= self.rect_size
TR.set_position(_pos*-1,false)
ctrl.add_child(TR)
set_drag_preview(ctrl)
if DeleteOnGrab :
self.queue_free()
return Item
#stuff can be dropped here
#eg you picked the wrong thing up, let go and it returns to nothingness
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
#do nothing if stuff is dropped here
func drop_data(_pos, _data):
pass
func get_resized_texture(t: Texture, width: int = 0, height: int = 0):
var image = t.get_data()
if width > 0 && height > 0:
image.resize(width, height)
var itex = ImageTexture.new()
itex.create_from_image(image,0)
return itex

View File

@@ -2,45 +2,7 @@
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Objects/Card/card.png" type="Texture" id=2]
[sub_resource type="GDScript" id=1]
script/source = "extends TextureRect
#CardDeck
export var Item:PackedScene
export var PreviewIcon:Texture
export var DeleteOnGrab:bool = false
#if a drag is initiated here
func get_drag_data(_pos):
var ctrl = Control.new()
var TR = TextureRect.new()
TR.texture = get_resized_texture(PreviewIcon,self.rect_size[0],self.rect_size[1])
TR.rect_size= self.rect_size
TR.set_position(_pos*-1,false)
ctrl.add_child(TR)
set_drag_preview(ctrl)
if DeleteOnGrab :
self.queue_free()
return Item
#stuff can be dropped here
#eg you picked the wrong thing up, let go and it returns to nothingness
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
#do nothing if stuff is dropped here
func drop_data(_pos, _data):
pass
func get_resized_texture(t: Texture, width: int = 0, height: int = 0):
var image = t.get_data()
if width > 0 && height > 0:
image.resize(width, height)
var itex = ImageTexture.new()
itex.create_from_image(image,0)
return itex
"
[ext_resource path="res://Menus/DragNDrop/DragSource.gd" type="Script" id=3]
[node name="DragSource" type="TextureRect"]
margin_left = 10.7364
@@ -49,11 +11,10 @@ margin_right = 42.7364
margin_bottom = 259.792
texture = ExtResource( 1 )
expand = true
script = SubResource( 1 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
PreviewIcon = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 16.0791, 16.0117 )

View File

@@ -36,7 +36,7 @@
[ext_resource path="res://Objects/Traps/Bear/Animation/0009.png" type="Texture" id=35]
[ext_resource path="res://Objects/Traps/Bear/Animation/0012.png" type="Texture" id=36]
[sub_resource type="SpriteFrames" id=1]
[sub_resource type="SpriteFrames" id=4]
animations = [ {
"frames": [ ExtResource( 12 ), ExtResource( 7 ), ExtResource( 28 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 9 ), ExtResource( 29 ), ExtResource( 24 ), ExtResource( 15 ), ExtResource( 35 ), ExtResource( 13 ), ExtResource( 22 ) ],
"loop": false,
@@ -54,7 +54,7 @@ animations = [ {
"speed": 60.0
} ]
[sub_resource type="CapsuleShape2D" id=2]
[sub_resource type="CapsuleShape2D" id=5]
height = 9.0
[sub_resource type="CapsuleShape2D" id=3]
@@ -68,15 +68,14 @@ kind = 10
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( -7.62939e-06, 0 )
frames = SubResource( 1 )
animation = "used"
frames = SubResource( 4 )
[node name="Hitbox" parent="." instance=ExtResource( 2 )]
collision_layer = 16
[node name="CollisionShape2D" parent="Hitbox" index="0"]
rotation = 1.5708
shape = SubResource( 2 )
shape = SubResource( 5 )
[node name="Hurtbox" parent="." instance=ExtResource( 5 )]
collision_layer = 32

View File

@@ -31,20 +31,19 @@ __meta__ = {
}
[node name="YSort" type="YSort" parent="."]
position = Vector2( 152, 120 )
[node name="Bonfire" parent="YSort" instance=ExtResource( 10 )]
position = Vector2( 264, -24 )
position = Vector2( 406.635, 139.865 )
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
position = Vector2( 240, 72 )
position = Vector2( 342.83, 130.381 )
scale = Vector2( 2, 2 )
debug = true
ROLL_SPEED = 140
FRICTION = 200
[node name="Boss_template" parent="YSort" instance=ExtResource( 17 )]
position = Vector2( -67.0889, 2.27742 )
position = Vector2( 71.566, 94.4929 )
debug = true
[node name="Grid" parent="." instance=ExtResource( 18 )]
@@ -57,6 +56,6 @@ visible = false
[node name="DragNDropUI" parent="CanvasLayer" instance=ExtResource( 5 )]
margin_top = -0.735092
margin_bottom = -0.735107
ObjectParent = NodePath("../..")
ObjectParent = NodePath("../../YSort")
[editable path="YSort/Bonfire"]