diff --git a/axel_sandbox/src/actors/Chest.gd b/axel_sandbox/src/actors/Chest.gd index ddc2efa..2fda386 100644 --- a/axel_sandbox/src/actors/Chest.gd +++ b/axel_sandbox/src/actors/Chest.gd @@ -4,14 +4,13 @@ extends KinematicBody2D export (bool) var full = false func _on_Player_item_collision(body): + print("me han llamaado ", body) if body == self: if full: $Sprite.play("open_full") else: $Sprite.play("open_empty") -func _process(delta): - print(full) func save(): var save_dict = { @@ -19,6 +18,8 @@ func save(): "parent" : get_parent().get_path(), "pos_x" : position.x, # Vector2 is not supported by JSON "pos_y" : position.y, - "full" : -1 + "full" : full, + "name" : "FullChest" if self.full else "EmptyChest" } return save_dict + diff --git a/axel_sandbox/src/actors/Chest.tscn b/axel_sandbox/src/actors/Chest.tscn index 0abe886..9cf2ee5 100644 --- a/axel_sandbox/src/actors/Chest.tscn +++ b/axel_sandbox/src/actors/Chest.tscn @@ -30,7 +30,6 @@ animations = [ { } ] [node name="Chest" type="KinematicBody2D" groups=[ -"Sensitive", "items", ]] collision_layer = 32 diff --git a/axel_sandbox/src/actors/Player.gd b/axel_sandbox/src/actors/Player.gd index 84b8bbe..2879b3f 100644 --- a/axel_sandbox/src/actors/Player.gd +++ b/axel_sandbox/src/actors/Player.gd @@ -3,8 +3,24 @@ extends Actor onready var card_database = preload("res://adri_sandbox/CardsDatabase.gd").DATA onready var funciones = preload("res://adri_sandbox/Effects.gd").new() -signal open_door(body) -signal item_collision(body) +signal open_door +signal item_collision + +func _ready(): + # TODO + # Pasar a generico por grupo de objetos + # Ver si hay alguna forma de que no de error y funcione + var empty_chest = get_tree().get_root().find_node("EmptyChest", true, false) + var full_chest = get_tree().get_root().find_node("FullChest", true, false) + var door = get_tree().get_root().find_node("Door", true, false) + # Es un hijo de puta y siempre da un error + self.disconnect("item_collision", empty_chest, "_on_Player_item_collision") + self.disconnect("item_collision", full_chest, "_on_Player_item_collision") + self.disconnect("open_door", door, "_on_Player_open_door") + self.connect("item_collision", empty_chest, "_on_Player_item_collision") + self.connect("item_collision", full_chest, "_on_Player_item_collision") + self.connect("open_door", door, "_on_Player_open_door") + func get_direction() -> Vector2: var velocity: = Vector2() @@ -29,6 +45,9 @@ func run_animation(delta): if Input.is_action_pressed('attack') and _time_since_attack < attack_timer: $Sprite.play("attack") _time_since_attack += delta + #print(get_tree().get_nodes_in_group("Sensitive")) + #for nooo in get_tree().get_nodes_in_group("Sensitive"): + #print(nooo.get_children()) elif Input.is_action_just_released('attack'): _time_since_attack = 0.0 elif is_movement(): @@ -43,8 +62,11 @@ func process_traps(): func process_overlapping_bodies_actions(overlapping_bodies): for body in overlapping_bodies: + print(body, body.is_in_group("items")) if body.is_in_group("items"): + print("llamando") emit_signal("item_collision", body) + print("llamado") if body.is_in_group("doors"): emit_signal("open_door", body) @@ -54,6 +76,8 @@ func _process(delta): run_animation(delta) _velocity = move_and_slide(_velocity) + + func _input(event): if Input.is_action_pressed("ui_right"): SceneManager.goto_scene("res://adri_sandbox/MainMenu.tscn") @@ -75,3 +99,15 @@ func _on_CollisionObjects_body_entered(body): print("Enemy killed") body.queue_free() SceneManager.goto_scene("res://real_deal/scenes/duel/DuelManager.tscn") + + +# Adri things for save manager +func save(): + var save_dict = { + "filename" : get_filename(), + "parent" : get_parent().get_path(), + "pos_x" : position.x, # Vector2 is not supported by JSON + "pos_y" : position.y, + "name" : "Player" + } + return save_dict diff --git a/axel_sandbox/src/actors/Player.tscn b/axel_sandbox/src/actors/Player.tscn index 11318e8..8972d36 100644 --- a/axel_sandbox/src/actors/Player.tscn +++ b/axel_sandbox/src/actors/Player.tscn @@ -35,9 +35,11 @@ animations = [ { [sub_resource type="RectangleShape2D" id=3] extents = Vector2( 8.32928, 8.55681 ) -[node name="Player" type="KinematicBody2D"] -collision_layer = 0 -collision_mask = 0 +[node name="Player" type="KinematicBody2D" groups=[ +"Sensitive", +]] +collision_layer = 2147483649 +collision_mask = 4 script = ExtResource( 2 ) __meta__ = { "_edit_horizontal_guides_": [ 50.0 ] @@ -50,8 +52,8 @@ shape = SubResource( 1 ) [node name="Camera2D" type="Camera2D" parent="."] current = true zoom = Vector2( 0.5, 0.5 ) -limit_left = 0 -limit_top = 0 +limit_left = -100000000 +limit_top = -100000000 limit_smoothed = true [node name="Sprite" type="AnimatedSprite" parent="."] @@ -65,5 +67,6 @@ collision_mask = 58 [node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerInfluece"] position = Vector2( -0.779537, -9.13171 ) +scale = Vector2( 1.001, 1 ) shape = SubResource( 3 ) [connection signal="body_entered" from="PlayerInfluece" to="." method="_on_CollisionObjects_body_entered"] diff --git a/axel_sandbox/src/levels/LevelTemplate.gd b/axel_sandbox/src/levels/LevelTemplate.gd index 77dafea..f6576d5 100644 --- a/axel_sandbox/src/levels/LevelTemplate.gd +++ b/axel_sandbox/src/levels/LevelTemplate.gd @@ -2,3 +2,24 @@ extends Node2D func _ready(): GameSaver.load_game() + print("jajaja") + set_owner(get_tree().get_nodes_in_group("Sensitive")) + print("oooooooooooooooo") + """ + var player = get_tree().get_root().find_node("Player", true, false) + var chest = get_tree().get_root().find_node("EmptyChest", true, false) + $Player.disconnect("item_collision", $EmptyChest, "_on_Player_item_collision") + print(player.connect("item_collision", chest, "_on_Player_item_collision")) + $Player.disconnect("item_collision", $FullChest, "_on_Player_item_collision") + print($Player.connect("item_collision", $FullChest, "_on_Player_item_collision")) + #$Player.connect("open_door", $Door, "_on_Player_open_door") + """ + +func set_owner(clueless_nodes): + for clueless_node in clueless_nodes: + print(clueless_node.owner) + clueless_node.owner = self + print(clueless_node.owner) + #set_owner(clueless_node.get_children()) + + diff --git a/axel_sandbox/src/levels/LevelTemplate.tscn b/axel_sandbox/src/levels/LevelTemplate.tscn index 6824c36..0d25665 100644 --- a/axel_sandbox/src/levels/LevelTemplate.tscn +++ b/axel_sandbox/src/levels/LevelTemplate.tscn @@ -88,7 +88,6 @@ shape = SubResource( 2 ) [node name="Player" parent="." instance=ExtResource( 1 )] position = Vector2( 497.67, 104.566 ) collision_layer = 1 -collision_mask = 4 [node name="Camera2D" parent="Player" index="1"] position = Vector2( -2.00226, 2.17174 ) @@ -96,6 +95,9 @@ limit_top = -450 limit_right = 2880 limit_bottom = 800 +[node name="CollisionShape2D" parent="Player/PlayerInfluece" index="0"] +scale = Vector2( 1.00131, 1 ) + [node name="EnemyOne" parent="." instance=ExtResource( 4 )] position = Vector2( 647.396, 83.4273 ) diff --git a/real_deal/scripts/utils/GameSaver.gd b/real_deal/scripts/utils/GameSaver.gd index e33c6c9..0b9aa95 100644 --- a/real_deal/scripts/utils/GameSaver.gd +++ b/real_deal/scripts/utils/GameSaver.gd @@ -54,8 +54,7 @@ func load_game(): # For our example, we will accomplish this by deleting saveable objects. var save_nodes = get_tree().get_nodes_in_group("Sensitive") for i in save_nodes: - print(i.name) - print("he eliminado cosas") + print("he eliminado ", i.name) i.queue_free() # Load the file line by line and process that dictionary to restore @@ -69,11 +68,11 @@ func load_game(): var new_object = load(node_data["filename"]).instance() get_node(node_data["parent"]).add_child(new_object) new_object.position = Vector2(node_data["pos_x"], node_data["pos_y"]) + #new_object.name = node_data["name"] # Now we set the remaining variables. for i in node_data.keys(): - print("jajajajaja") - print(i) + print("keys", i) if i == "filename" or i == "parent" or i == "pos_x" or i == "pos_y": continue new_object.set(i, node_data[i])