diff --git a/objects/trampoline.gd b/objects/trampoline.gd new file mode 100644 index 00000000..64b57ecc --- /dev/null +++ b/objects/trampoline.gd @@ -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") diff --git a/objects/trampoline.tscn b/objects/trampoline.tscn new file mode 100644 index 00000000..2a0ff4ac --- /dev/null +++ b/objects/trampoline.tscn @@ -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"] diff --git a/scripts/player.gd b/scripts/player.gd index dc4bcfda..80dbddb1 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -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(): @@ -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; + diff --git a/scripts/view.gd b/scripts/view.gd index 0845160a..48eaf79a 100644 --- a/scripts/view.gd +++ b/scripts/view.gd @@ -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 @@ -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 diff --git a/sounds/trampoline_bounce.mp3 b/sounds/trampoline_bounce.mp3 new file mode 100644 index 00000000..c5123ac7 Binary files /dev/null and b/sounds/trampoline_bounce.mp3 differ diff --git a/sounds/trampoline_bounce.mp3.import b/sounds/trampoline_bounce.mp3.import new file mode 100644 index 00000000..640cbea5 --- /dev/null +++ b/sounds/trampoline_bounce.mp3.import @@ -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