Skip to content

Commit

Permalink
Control del player al cargar pero es un hijo de puta y aunque funcion…
Browse files Browse the repository at this point in the history
…a, da un error.
  • Loading branch information
SeindElBardo committed Feb 1, 2021
1 parent 1748111 commit 97f30ed
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 16 deletions.
7 changes: 4 additions & 3 deletions axel_sandbox/src/actors/Chest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ 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 = {
"filename" : get_filename(),
"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

1 change: 0 additions & 1 deletion axel_sandbox/src/actors/Chest.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ animations = [ {
} ]

[node name="Chest" type="KinematicBody2D" groups=[
"Sensitive",
"items",
]]
collision_layer = 32
Expand Down
40 changes: 38 additions & 2 deletions axel_sandbox/src/actors/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand All @@ -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)

Expand All @@ -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")
Expand All @@ -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
13 changes: 8 additions & 5 deletions axel_sandbox/src/actors/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand All @@ -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="."]
Expand All @@ -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"]
21 changes: 21 additions & 0 deletions axel_sandbox/src/levels/LevelTemplate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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())


4 changes: 3 additions & 1 deletion axel_sandbox/src/levels/LevelTemplate.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ 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 )
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 )

Expand Down
7 changes: 3 additions & 4 deletions real_deal/scripts/utils/GameSaver.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down

0 comments on commit 97f30ed

Please sign in to comment.