45 lines
1.1 KiB
GDScript
45 lines
1.1 KiB
GDScript
extends Control
|
|
class_name CardMachine
|
|
const CARD = preload("res://scene/card.tscn")
|
|
var rand_release:float=20
|
|
@export var release_card_pos:Control
|
|
var distance:float=100
|
|
var card_arr:Array[Card]=[]
|
|
var queue_card:Array[Card]=[]
|
|
func get_index_position(index:int)->Vector2:
|
|
var center=size/2
|
|
var left=center-Vector2(distance*card_arr.size()/2,0)
|
|
var rand_y=randf_range(-10,10)
|
|
return left+Vector2(distance*index,rand_y)
|
|
func _ready() -> void:
|
|
add_card("xxx",4)
|
|
|
|
func get_put_pos():
|
|
return size/2
|
|
|
|
func add_card(card_id:String,num:int):
|
|
for i in num:
|
|
var new_card=CARD.instantiate() as Card
|
|
add_child(new_card)
|
|
new_card.set_data(card_id)
|
|
card_arr.append(new_card)
|
|
for j in card_arr:
|
|
j.request_resize()
|
|
|
|
pass
|
|
#获取释放位置
|
|
func get_release_pos()->Vector2:
|
|
var pos:Vector2
|
|
if release_card_pos!=null:
|
|
pos=release_card_pos.position
|
|
else:
|
|
pos=Vector2.ZERO
|
|
var rand:Vector2=Vector2(randf_range(-rand_release,rand_release),randf_range(-rand_release,rand_release))
|
|
return pos+rand
|
|
|
|
func add_to_queue(card:Card):
|
|
|
|
if queue_card.size()==0:
|
|
queue_card.append(card)
|
|
card.send("your_turn")
|