2048-Shooter/Game.gd
2022-11-24 16:00:50 +01:00

54 lines
1.4 KiB
GDScript

extends Node2D
const SlotClass = preload("res://Slot.gd")
var Panzer_Temp = preload("res://Panzer.tscn")
onready var game_slots = $VBoxContainer/PanzerSlots
var holding_item = null
signal speed_shoot
func _ready():
for gam_slot in game_slots.get_children():
gam_slot.connect("gui_input", self, "slot_gui_input", [gam_slot])
func slot_gui_input(event: InputEvent, slot: SlotClass):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT && event.pressed:
if holding_item != null:
if!slot.Panzer:
slot.putIntoSlot(holding_item)
holding_item = null
else:
var temp_item = slot.Panzer
slot.pickFromSlot()
temp_item.global_position = event.global_position
slot.putIntoSlot(holding_item)
holding_item = temp_item
elif slot.Panzer:
holding_item = slot.Panzer
slot.pickFromSlot()
holding_item.global_position = get_global_mouse_position()
func _input(event):
if holding_item:
holding_item.global_position = get_global_mouse_position()
pass
func _on_Panzer_pressed():
if holding_item == null:
var Panzer = null
Panzer = Panzer_Temp.instance()
add_child(Panzer)
holding_item = Panzer
holding_item.global_position = get_global_mouse_position()
pass # Replace with function body.
func _on_Speed_pressed():
var value = 0.5
emit_signal("speed_shoot", value)
pass # Replace with function body.