M1b: survival stats, day/night, fire fuel, cooking, foraging, torches, death + grave
- Health, stamina, hunger, warmth and wet with HUD bars, status tags and clock - 20-minute day/night cycle with moon, stars and lit clouds - Campfire fuel (2 min start, 15 min max), heat radius, cooking needs a lit fire - Berry bushes (regrow 10 min), mushrooms, roasted mushroom, torch - Stamina costs for sprint, jump and harvest hits - Death respawns at island start and leaves a grave bag - Saves include stats, time of day, fire fuel, regrowth timers and graves - New test_survival_stats suite; tests fail if a script error aborts them
This commit is contained in:
@@ -26,6 +26,7 @@ var inventory := Inventory.new(40) ## slots 0-7 are the hotbar
|
||||
var selected := 0
|
||||
var ui_open := false ## set by the inventory screen; freezes look/move
|
||||
var hands: Node3D
|
||||
var survival: Node ## health / stamina / hunger / warmth (survival.gd)
|
||||
|
||||
var _gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity", 9.8)
|
||||
|
||||
@@ -36,6 +37,11 @@ func _ready() -> void:
|
||||
hands.name = "Hands"
|
||||
hands.player = self
|
||||
camera.add_child(hands)
|
||||
survival = preload("res://scripts/player/survival.gd").new()
|
||||
survival.name = "Survival"
|
||||
survival.player = self
|
||||
survival.world = get_parent()
|
||||
add_child(survival)
|
||||
|
||||
func held_item_id() -> String:
|
||||
var s = inventory.get_slot(selected)
|
||||
@@ -70,17 +76,21 @@ func _physics_process(delta: float) -> void:
|
||||
elif not is_on_floor():
|
||||
velocity.y -= _gravity * delta
|
||||
|
||||
if global_position.y < water_level - 0.6:
|
||||
survival.soak() # waist-deep or more: you're wet
|
||||
|
||||
var jump := Input.is_action_just_pressed("jump") and not ui_open
|
||||
if jump and is_on_floor():
|
||||
velocity.y = jump_velocity
|
||||
elif jump and global_position.y > float_y - 0.4 and global_position.y < float_y + 0.3:
|
||||
# Swim-jump: kick up out of the water to climb onto a bank.
|
||||
var can_swim_jump := global_position.y > float_y - 0.4 and global_position.y < float_y + 0.3
|
||||
if jump and (is_on_floor() or can_swim_jump) and survival.use_stamina(8.0):
|
||||
# (A swim-jump kicks you up out of the water onto a bank.)
|
||||
velocity.y = jump_velocity
|
||||
|
||||
var input_dir := Vector2.ZERO if ui_open else Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
var current_speed := sprint_speed if Input.is_key_pressed(KEY_SHIFT) else speed
|
||||
var sprinting: bool = Input.is_key_pressed(KEY_SHIFT) and direction.length() > 0.1 and not ui_open \
|
||||
and survival.use_stamina(14.0 * delta, true)
|
||||
var current_speed := sprint_speed if sprinting else speed
|
||||
if swimming:
|
||||
current_speed = swim_speed
|
||||
if direction:
|
||||
|
||||
Reference in New Issue
Block a user