diff --git a/Global.gd b/Global.gd new file mode 100644 index 0000000..8d7494f --- /dev/null +++ b/Global.gd @@ -0,0 +1,20 @@ +extends Node + +var rock_manager: Node + + +# SHAKE NODES +const _shake_level: float = 40 +const _duration: float = .5 +const _frequency: int = 10 +const _property_to_shake: String = "position" +func create_shake_node2d_tween(node: Node2D, shake_level: float = _shake_level, duration: float = _duration, frequency: float = _frequency, property_to_shake: String = _property_to_shake) -> Tween: + var tween: Tween = get_tree().create_tween() + var period = duration / frequency + for i in range(frequency - 1): + tween.tween_property(node, property_to_shake, node.position + get_random_offset(), period) + tween.tween_property(node, property_to_shake, node.position, period) + return tween + +func get_random_offset() -> Vector2: + return Vector2(randf_range(-_shake_level, _shake_level), randf_range(-_shake_level, _shake_level)) diff --git a/assets/zarigueya/culo_salto.png b/assets/zarigueya/culo_salto.png index 9a51aff..7e00ae9 100644 Binary files a/assets/zarigueya/culo_salto.png and b/assets/zarigueya/culo_salto.png differ diff --git a/assets/zarigueya/main_caida.png b/assets/zarigueya/main_caida.png index 2e11039..b0f459f 100644 Binary files a/assets/zarigueya/main_caida.png and b/assets/zarigueya/main_caida.png differ diff --git a/assets/zarigueya/main_salto.png b/assets/zarigueya/main_salto.png index 77f305e..f15cea7 100644 Binary files a/assets/zarigueya/main_salto.png and b/assets/zarigueya/main_salto.png differ diff --git a/assets/zarigueya/mano_salto.png b/assets/zarigueya/mano_salto.png index 15c196a..2827b45 100644 Binary files a/assets/zarigueya/mano_salto.png and b/assets/zarigueya/mano_salto.png differ diff --git a/assets/zarigueya/susto_caida.png b/assets/zarigueya/susto_caida.png index 8d4b46c..748c073 100644 Binary files a/assets/zarigueya/susto_caida.png and b/assets/zarigueya/susto_caida.png differ diff --git a/project.godot b/project.godot index 573ded4..b103d26 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://scenes/gameplay/gameplay.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg" +[autoload] + +Global="*res://Global.gd" + [display] window/size/viewport_width=600 diff --git a/scenes/gameplay/detect_player.tscn b/scenes/gameplay/detect_player.tscn new file mode 100644 index 0000000..55ae0eb --- /dev/null +++ b/scenes/gameplay/detect_player.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://dd2homxrf853x"] + +[ext_resource type="Script" path="res://scenes/utils/signal_player_entered.gd" id="1_1wnt7"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_ageqp"] +size = Vector2(600, 300) + +[node name="DetectPlayer" type="Area2D"] +position = Vector2(308, -728) +script = ExtResource("1_1wnt7") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_ageqp") + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/gameplay/game_finish.gd b/scenes/gameplay/game_finish.gd new file mode 100644 index 0000000..c95364b --- /dev/null +++ b/scenes/gameplay/game_finish.gd @@ -0,0 +1,13 @@ +extends Node2D + +signal game_finished + +@onready var player_character = $"../PlayerCharacter" +var is_game_finished := false + +func _process(delta): + if is_game_finished: + return + if player_character.position.y < position.y - 100: + $StaticBody2D.position.x = 300 + game_finished.emit() diff --git a/scenes/gameplay/gameplay.tscn b/scenes/gameplay/gameplay.tscn index 3ee3c54..d783edf 100644 --- a/scenes/gameplay/gameplay.tscn +++ b/scenes/gameplay/gameplay.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=15 format=3 uid="uid://iaq32s2ve124"] +[gd_scene load_steps=20 format=3 uid="uid://iaq32s2ve124"] +[ext_resource type="Script" path="res://scenes/gameplay/rock/rock_manager.gd" id="1_023ww"] [ext_resource type="Script" path="res://scenes/gameplay/bottom_floor.gd" id="1_id8xs"] [ext_resource type="Script" path="res://scenes/gameplay/player-character.gd" id="1_x4a8u"] [ext_resource type="Script" path="res://scenes/gameplay/rope_bounce_animation.gd" id="2_mp23v"] @@ -9,8 +10,11 @@ [ext_resource type="Texture2D" uid="uid://bveq7w6bpd8l6" path="res://assets/square.svg" id="4_iy44v"] [ext_resource type="Script" path="res://scenes/gameplay/camera.gd" id="5_h12vd"] [ext_resource type="Texture2D" uid="uid://dtt0hpq8wd37p" path="res://assets/cuerda/medio_cuerda.png" id="8_nf74t"] -[ext_resource type="PackedScene" uid="uid://cyu1bpvwwjhgy" path="res://scenes/gameplay/trampoline/map.tscn" id="11_wuw5i"] +[ext_resource type="PackedScene" uid="uid://dcgm675xw4oul" path="res://scenes/gameplay/rock_spawner.tscn" id="8_w2p7d"] +[ext_resource type="PackedScene" path="res://scenes/gameplay/trampoline/map.tscn" id="11_wuw5i"] [ext_resource type="Texture2D" uid="uid://byken0ipxg6jc" path="res://assets/montana3.png" id="12_ux224"] +[ext_resource type="Script" path="res://scenes/gameplay/game_finish.gd" id="12_wvmty"] +[ext_resource type="PackedScene" uid="uid://dd2homxrf853x" path="res://scenes/gameplay/detect_player.tscn" id="14_shnt8"] [sub_resource type="CircleShape2D" id="CircleShape2D_bnr8y"] radius = 32.0 @@ -21,11 +25,18 @@ size = Vector2(64, 64) [sub_resource type="SegmentShape2D" id="SegmentShape2D_j5mx2"] b = Vector2(600, 0) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_fnds3"] +size = Vector2(600, 100) + [node name="Main" type="Node2D"] -[node name="PlayerCharacter" type="CharacterBody2D" parent="."] +[node name="RockManager" type="Node2D" parent="."] +script = ExtResource("1_023ww") + +[node name="PlayerCharacter" type="CharacterBody2D" parent="." groups=["player"]] position = Vector2(300, 300) -collision_mask = 3 +collision_layer = 3 +collision_mask = 11 floor_stop_on_slope = false script = ExtResource("1_x4a8u") max_bounce = 2.0 @@ -74,6 +85,8 @@ shape = SubResource("RectangleShape2D_8jgpq") scale = Vector2(0.5, 0.5) texture = ExtResource("4_iy44v") +[node name="RockSpawner" parent="Camera2D" instance=ExtResource("8_w2p7d")] + [node name="ParallaxBackground" type="ParallaxBackground" parent="."] [node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"] @@ -100,3 +113,20 @@ texture_mode = 1 script = ExtResource("2_mp23v") [node name="Map" parent="." instance=ExtResource("11_wuw5i")] + +[node name="GameFinish" type="Node2D" parent="."] +position = Vector2(0, -500) +script = ExtResource("12_wvmty") + +[node name="StaticBody2D" type="StaticBody2D" parent="GameFinish" groups=["game_finish_floor"]] +position = Vector2(-300, 50) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="GameFinish/StaticBody2D"] +shape = SubResource("RectangleShape2D_fnds3") +debug_color = Color(0, 0.6, 0.701961, 0.419608) + +[node name="DetectPlayer" parent="." instance=ExtResource("14_shnt8")] +position = Vector2(278, -97) + +[connection signal="game_finished" from="GameFinish" to="TrampolineManager" method="_on_game_finish_game_finished"] +[connection signal="on_player_entered" from="DetectPlayer" to="Camera2D/RockSpawner" method="start"] diff --git a/scenes/gameplay/global_position.gdshader b/scenes/gameplay/global_position.gdshader deleted file mode 100644 index 349c0cd..0000000 --- a/scenes/gameplay/global_position.gdshader +++ /dev/null @@ -1,19 +0,0 @@ -shader_type canvas_item; - -uniform vec2 node_size = vec2(400.0, 400.0); - -varying vec2 vert; - -void vertex(){ - vert = VERTEX; -} - -void fragment() { - vec2 full_uv = vert/node_size; - COLOR.rgb = vec3(full_uv, 0.0); -} - -//void light() { - // Called for every pixel for every light affecting the CanvasItem. - // Uncomment to replace the default light processing function with this one. -//} diff --git a/scenes/gameplay/player-character.gd b/scenes/gameplay/player-character.gd index e34756e..e3545e0 100644 --- a/scenes/gameplay/player-character.gd +++ b/scenes/gameplay/player-character.gd @@ -10,6 +10,8 @@ func _physics_process(delta): velocity.y += delta * gravity var collision = move_and_collide(velocity * delta * speed) if collision: + if (collision.get_collider() as Node).is_in_group("game_finish_floor"): + return var bounce_magnitude = velocity.bounce(collision.get_normal()).length() var lerped_bounce = lerpf(max_bounce, min_bounce, bounce_magnitude / 100) if (collision.get_collider() as Node).is_in_group("bottom_floor"): diff --git a/scenes/gameplay/rock/rock.tscn b/scenes/gameplay/rock/rock.tscn new file mode 100644 index 0000000..103d95f --- /dev/null +++ b/scenes/gameplay/rock/rock.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=5 format=3 uid="uid://g6i6xqvaxk81"] + +[ext_resource type="Texture2D" uid="uid://dds1sdaxddjq" path="res://assets/circle.svg" id="1_18x6o"] +[ext_resource type="Script" path="res://scenes/gameplay/rock/rock_hit.gd" id="2_f6cby"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_gafgp"] +radius = 65.0 + +[sub_resource type="CircleShape2D" id="CircleShape2D_eggec"] +radius = 43.0116 + +[node name="Rock" type="RigidBody2D"] +collision_layer = 4 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_gafgp") + +[node name="Sprite2D" type="Sprite2D" parent="CollisionShape2D"] +texture = ExtResource("1_18x6o") + +[node name="HitArea" type="Area2D" parent="."] +collision_layer = 8 +collision_mask = 2 +script = ExtResource("2_f6cby") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="HitArea"] +shape = SubResource("CircleShape2D_eggec") + +[connection signal="body_entered" from="HitArea" to="HitArea" method="_on_body_entered"] diff --git a/scenes/gameplay/rock/rock_hit.gd b/scenes/gameplay/rock/rock_hit.gd new file mode 100644 index 0000000..386c804 --- /dev/null +++ b/scenes/gameplay/rock/rock_hit.gd @@ -0,0 +1,23 @@ +extends Area2D + +const push_down_velocity: float = 100 + +func _on_body_entered(body: Node2D): + if body.is_in_group("player"): + push_player_down(body) + +func break_rock(): + queue_free() + +func push_player_down(player: Node2D): + set_deferred("monitoring", false) + #Global.rock_manager.set_deferred("sleeping", true) + Global.rock_manager.propagate_call("set_sleeping", [true]) + player.velocity = Vector2.DOWN * push_down_velocity + var tween := Global.create_shake_node2d_tween(player) + tween.tween_callback(restart_physics_and_free) + +func restart_physics_and_free(): + Global.rock_manager.propagate_call("set_sleeping", [false]) + call_deferred("queue_free") + get_parent().queue_free() diff --git a/scenes/gameplay/rock/rock_manager.gd b/scenes/gameplay/rock/rock_manager.gd new file mode 100644 index 0000000..32b581f --- /dev/null +++ b/scenes/gameplay/rock/rock_manager.gd @@ -0,0 +1,11 @@ +extends Node2D + +const DISTANCE_TO_DELETE: float = 1000 + +func _ready(): + Global.rock_manager = self + +func _process(_delta): + for child in get_children(): + if child.position.y > 1000: + child.queue_free() diff --git a/scenes/gameplay/rock/rock_spawner.gd b/scenes/gameplay/rock/rock_spawner.gd new file mode 100644 index 0000000..1dec656 --- /dev/null +++ b/scenes/gameplay/rock/rock_spawner.gd @@ -0,0 +1,30 @@ +extends Area2D + +@onready var rock_scene: PackedScene = load("res://scenes/gameplay/rock/rock.tscn") +@onready var timer = $Timer +@export var spawn_rocks_on_start: bool = false + +func _ready(): + if spawn_rocks_on_start: + $Timer.start() + +func get_random_position_in_spawn_area() -> Vector2: + var rect: Rect2 = $CollisionShape2D.shape.get_rect() + var x = randf_range(rect.position.x, rect.position.x + rect.size.x) + var y = randf_range(rect.position.y, rect.position.y + rect.size.y) + return Vector2(x,y) + +func spawn_rock(): + var instance = rock_scene.instantiate() + instance.position = get_random_position_in_spawn_area() + self.global_position + Global.rock_manager.add_child(instance) + +func _on_timer_timeout(): + get_random_position_in_spawn_area() + spawn_rock() + +func stop(): + $Timer.stop() + +func start(): + $Timer.start(0) diff --git a/scenes/gameplay/rock_spawner.tscn b/scenes/gameplay/rock_spawner.tscn new file mode 100644 index 0000000..8e38088 --- /dev/null +++ b/scenes/gameplay/rock_spawner.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=3 uid="uid://dcgm675xw4oul"] + +[ext_resource type="Script" path="res://scenes/gameplay/rock/rock_spawner.gd" id="1_cglio"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_7ch2b"] +size = Vector2(500, 20) + +[node name="RockSpawner" type="Area2D"] +position = Vector2(-8, -488) +script = ExtResource("1_cglio") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(0, 28) +shape = SubResource("RectangleShape2D_7ch2b") + +[node name="Timer" type="Timer" parent="."] +wait_time = 2.0 + +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/scenes/gameplay/trampoline/trampoline-manager.gd b/scenes/gameplay/trampoline/trampoline-manager.gd index d9f0967..cb95c65 100644 --- a/scenes/gameplay/trampoline/trampoline-manager.gd +++ b/scenes/gameplay/trampoline/trampoline-manager.gd @@ -2,9 +2,10 @@ extends Node2D const TRAMPOLINE = preload("res://scenes/gameplay/trampoline/trampoline.tscn") var current_trampoline +var is_game_finised := false func _input(event): - if event is InputEventMouseButton: + if event is InputEventMouseButton and !is_game_finised: if event.pressed: current_trampoline = TRAMPOLINE.instantiate() get_tree().root.add_child(current_trampoline) @@ -12,3 +13,6 @@ func _input(event): else: if current_trampoline != null: current_trampoline.stop_editing() + +func _on_game_finish_game_finished(): + is_game_finised = true diff --git a/scenes/utils/signal_player_entered.gd b/scenes/utils/signal_player_entered.gd new file mode 100644 index 0000000..6774d66 --- /dev/null +++ b/scenes/utils/signal_player_entered.gd @@ -0,0 +1,7 @@ +extends Area2D + +signal on_player_entered + +func _on_body_entered(body): + if body.is_in_group("player"): + on_player_entered.emit()