78 lines
1.8 KiB
GDScript
78 lines
1.8 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]=[]
|
|
var energy_start:int=3
|
|
var energy:int=0
|
|
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 get_put_pos():
|
|
return size/2
|
|
func get_discard_pos()->Vector2:
|
|
return size
|
|
|
|
pass
|
|
func add_card(card_id:String,num:int=1):
|
|
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)
|
|
new_card.queue.connect(card_queue.bind(new_card))
|
|
for j in card_arr:
|
|
j.request_resize()
|
|
|
|
|
|
pass
|
|
func get_card_index(card:Card):
|
|
if card in card_arr:
|
|
return card_arr.find(card)
|
|
else:
|
|
return 0
|
|
func card_queue(card:Card):
|
|
queue_card.append(card)
|
|
pass
|
|
#获取释放位置
|
|
func get_queue_pos()->Vector2:
|
|
var pos:Vector2
|
|
if release_card_pos!=null:
|
|
pos=release_card_pos.global_position -self.global_position
|
|
else:
|
|
pos=Vector2.ZERO
|
|
var rand:Vector2=Vector2(randf_range(-rand_release,rand_release),randf_range(-rand_release,rand_release))
|
|
return pos+rand
|
|
@export var exe_card_pos:Control
|
|
func get_exe_position():
|
|
var pos:Vector2
|
|
if release_card_pos!=null:
|
|
pos=exe_card_pos.global_position -self.global_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 clear_card():
|
|
for i in card_arr:
|
|
if not i in queue_card:
|
|
i.clear()
|
|
card_arr.clear()
|
|
|
|
pass
|
|
func exe_queue():
|
|
var i:int=0
|
|
while i<queue_card.size():
|
|
await queue_card[i].exe()
|
|
i+=1
|
|
print("清理队列")
|
|
queue_card.clear()
|
|
pass
|