Skip to content

Commit

Permalink
Small tweak to button, added a sample level
Browse files Browse the repository at this point in the history
  • Loading branch information
ferruccio4 committed Nov 15, 2024
1 parent b5a831f commit c303b75
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 11 deletions.
4 changes: 4 additions & 0 deletions objects/button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0751945, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"]
shape = SubResource("BoxShape3D_0fkk3")

[node name="CooldownTimer" type="Timer" parent="." index="4"]
wait_time = 1.5
one_shot = true

[connection signal="area_entered" from="ButtonArea3D" to="." method="_on_button_area_3d_area_entered"]
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="Level Design Starter Kit 3D Platformer"
config/tags=PackedStringArray("futuregames")
run/main_scene="res://scenes/main.tscn"
run/main_scene="res://scenes/sample.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
boot_splash/bg_color=Color(0.92549, 0.92549, 0.960784, 1)
boot_splash/image="res://splash-screen.png"
Expand Down
312 changes: 312 additions & 0 deletions scenes/sample.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
[gd_scene load_steps=30 format=3 uid="uid://e6jwbml72r4o"]

[ext_resource type="Environment" uid="uid://bqnqgflivjvue" path="res://scenes/main-environment.tres" id="1_apxki"]
[ext_resource type="PackedScene" uid="uid://dl2ed4gkybggf" path="res://objects/player.tscn" id="2_hgw2l"]
[ext_resource type="Script" path="res://scripts/view.gd" id="3_xcrwe"]
[ext_resource type="PackedScene" uid="uid://bpharv43ulngb" path="res://objects/platform_moving.tscn" id="4_5ex8m"]
[ext_resource type="PackedScene" uid="uid://bdm3quh21j64k" path="res://objects/platform_large.tscn" id="5_ly2vk"]
[ext_resource type="PackedScene" uid="uid://bs65o07otxbmm" path="res://objects/moving_object_path_3d.tscn" id="6_fuduw"]
[ext_resource type="PackedScene" uid="uid://dhxok27jxvik8" path="res://objects/flag.tscn" id="7_dhnka"]
[ext_resource type="PackedScene" uid="uid://dwvhgrcyestak" path="res://objects/trap_spikes.tscn" id="11_s1f4a"]
[ext_resource type="PackedScene" uid="uid://g73m8k0j7lyo" path="res://objects/button.tscn" id="12_kk8bf"]
[ext_resource type="PackedScene" uid="uid://0v6t454aaexr" path="res://objects/door.tscn" id="13_2py5d"]
[ext_resource type="PackedScene" uid="uid://cxea8lmw7cy1l" path="res://objects/player_kill_volume.tscn" id="14_6of3h"]
[ext_resource type="PackedScene" uid="uid://cyvet7kb6y80r" path="res://objects/checkpoint.tscn" id="15_4nog2"]
[ext_resource type="PackedScene" uid="uid://cnymdajj1vsqm" path="res://objects/platform.tscn" id="16_82380"]
[ext_resource type="PackedScene" uid="uid://rjh4ifidqrfp" path="res://objects/platform_medium.tscn" id="17_qgsha"]
[ext_resource type="PackedScene" uid="uid://c8up71en5djgm" path="res://objects/platform_falling.tscn" id="18_x8jhr"]
[ext_resource type="PackedScene" uid="uid://uqr4hswv6d2g" path="res://objects/platform_grass_large_round.tscn" id="19_qait6"]
[ext_resource type="PackedScene" uid="uid://dfpisimsgf5ce" path="res://objects/coin.tscn" id="20_lfsn4"]
[ext_resource type="PackedScene" uid="uid://dy017k58p20sk" path="res://objects/cloud.tscn" id="21_dryjk"]
[ext_resource type="Script" path="res://scripts/hud.gd" id="22_1dx8f"]
[ext_resource type="Texture2D" uid="uid://cd7oyc56ehkx1" path="res://sprites/coin.png" id="23_324j0"]
[ext_resource type="LabelSettings" uid="uid://daohhjonjrdx8" path="res://themes/label_settings.tres" id="24_6hsja"]
[ext_resource type="FontFile" uid="uid://d0cxd77jybrcn" path="res://fonts/lilita_one_regular.ttf" id="25_vfu23"]
[ext_resource type="Theme" uid="uid://d3avl0mr4r87l" path="res://themes/default_theme.tres" id="26_xw2uw"]
[ext_resource type="Texture2D" uid="uid://dm50aa4qogm65" path="res://sprites/button_rectangle_depth_gloss.png" id="27_ct75u"]

[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_u8ojw"]
auto_exposure_scale = 0.75
dof_blur_far_distance = 0.01

[sub_resource type="Curve3D" id="Curve3D_5n82a"]
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, -25.545, 2.4, -1.4, 0, 0, 0, 0, 0, 0, -19, 2.4, -1.4),
"tilts": PackedFloat32Array(0, 0)
}
point_count = 2

[sub_resource type="LabelSettings" id="LabelSettings_ri8jt"]
font = ExtResource("25_vfu23")
font_size = 128
shadow_color = Color(0, 0, 0, 0.376471)
shadow_offset = Vector2(2, 2)

[sub_resource type="LabelSettings" id="LabelSettings_x4d2s"]
font = ExtResource("25_vfu23")
font_size = 32
shadow_color = Color(0, 0, 0, 0.376471)
shadow_offset = Vector2(2, 2)

[sub_resource type="LabelSettings" id="LabelSettings_v6r7m"]
font = ExtResource("25_vfu23")
font_size = 42
shadow_color = Color(0, 0, 0, 0.376471)
shadow_offset = Vector2(2, 2)

[node name="Main" type="Node3D"]

[node name="Environment" type="WorldEnvironment" parent="."]
unique_name_in_owner = true
environment = ExtResource("1_apxki")
camera_attributes = SubResource("CameraAttributesPractical_u8ojw")

[node name="Player" parent="." node_paths=PackedStringArray("view") instance=ExtResource("2_hgw2l")]
transform = Transform3D(-0.436802, 0, -0.899558, 0, 1, 0, 0.899558, 0, -0.436802, 0, 1.86931, 6.61307)
view = NodePath("../View")

[node name="View" type="Node3D" parent="." node_paths=PackedStringArray("target") groups=["View"]]
process_mode = 3
transform = Transform3D(0.707107, -0.298836, 0.640856, 0, 0.906308, 0.422618, -0.707107, -0.298836, 0.640856, 0, 0, 0)
script = ExtResource("3_xcrwe")
target = NodePath("../Player")

[node name="Camera" type="Camera3D" parent="View"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
current = true
fov = 40.0

[node name="World" type="Node3D" parent="."]

[node name="platform-moving" parent="World" instance=ExtResource("4_5ex8m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 0)

[node name="platform-large" parent="World" instance=ExtResource("5_ly2vk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -14.9563, 2.11817, -1.1764)

[node name="platform-large2" parent="World" instance=ExtResource("5_ly2vk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -34.9558, 2.20127, -8.90485)

[node name="moving_object_path" parent="World" node_paths=PackedStringArray("object_to_move") instance=ExtResource("6_fuduw")]
curve = SubResource("Curve3D_5n82a")
object_to_move = NodePath("../platform-moving")
is_on_from_start = false
ping_pong = true

[node name="flag" parent="World" instance=ExtResource("7_dhnka")]
transform = Transform3D(0.707107, 0, -0.707107, 0, 1, 0, 0.707107, 0, 0.707107, -35.0779, 2.7273, -8.92648)

[node name="trap-spikes" parent="World" instance=ExtResource("11_s1f4a")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -34.578, 2.71517, -4.91552)

[node name="trap-spikes2" parent="World" instance=ExtResource("11_s1f4a")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -35.3781, 2.71517, -4.91552)

[node name="button" parent="World" node_paths=PackedStringArray("target") instance=ExtResource("12_kk8bf")]
transform = Transform3D(0.997099, 0, 0.0761099, 0, 1, 0, -0.0761099, 0, 0.997099, -20.392, 4.90807, 6.39096)
target = NodePath("../moving_object_path")

[node name="button2" parent="World" node_paths=PackedStringArray("target") instance=ExtResource("12_kk8bf")]
transform = Transform3D(0.999991, 0, 0.00434586, 0, 1, 0, -0.00434586, 0, 0.999991, -16.3423, 2.64299, 0.277611)
target = NodePath("../door")

[node name="door" parent="World" instance=ExtResource("13_2py5d")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -28.3271, 2.71653, -1.4)
look_at_door_when_opens = true

[node name="player_kill_volume" parent="World" instance=ExtResource("14_6of3h")]

[node name="checkpoint" parent="World" instance=ExtResource("15_4nog2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -14.7315, 2.80471, -1.40497)

[node name="checkpoint2" parent="World" instance=ExtResource("15_4nog2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -34.7315, 2.80471, -1.40497)

[node name="platform" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(0.993085, 0, -0.117399, 0, 1, 0, 0.117399, 0, 0.993085, -14.7193, 2.1308, 3.52329)

[node name="platform9" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(0.717166, 0, -0.696903, 0, 1, 0, 0.696903, 0, 0.717166, -15.5266, 3.15296, 5.0365)

[node name="platform8" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(0.98534, 0, 0.170605, 0, 1, 0, -0.170605, 0, 0.98534, -17.133, 4.06614, 5.95493)

[node name="platform2" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -28.9535, 2.20613, -1.4)

[node name="platform3" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -30.9725, 2.20613, -1.4)

[node name="platform4" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -32.9883, 2.20613, -1.4)

[node name="platform5" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -34.9883, 2.20613, -1.4)

[node name="platform6" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -34.9883, 2.20613, -3.4)

[node name="platform7" parent="World" instance=ExtResource("16_82380")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -34.9883, 2.20613, -5.4)

[node name="platform-medium" parent="World" instance=ExtResource("17_qgsha")]
transform = Transform3D(0.86084, 0, -0.508876, 0, 1, 0, 0.508876, 0, 0.86084, -5.83677, 1.85731, 1.13776)

[node name="platform-medium2" parent="World" instance=ExtResource("17_qgsha")]
transform = Transform3D(0.997325, 0, 0.073099, 0, 1, 0, -0.073099, 0, 0.997325, -20.3597, 4.41057, 6.41009)

[node name="platform-falling" parent="World" instance=ExtResource("18_x8jhr")]
transform = Transform3D(0.989985, 0, -0.141178, 0, 1, 0, 0.141178, 0, 0.989985, -9.67817, 1.89327, -0.633746)

[node name="platform-grass-large-round" parent="World" instance=ExtResource("19_qait6")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.498435, 1.04456, 6.24435)

[node name="platform-grass-large-round3" parent="World" instance=ExtResource("19_qait6")]
transform = Transform3D(-0.989085, 0, 0.147343, 0, 1, 0, -0.147343, 0, -0.989085, -2.63518, 0.951342, 3.40817)

[node name="platform-grass-large-round4" parent="World" instance=ExtResource("19_qait6")]
transform = Transform3D(-0.294924, 0, 0.955521, 0, 1, 0, -0.955521, 0, -0.294924, 0.406457, 0.754891, 5.06137)

[node name="coin" parent="World" instance=ExtResource("20_lfsn4")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.54416, 2.55254, 1.27727)

[node name="cube8" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.5495, 1.10741, -2.666)

[node name="cube9" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(1.27593, -0.401864, 0.422933, 0.471408, 1.30937, -0.178025, -0.343721, 0.304009, 1.32582, 3.33538, 1.37146, -4.1932)

[node name="cube10" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(1.32811, 0.370441, 0.259369, -0.293866, 1.3186, -0.37854, -0.34372, 0.30401, 1.32582, -10.5752, 2.03819, -7.93707)

[node name="cube11" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(0.476646, 0.924607, 0.941422, -0.929853, 0.945559, -0.457882, -0.93624, -0.468385, 0.934042, -11.1815, 2.03819, 9.2812)

[node name="cube12" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(-1.02876, -0.695523, 0.652886, -0.929853, 0.945557, -0.457881, -0.213027, -0.768461, -1.15432, -10.9158, 2.79508, 11.515)

[node name="cube13" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(1.56209, -1.37982, 1.71508, 1.97375, 1.80907, -0.342241, -0.974547, 1.4522, 2.05595, -14.3045, 2.03819, -8.24191)

[node name="cube14" parent="World" instance=ExtResource("21_dryjk")]
transform = Transform3D(1.56209, -1.37982, 1.71508, 1.97375, 1.80907, -0.342241, -0.974547, 1.4522, 2.05595, -15.866, 2.03819, 7.83702)

[node name="Sun" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.422618, -0.694272, 0.582563, 0, 0.642788, 0.766044, -0.906308, 0.323744, -0.271654, 0, 0, 0)
shadow_enabled = true
shadow_opacity = 0.75

[node name="HUD" type="CanvasLayer" parent="." groups=["HUD"]]
process_mode = 3
script = ExtResource("22_1dx8f")

[node name="Control" type="Control" parent="HUD"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="Icon" type="TextureRect" parent="HUD/Control"]
layout_mode = 0
offset_left = 57.0
offset_top = 67.0
offset_right = 313.0
offset_bottom = 323.0
scale = Vector2(0.2, 0.2)
texture = ExtResource("23_324j0")

[node name="x" type="Label" parent="HUD/Control"]
layout_mode = 0
offset_left = 112.0
offset_top = 64.0
offset_right = 144.0
offset_bottom = 123.0
text = "×"
label_settings = ExtResource("24_6hsja")

[node name="Level Complete" type="Label" parent="HUD/Control"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -429.0
offset_top = 139.0
offset_right = 429.0
offset_bottom = 287.0
grow_horizontal = 2
text = "Level Complete!"
label_settings = SubResource("LabelSettings_ri8jt")

[node name="CoinsLabel" type="Label" parent="HUD/Control"]
unique_name_in_owner = true
layout_mode = 0
offset_left = 144.0
offset_top = 64.0
offset_right = 368.0
offset_bottom = 123.0
text = "0"
label_settings = ExtResource("24_6hsja")

[node name="PlayAgainButton" type="Button" parent="HUD/Control"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -196.0
offset_top = -258.0
offset_right = 196.0
offset_bottom = -122.0
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 0
theme = ExtResource("26_xw2uw")
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_constants/outline_size = 2
theme_override_fonts/font = ExtResource("25_vfu23")
theme_override_font_sizes/font_size = 60
text = "Play Again?"
icon = ExtResource("27_ct75u")
flat = true
icon_alignment = 1

[node name="TimeLabel" type="Label" parent="HUD/Control"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -48.5
offset_top = 59.0
offset_right = 48.5
offset_bottom = 115.0
grow_horizontal = 2
text = "00"
label_settings = SubResource("LabelSettings_x4d2s")
horizontal_alignment = 1
vertical_alignment = 1

[node name="TimeNameLabel" type="Label" parent="HUD/Control"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -49.0
offset_top = 22.0
offset_right = 49.0
offset_bottom = 78.0
grow_horizontal = 2
text = "TIME"
label_settings = SubResource("LabelSettings_v6r7m")
horizontal_alignment = 1
vertical_alignment = 1

[connection signal="coin_collected" from="Player" to="HUD" method="_on_coin_collected"]
[connection signal="reached_goal" from="Player" to="HUD" method="_on_player_reached_goal"]
[connection signal="pressed" from="HUD/Control/PlayAgainButton" to="HUD" method="_on_play_again_button_pressed"]
23 changes: 13 additions & 10 deletions scripts/button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends Node3D
@export var pressed_by_default : bool
@onready var animation_player: AnimationPlayer = $AnimationPlayer
var button_state : bool = false
@onready var cooldown_timer: Timer = $CooldownTimer

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Expand All @@ -18,13 +19,15 @@ func _process(_delta: float) -> void:
pass

func _on_button_area_3d_area_entered(_area: Area3D) -> void:
if not animation_player.is_playing():
if button_state:
button_state = false
animation_player.play("toggle-off")
else:
button_state = true
animation_player.play("toggle-on")

if target and target.has_method("receive_input"):
target.receive_input(button_state)
if cooldown_timer.is_stopped():
cooldown_timer.start()
if not animation_player.is_playing():
if button_state:
button_state = false
animation_player.play("toggle-off")
else:
button_state = true
animation_player.play("toggle-on")

if target and target.has_method("receive_input"):
target.receive_input(button_state)

0 comments on commit c303b75

Please sign in to comment.