Compare commits

...

5 commits

Author SHA1 Message Date
9a0ff2dd1b world: added grass and sky 2026-01-22 21:48:53 +13:00
42de0ed122 player: organise code 2026-01-22 21:25:16 +13:00
e6cbaba0fa player: add health callbacks
Allows us to update the HUD on health change
2026-01-22 21:25:16 +13:00
47aa5ac9aa player: display health in HUD 2026-01-22 21:25:16 +13:00
df449af0f3 player: rename BackpackUI to HUD 2026-01-22 21:25:16 +13:00
6 changed files with 104 additions and 41 deletions

View file

@ -0,0 +1,9 @@
shader_type sky;
uniform vec3 skyColor : source_color;
uniform vec3 horizonColor : source_color;
void sky() {
float col = clamp(EYEDIR.y / 0.05, 0.0, 1.0);
vec3 finalColor = mix(horizonColor,skyColor,col);
COLOR = finalColor;
}

BIN
Textures/grass.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -1,19 +1,39 @@
[gd_scene load_steps=9 format=3 uid="uid://eiaw4xbs3suk"] [gd_scene load_steps=16 format=3 uid="uid://eiaw4xbs3suk"]
[ext_resource type="PackedScene" uid="uid://qb8cbljxgnub" path="res://world/killbrick.tscn" id="1_h2yge"] [ext_resource type="PackedScene" uid="uid://qb8cbljxgnub" path="res://world/killbrick.tscn" id="1_h2yge"]
[ext_resource type="PackedScene" uid="uid://cfceg80unq0pe" path="res://player/player.tscn" id="1_ig7tw"] [ext_resource type="PackedScene" uid="uid://cfceg80unq0pe" path="res://player/player.tscn" id="1_ig7tw"]
[ext_resource type="PackedScene" uid="uid://bcmrj6qkemrll" path="res://world/radiohead_cube.tscn" id="2_0xm2m"] [ext_resource type="PackedScene" uid="uid://bcmrj6qkemrll" path="res://world/radiohead_cube.tscn" id="2_0xm2m"]
[ext_resource type="Texture2D" uid="uid://dbapbvmrdkqht" path="res://Textures/grass.jpg" id="2_7mycd"]
[ext_resource type="PackedScene" uid="uid://of6tq8gpjxtu" path="res://gears/gear_pickup.tscn" id="3_lquwl"] [ext_resource type="PackedScene" uid="uid://of6tq8gpjxtu" path="res://gears/gear_pickup.tscn" id="3_lquwl"]
[ext_resource type="PackedScene" uid="uid://bafl8q0r61xrg" path="res://gears/gear.tscn" id="4_7mycd"] [ext_resource type="PackedScene" uid="uid://bafl8q0r61xrg" path="res://gears/gear.tscn" id="4_7mycd"]
[ext_resource type="Shader" uid="uid://c1fjj72syvy7l" path="res://Shaders/SkyShader.gdshader" id="7_272bh"]
[sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"] [sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"]
size = Vector3(100, 2, 100) size = Vector3(1000, 2, 1000)
[sub_resource type="BoxMesh" id="BoxMesh_ig7tw"] [sub_resource type="BoxMesh" id="BoxMesh_ig7tw"]
size = Vector3(100, 2, 100) size = Vector3(1000, 2, 1000)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ig7tw"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_272bh"]
albedo_color = Color(0.49454, 0.79, 0.4424, 1) albedo_texture = ExtResource("2_7mycd")
uv1_scale = Vector3(300, 300, 300)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_272bh"]
shader = ExtResource("7_272bh")
shader_parameter/skyColor = Color(0.4991548, 0.59654385, 0.98058206, 1)
shader_parameter/horizonColor = Color(0.64705884, 0.6901961, 0.8509804, 1)
[sub_resource type="Sky" id="Sky_7mycd"]
sky_material = SubResource("ShaderMaterial_272bh")
[sub_resource type="Environment" id="Environment_7mycd"]
background_mode = 2
sky = SubResource("Sky_7mycd")
sky_rotation = Vector3(6.2831855, 0, 0)
[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_272bh"]
[sub_resource type="Compositor" id="Compositor_5vw27"]
[node name="Main" type="Node3D"] [node name="Main" type="Node3D"]
@ -26,7 +46,7 @@ shape = SubResource("BoxShape3D_7dm0k")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Baseplate"] [node name="MeshInstance3D" type="MeshInstance3D" parent="Baseplate"]
mesh = SubResource("BoxMesh_ig7tw") mesh = SubResource("BoxMesh_ig7tw")
surface_material_override/0 = SubResource("StandardMaterial3D_ig7tw") surface_material_override/0 = SubResource("StandardMaterial3D_272bh")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.7071068, -0.49999994, 0.49999994, 0, 0.7071067, 0.7071067, -0.7071068, -0.49999994, 0.49999994, 50, 50, 50) transform = Transform3D(0.7071068, -0.49999994, 0.49999994, 0, 0.7071067, 0.7071067, -0.7071068, -0.49999994, 0.49999994, 50, 50, 50)
@ -52,3 +72,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 2, -21)
[node name="Gear" parent="GearPickup" instance=ExtResource("4_7mycd")] [node name="Gear" parent="GearPickup" instance=ExtResource("4_7mycd")]
transform = Transform3D(1, 0, 0, 0, -0.012967386, 0.9999159, 0, -0.9999159, -0.012967386, 0, 0.5, 0) transform = Transform3D(1, 0, 0, 0, -0.012967386, 0.9999159, 0, -0.9999159, -0.012967386, 0, 0.5, 0)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_7mycd")
camera_attributes = SubResource("CameraAttributesPractical_272bh")
compositor = SubResource("Compositor_5vw27")

View file

@ -10,37 +10,57 @@ const gear_slots = ["1", "2", "3"]
var starting_gear = preload("res://gears/ball.tscn") var starting_gear = preload("res://gears/ball.tscn")
var health = 100
var suspended = false var suspended = false
var direction = Vector3.ZERO var direction = Vector3.ZERO
var target_velocity = Vector3.ZERO var target_velocity = Vector3.ZERO
var _health = 100
# Player UI
func resize_ui(): func resize_ui():
var bpui_h = 200 var hud_h = 200
var size = get_viewport().get_visible_rect().size var size = get_viewport().get_visible_rect().size
$Message.size.x = size.x $Message.size.x = size.x
$BackpackUI.size.x = size.x $HUD.size.x = size.x
$BackpackUI.size.y = bpui_h $HUD.size.y = hud_h
$BackpackUI.position.x = 0 $HUD.position.x = 0
$BackpackUI.position.y = size.y - bpui_h $HUD.position.y = size.y - hud_h
func make_backpack_ui(): func make_hud():
var text = "Holding " + $Pivot/Container/Gear.gear_name() var text = ""
for node in $Backpack.get_children(): for node in $Backpack.get_children():
if not node is Gear: if not node is Gear:
continue continue
text += "\n%s (%s)" % [node.gear_name(), node.name] text += "%s (%s)\n" % [node.gear_name(), node.name]
$BackpackUI.text = text text += "Holding " + $Pivot/Container/Gear.gear_name() + "\n"
text += str(health()) + " hp"
$HUD.text = text
func message(string): func message(string):
$Message.text = string $Message.text = string
$Message.visible = true $Message.visible = true
$Message/VanishTimer.start() $Message/VanishTimer.start()
# State functions
func harm(hp):
assert(hp >= 0)
_health -= hp
make_hud()
func heal(hp):
assert(hp >= 0)
_health += hp
make_hud()
func health():
return _health
func die(): func die():
suspended = true suspended = true
visible = false visible = false
$BackpackUI.visible = false $HUD.visible = false
# strip gears # strip gears
for gear in $Backpack.get_children(): for gear in $Backpack.get_children():
@ -53,7 +73,7 @@ func die():
func respawn(): func respawn():
position = Vector3(spawn) position = Vector3(spawn)
$CameraGimbal.reset() $CameraGimbal.reset()
health = 100 _health = 100
visible = true visible = true
suspended = false suspended = false
@ -61,8 +81,8 @@ func respawn():
var gear = starting_gear.instantiate() var gear = starting_gear.instantiate()
$Pivot/Container.add_child(gear) $Pivot/Container.add_child(gear)
make_backpack_ui() make_hud()
$BackpackUI.visible = true $HUD.visible = true
# Backpack functions # Backpack functions
@ -87,7 +107,7 @@ func use_backpack_slot(n):
old.reparent($Backpack, false) old.reparent($Backpack, false)
get_node(gear_node).reparent($Pivot/Container, false) get_node(gear_node).reparent($Pivot/Container, false)
get_node("Pivot/Container/" + n).name = "Gear" get_node("Pivot/Container/" + n).name = "Gear"
make_backpack_ui() make_hud()
return return
# couldn't find a free slot, so replace # couldn't find a free slot, so replace
# the new slot with the current gear # the new slot with the current gear
@ -95,7 +115,7 @@ func use_backpack_slot(n):
old.reparent($Backpack, false) old.reparent($Backpack, false)
old.name = n old.name = n
get_node("Pivot/Container/" + n).name = "Gear" get_node("Pivot/Container/" + n).name = "Gear"
make_backpack_ui() make_hud()
return return
func equip(gear: Gear): func equip(gear: Gear):
@ -120,14 +140,14 @@ func equip(gear: Gear):
new_gear = gear.duplicate() new_gear = gear.duplicate()
new_gear.name = "Gear" new_gear.name = "Gear"
$Pivot/Container.add_child(new_gear) $Pivot/Container.add_child(new_gear)
make_backpack_ui() make_hud()
message("You picked up a " + gear_name + "!") message("You picked up a " + gear_name + "!")
return true return true
# if no slots are free # if no slots are free
message("Backpack full") message("Backpack full")
return false return false
# Player movement and engine callbacks # Player mechanics
func move_player(x, z): func move_player(x, z):
var camera_basis = $CameraGimbal.get_global_transform().basis var camera_basis = $CameraGimbal.get_global_transform().basis
@ -148,19 +168,7 @@ func move_player(x, z):
if x != 0: if x != 0:
direction += camera_basis.x * x direction += camera_basis.x * x
func _ready(): func do_backpack_keys():
get_viewport().size_changed.connect(resize_ui)
resize_ui()
respawn()
func _physics_process(delta):
if suspended:
return
if health < 1 or position.y <= -1000:
die()
# UI and backpack keys
if Input.is_action_just_pressed("backpack_1"): if Input.is_action_just_pressed("backpack_1"):
use_backpack_slot("1") use_backpack_slot("1")
if Input.is_action_just_pressed("backpack_2"): if Input.is_action_just_pressed("backpack_2"):
@ -168,7 +176,7 @@ func _physics_process(delta):
if Input.is_action_just_pressed("backpack_3"): if Input.is_action_just_pressed("backpack_3"):
use_backpack_slot("3") use_backpack_slot("3")
# Movement keys func do_movement(delta):
var mx = 0 var mx = 0
var mz = 0 var mz = 0
@ -196,7 +204,7 @@ func _physics_process(delta):
move_and_slide() move_and_slide()
# Gear uses func do_gears():
var gear = $Pivot/Container/Gear var gear = $Pivot/Container/Gear
assert(gear is Gear) assert(gear is Gear)
if gear.continuous(): if gear.continuous():
@ -206,6 +214,27 @@ func _physics_process(delta):
if Input.is_action_just_pressed("gear_use"): if Input.is_action_just_pressed("gear_use"):
gear.use(self) gear.use(self)
# Engine callbacks
func _ready():
get_viewport().size_changed.connect(resize_ui)
resize_ui()
respawn()
func _physics_process(delta):
if health() < 1 or position.y <= -1000:
die()
if suspended:
return
# Backpack keys
do_backpack_keys()
# Movement
do_movement(delta)
# Use gears
do_gears()
# Signals # Signals
func _on_vanish_timer_timeout(): func _on_vanish_timer_timeout():

View file

@ -93,7 +93,7 @@ vertical_alignment = 1
wait_time = 4.0 wait_time = 4.0
one_shot = true one_shot = true
[node name="BackpackUI" type="Label" parent="."] [node name="HUD" type="Label" parent="."]
offset_right = 200.0 offset_right = 200.0
offset_bottom = 200.0 offset_bottom = 200.0
text = "Pictures of you" text = "Pictures of you"

View file

@ -2,4 +2,4 @@ extends Area3D
func _on_body_entered(body: Node3D): func _on_body_entered(body: Node3D):
if body is Player: if body is Player:
body.health = 0 body.die()