From 0d5c78d2a4c65ed446aa84db619a62dd0cccc079 Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 13 Oct 2020 17:29:24 +0200 Subject: [PATCH] Automatically draw new cards --- card.gd | 20 ++++++++++++++++---- cardgame.gd | 19 +++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/card.gd b/card.gd index 556c0e6..0152c05 100644 --- a/card.gd +++ b/card.gd @@ -30,10 +30,16 @@ func _unhandled_input(event): dragged = false game.dragged_object = null modulate.a = 1 - move_back() - - if arg_number == 0 and get_viewport().get_mouse_position().y < get_viewport().size.y/2 : - $"../Terminal".send_command($Label.text) + + + if get_viewport().get_mouse_position().y < get_viewport().size.y/2: + if arg_number == 0 : + $"../Terminal".send_command($Label.text) + buuurn() + else: + move_back() + else: + _home_position = get_viewport().get_mouse_position() + drag_offset func _mouse_entered(): hovered = true @@ -47,6 +53,10 @@ func set_command(new_command): func move_back(): position = _home_position + +func buuurn(): + queue_free() + $"..".draw_rand_card() func dropped_on(other): #print("I have been dropped on "+str(other.id)) @@ -55,10 +65,12 @@ func dropped_on(other): 1: full_command = $Label.text + " " + other.id $"../Terminal".send_command(full_command) + buuurn() 2: if _first_argument: full_command = $Label.text + " " + _first_argument + " " + other.id $"../Terminal".send_command(full_command) + buuurn() else: _first_argument = other.id diff --git a/cardgame.gd b/cardgame.gd index 8237c0f..cc65749 100644 --- a/cardgame.gd +++ b/cardgame.gd @@ -24,14 +24,17 @@ func _ready(): $Terminal.repository = $Repository - var pos_x = 100 - for card in cards: - var new_card = preload("res://card.tscn").instance() - new_card.command = card.command - new_card.arg_number = card.arg_number - new_card.position = Vector2(pos_x, get_viewport().size.y*3/4) - pos_x += 250 - add_child(new_card) + for i in range(4): + draw_rand_card() func _update_repo(): $Repository.update_everything() + +func draw_rand_card(): + var new_card = preload("res://card.tscn").instance() + var card = cards[randi() % cards.size()] + new_card.command = card.command + new_card.arg_number = card.arg_number + new_card.position = Vector2(rand_range(200, get_viewport().size.x - 200), get_viewport().size.y*3/4 + rand_range(-200,200)) + add_child(new_card) +