Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aliciaredmarr committed Jan 27, 2024
2 parents 7cce846 + fb0d1ab commit 0531293
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 24 deletions.
20 changes: 20 additions & 0 deletions Global.gd
Original file line number Diff line number Diff line change
@@ -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))
Binary file modified assets/zarigueya/culo_salto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/zarigueya/main_caida.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/zarigueya/main_salto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/zarigueya/mano_salto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/zarigueya/susto_caida.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions scenes/gameplay/detect_player.tscn
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions scenes/gameplay/game_finish.gd
Original file line number Diff line number Diff line change
@@ -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()
38 changes: 34 additions & 4 deletions scenes/gameplay/gameplay.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
19 changes: 0 additions & 19 deletions scenes/gameplay/global_position.gdshader

This file was deleted.

2 changes: 2 additions & 0 deletions scenes/gameplay/player-character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
30 changes: 30 additions & 0 deletions scenes/gameplay/rock/rock.tscn
Original file line number Diff line number Diff line change
@@ -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"]
23 changes: 23 additions & 0 deletions scenes/gameplay/rock/rock_hit.gd
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions scenes/gameplay/rock/rock_manager.gd
Original file line number Diff line number Diff line change
@@ -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()
30 changes: 30 additions & 0 deletions scenes/gameplay/rock/rock_spawner.gd
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions scenes/gameplay/rock_spawner.tscn
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 5 additions & 1 deletion scenes/gameplay/trampoline/trampoline-manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ 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)
current_trampoline.position = get_global_mouse_position()
else:
if current_trampoline != null:
current_trampoline.stop_editing()

func _on_game_finish_game_finished():
is_game_finised = true
7 changes: 7 additions & 0 deletions scenes/utils/signal_player_entered.gd
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 0531293

Please sign in to comment.