Skip to content

Commit

Permalink
Added trampoline object with functionality and sound, added customiza…
Browse files Browse the repository at this point in the history
…ble limits to camera vertical movement
  • Loading branch information
ferruccio4 committed Nov 26, 2024
1 parent 6bbf593 commit e265046
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 3 deletions.
20 changes: 20 additions & 0 deletions objects/trampoline.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends Node3D
@export var trampoline_strength : float = 10
@onready var trampoline_audio_stream_player_3d: AudioStreamPlayer3D = $TrampolineAudioStreamPlayer3D
@onready var trampoline_animation_player: AnimationPlayer = $TrampolineAnimationPlayer

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass


func _on_area_3d_body_entered(body: Node3D) -> void:
if body.has_method("bounce_player"):
body.bounce_player(trampoline_strength)
trampoline_audio_stream_player_3d.play()
trampoline_animation_player.play("bounce")
102 changes: 102 additions & 0 deletions objects/trampoline.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[gd_scene load_steps=9 format=3 uid="uid://ytqajrdi7fqj"]

[ext_resource type="Script" path="res://objects/trampoline.gd" id="1_73nxn"]
[ext_resource type="AudioStream" uid="uid://c74thugcgcetg" path="res://sounds/trampoline_bounce.mp3" id="3_0nmjc"]
[ext_resource type="PackedScene" uid="uid://1hx4wcwosemd" path="res://models/props/block-moving-large.glb" id="3_lbpl7"]

[sub_resource type="BoxShape3D" id="BoxShape3D_t50jv"]
size = Vector3(2, 0.5, 2)

[sub_resource type="BoxShape3D" id="BoxShape3D_rnm3k"]
size = Vector3(1.75, 0.5, 1.75)

[sub_resource type="Animation" id="Animation_1iltb"]
resource_name = "bounce"
length = 0.3
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("block-extended:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.3),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [true, true]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("block-extended:scale")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.1, 0.133333, 0.166667, 0.266667, 0.3),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1),
"update": 0,
"values": [Vector3(2, 1, 2), Vector3(1.75, 2, 1.75), Vector3(1.75, 2.1, 1.75), Vector3(1.75, 2, 1.75), Vector3(2.25, 0.9, 2.25), Vector3(2, 1, 2)]
}

[sub_resource type="Animation" id="Animation_hgpsv"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("block-extended:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("block-extended:scale")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(2, 1, 2)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_leh4b"]
_data = {
"RESET": SubResource("Animation_hgpsv"),
"bounce": SubResource("Animation_1iltb")
}

[node name="trampoline" type="Node3D"]
script = ExtResource("1_73nxn")

[node name="StaticBody3D" type="StaticBody3D" parent="."]

[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0)
shape = SubResource("BoxShape3D_t50jv")

[node name="Area3D" type="Area3D" parent="."]
collision_mask = 2
monitorable = false

[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.425, 0)
shape = SubResource("BoxShape3D_rnm3k")

[node name="TrampolineAudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("3_0nmjc")

[node name="block-extended" parent="." instance=ExtResource("3_lbpl7")]
transform = Transform3D(2, 0, 0, 0, 1, 0, 0, 0, 2, 0, -0.1, 0)

[node name="TrampolineAnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_leh4b")
}

[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]
8 changes: 6 additions & 2 deletions scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func handle_controls(delta):
# Handle gravity

func handle_gravity(delta):

gravity += 25 * delta
if gravity < 15:
gravity += 25 * delta

if gravity > 0 and is_on_floor():

Expand Down Expand Up @@ -165,3 +165,7 @@ func player_died() -> void:
func reached_checkpoint(checkpoint_pos : Vector3) -> void:
latest_checkpoint = checkpoint_pos

func bounce_player(bounce_strength : float) -> void:
gravity = -bounce_strength
jump_double = true;

4 changes: 3 additions & 1 deletion scripts/view.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extends Node3D
@export var zoom_maximum = 4
@export var zoom_speed = 10
@export var default_zoom = 10
@export var camera_angle_min : float = -80
@export var camera_angle_max : float = -10

@export_group("Rotation")
@export var rotation_speed = 120
Expand Down Expand Up @@ -64,7 +66,7 @@ func handle_input(delta):
input.x = Input.get_axis("camera_down","camera_up")

camera_rotation += input.limit_length(1.0) * rotation_speed * delta
camera_rotation.x = clamp(camera_rotation.x, -80, -10)
camera_rotation.x = clamp(camera_rotation.x, camera_angle_min, camera_angle_max)

# Zooming

Expand Down
Binary file added sounds/trampoline_bounce.mp3
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/trampoline_bounce.mp3.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="mp3"
type="AudioStreamMP3"
uid="uid://c74thugcgcetg"
path="res://.godot/imported/trampoline_bounce.mp3-7a92a5c42b3b5ed5ed4ee2b1090fb950.mp3str"

[deps]

source_file="res://sounds/trampoline_bounce.mp3"
dest_files=["res://.godot/imported/trampoline_bounce.mp3-7a92a5c42b3b5ed5ed4ee2b1090fb950.mp3str"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

0 comments on commit e265046

Please sign in to comment.