extends Node2D const SlotClass = preload("res:///Objects/Slot.gd") var Panzer_Temp = preload("res://Objects/Panzer.tscn") onready var game_slots = $VBoxContainer/PanzerSlots onready var overlay_node = find_node("Overlay") var score_file = "user://highscore_2048Shooter.save" var holding_item = null var buy_panzer_left = 0 var life = 100 var hover = null onready var start_panzer = 1 var rng = RandomNumberGenerator.new() signal speed_shoot func _ready(): #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) var node = String("Slot ") node += rng.randi_range(1, 8) as String node = find_node(node) node.start_panzer += 1; $Panel/Area2D/LifeBar.value = life overlay_node.connect("score", self, "update_life_bar") for gam_slot in game_slots.get_children(): gam_slot.connect("gui_input", self, "slot_gui_input", [gam_slot]) var pBars = get_tree().get_nodes_in_group("XP") for pBar in pBars: pBar.connect("full_bar", self, "_enable_Panzer") func _process(delta): if $Panel/Area2D/LifeBar.value == 0: save_score() get_tree().change_scene("res://Main Scenes/GameOver.tscn") func slot_gui_input(event: InputEvent, slot: SlotClass): # if OS.get_name() != "Android": # if event is InputEventMouseButton: # if event.button_index == BUTTON_LEFT && event.pressed: # _Panzer_Slot_handler(event, slot) # else: if event is InputEventScreenTouch: if event.pressed: _Panzer_Slot_handler_touch(event, slot) else: if holding_item != null and hover == null and holding_item.old_slot != null: holding_item.old_slot.putIntoSlot(holding_item) holding_item = null elif holding_item != null and hover != null: drag_drop_handle(hover) else: pass pass func _input(event): if event is InputEventScreenDrag: if holding_item: holding_item.global_position = get_global_mouse_position() pass func _on_Panzer_pressed(): if holding_item == null: buy_panzer_left -= 1 if buy_panzer_left == 0: $VBoxContainer/ButtonGrid/Panzer.disabled = true 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) $VBoxContainer/ButtonGrid/Speed.disabled = true pass # Replace with function body. func _enable_Panzer(value): buy_panzer_left += 1 $VBoxContainer/ButtonGrid/Panzer.disabled = false func update_life_bar(): var lifebar = find_node("LifeBar") lifebar.value = lifebar.max_value pass func _on_Bullet_Grave_area_entered(area): if area.is_in_group("Bullet"): var Bullet = area.get_parent() Bullet.queue_free() pass # Replace with function body. func _Panzer_Slot_handler(event: InputEvent, slot: SlotClass): if holding_item != null: if!slot.Panzer: slot.putIntoSlot(holding_item) holding_item = null elif slot.Panzer and holding_item.PanzerType == slot.Panzer.PanzerType: slot.upgradePanzerInSlot() holding_item.queue_free() holding_item = null else: print("yes") # var temp_item = slot.Panzer # slot.pickFromSlot() # temp_item.global_position = event.global_position # slot.putIntoSlot(holding_item) # holding_item = temp_item holding_item.old_slot.putIntoSlot(slot.Panzer) slot.Panzer.old_slot.putIntoSlot(holding_item) elif slot.Panzer: holding_item = slot.Panzer slot.pickFromSlot() holding_item.global_position = get_global_mouse_position() func _Panzer_Slot_handler_touch(event: InputEvent, slot: SlotClass): if holding_item != null and holding_item.old_slot != slot: if!slot.Panzer: slot.putIntoSlot(holding_item) holding_item = null elif slot.Panzer and holding_item.PanzerType == slot.Panzer.PanzerType: slot.upgradePanzerInSlot() holding_item.queue_free() holding_item = null elif holding_item.old_slot != slot: pass elif slot.Panzer and holding_item == null: holding_item = slot.Panzer slot.pickFromSlot() holding_item.global_position = get_global_mouse_position() func drag_drop_handle(hover): if!hover.Panzer: hover.putIntoSlot(holding_item) holding_item = null elif hover.Panzer and holding_item.PanzerType == hover.Panzer.PanzerType: hover.upgradePanzerInSlot() holding_item.queue_free() holding_item = null elif holding_item.old_slot != null: var temp = hover.Panzer var temp2 = holding_item hover.pickFromSlot() hover.putIntoSlot(holding_item) temp2.old_slot.putIntoSlot(temp) holding_item = null elif holding_item.old_slot == null: var temp = hover.Panzer var temp2 = holding_item hover.pickFromSlot() hover.putIntoSlot(holding_item) holding_item = temp holding_item.global_position = get_global_mouse_position() holding_item.old_slot = null func save_score(): var highscoreNode = find_node("Score") var f = File.new() if f.file_exists(score_file): f.open(score_file, File.READ) if (f.get_var() as int) > 0: f.close() f.open(score_file,File.WRITE) f.store_var(highscoreNode.text) f.close()