commit dd2aae85a13e0c9c65687c6ee478ce90881f8c4e
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date: Mon, 20 Sep 2021 15:23:47 +0300
First commit.
Diffstat:
9 files changed, 265 insertions(+), 0 deletions(-)
diff --git a/Camera.gd b/Camera.gd
@@ -0,0 +1,13 @@
+extends Camera
+
+
+var offset
+onready var player: KinematicBody = get_parent().get_node("Player")
+
+
+func _ready() -> void:
+ offset = translation - player.translation
+
+
+func _physics_process(delta: float) -> void:
+ translation = player.translation + offset
diff --git a/HUD.gd b/HUD.gd
@@ -0,0 +1,11 @@
+extends Control
+
+
+onready var speed_label: Label = $SpeedHBoxContainer/SpeedLabel
+
+
+func _on_Player_speed_changed(new_speed: int) -> void:
+ var number_of_speed_bars: int = new_speed / 10
+ speed_label.text = "=".repeat(number_of_speed_bars)
+ print_debug(speed_label.text)
+
diff --git a/Level1.gd b/Level1.gd
@@ -0,0 +1,20 @@
+extends Spatial
+
+
+# Declare member variables here. Examples:
+# var a: int = 2
+# var b: String = "text"
+
+
+# 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_Player_off_the_deep_end() -> void:
+ get_tree().reload_current_scene()
diff --git a/Level1.tscn b/Level1.tscn
@@ -0,0 +1,73 @@
+[gd_scene load_steps=7 format=2]
+
+[ext_resource path="res://Camera.gd" type="Script" id=1]
+[ext_resource path="res://Player.gd" type="Script" id=2]
+[ext_resource path="res://HUD.gd" type="Script" id=3]
+[ext_resource path="res://Level1.gd" type="Script" id=4]
+
+[sub_resource type="SpatialMaterial" id=1]
+albedo_color = Color( 0.482353, 0.980392, 0.572549, 1 )
+
+[sub_resource type="BoxShape" id=2]
+extents = Vector3( 0.125, 0.075, 0.15 )
+
+[node name="Level1" type="Spatial"]
+script = ExtResource( 4 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 0.964893, 0.262644, 0, -0.262644, 0.964893, 0, 0.937895, 0.953137 )
+script = ExtResource( 1 )
+
+[node name="CSGBox" type="CSGBox" parent="."]
+use_collision = true
+width = 1.0
+height = 0.5
+depth = 33.62
+
+[node name="Player" type="KinematicBody" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.336291, 0 )
+script = ExtResource( 2 )
+
+[node name="CSGBox2" type="CSGBox" parent="Player"]
+width = 0.25
+height = 0.15
+depth = 0.3
+material = SubResource( 1 )
+
+[node name="CollisionShape" type="CollisionShape" parent="Player"]
+shape = SubResource( 2 )
+
+[node name="ForwardSpeedChangeTimer" type="Timer" parent="Player"]
+wait_time = 0.2
+one_shot = true
+
+[node name="HUD" type="Control" parent="."]
+margin_right = 40.0
+margin_bottom = 40.0
+script = ExtResource( 3 )
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="SpeedHBoxContainer" type="HBoxContainer" parent="HUD"]
+margin_left = 447.357
+margin_top = 531.447
+margin_right = 522.357
+margin_bottom = 571.447
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="Label" type="Label" parent="HUD/SpeedHBoxContainer"]
+margin_top = 13.0
+margin_right = 43.0
+margin_bottom = 27.0
+text = "Speed:"
+
+[node name="SpeedLabel" type="Label" parent="HUD/SpeedHBoxContainer"]
+margin_left = 47.0
+margin_top = 13.0
+margin_right = 47.0
+margin_bottom = 27.0
+[connection signal="off_the_deep_end" from="Player" to="." method="_on_Player_off_the_deep_end"]
+[connection signal="speed_changed" from="Player" to="HUD" method="_on_Player_speed_changed"]
diff --git a/Player.gd b/Player.gd
@@ -0,0 +1,73 @@
+extends KinematicBody
+
+
+const fall_acceleration: float = 2.0
+const jump_impulse: float = 1.0
+const maximum_forward_speed: int = 200
+const forward_speed_increment: int = 20
+const side_speed: float = 50.0
+
+
+var velocity: Vector3 = Vector3.ZERO
+var driving_speed: int = 0
+var direction: int = 0
+
+
+signal speed_changed
+signal off_the_deep_end
+
+
+onready var forward_speed_change_timer: Timer = $ForwardSpeedChangeTimer
+
+
+func _ready() -> void:
+ connect("off_the_deep_end", self, "on_off_the_deep_end")
+ print_debug(forward_speed_change_timer.time_left)
+ forward_speed_change_timer
+
+
+func on_off_the_deep_end() -> void:
+ print_debug("off the deep end")
+
+
+func _physics_process(delta: float) -> void:
+ if is_on_floor():
+ if Input.is_action_just_pressed("ui_right"): # and Input.is_action_pressed("ui_left"):
+ direction = 1
+ if Input.is_action_just_pressed("ui_left"): # and Input.is_action_pressed("ui_right"):
+ direction = -1
+ if Input.is_action_just_released("ui_right"):
+ if Input.is_action_pressed("ui_left"):
+ direction = -1
+ else:
+ direction = 0
+ if Input.is_action_just_released("ui_left"):
+ if Input.is_action_pressed("ui_right"):
+ direction = 1
+ else:
+ direction = 0
+ if Input.is_action_pressed("ui_up") and forward_speed_change_timer.time_left == 0.0:
+ print_debug(forward_speed_change_timer.time_left)
+ forward_speed_change_timer.start()
+ driving_speed += forward_speed_increment
+ driving_speed = clamp(driving_speed, 0, maximum_forward_speed)
+ emit_signal("speed_changed", driving_speed)
+ if Input.is_action_pressed("ui_down") and forward_speed_change_timer.time_left == 0.0:
+ print_debug(forward_speed_change_timer.time_left)
+ forward_speed_change_timer.start()
+ driving_speed -= forward_speed_increment
+ driving_speed = clamp(driving_speed, 0, maximum_forward_speed)
+ emit_signal("speed_changed", driving_speed)
+
+
+ velocity.x = direction * side_speed * delta
+ velocity.z = -driving_speed * delta
+
+ if is_on_floor() and Input.is_action_just_pressed("jump"):
+ velocity.y += jump_impulse
+ velocity.y -= fall_acceleration * delta
+
+ velocity = move_and_slide(velocity, Vector3.UP)
+
+ if translation.y < 0:
+ emit_signal("off_the_deep_end")
diff --git a/default_env.tres b/default_env.tres
@@ -0,0 +1,7 @@
+[gd_resource type="Environment" load_steps=2 format=2]
+
+[sub_resource type="ProceduralSky" id=1]
+
+[resource]
+background_mode = 2
+background_sky = SubResource( 1 )
diff --git a/icon.png b/icon.png
Binary files differ.
diff --git a/icon.png.import b/icon.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.png"
+dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=true
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+stream=false
+size_limit=0
+detect_3d=true
+svg/scale=1.0
diff --git a/project.godot b/project.godot
@@ -0,0 +1,34 @@
+; Engine configuration file.
+; It's best edited using the editor UI and not directly,
+; since the parameters that go here are not all obvious.
+;
+; Format:
+; [section] ; section goes between []
+; param=value ; assign values to parameters
+
+config_version=4
+
+_global_script_classes=[ ]
+_global_script_class_icons={
+
+}
+
+[application]
+
+config/name="spacevroom"
+config/icon="res://icon.png"
+
+[input]
+
+jump={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
+ ]
+}
+
+[rendering]
+
+quality/driver/driver_name="GLES2"
+vram_compression/import_etc=true
+vram_compression/import_etc2=false
+environment/default_environment="res://default_env.tres"