added stamina and health bar, gold can now be picked up
This commit is contained in:
@@ -2,7 +2,7 @@ extends Camera3D
|
||||
|
||||
var height_target = position.y
|
||||
const CHANGE_AMT_ON_SCROLL = 4.0
|
||||
const CAM_CHANGE_SPEED = 2.0
|
||||
const CAM_CHANGE_SPEED = 4.0
|
||||
var MAX_CAM_HEIGHT = position.y + CHANGE_AMT_ON_SCROLL
|
||||
var MIN_CAM_HEIGHT = position.y - (CHANGE_AMT_ON_SCROLL * 2)
|
||||
|
||||
@@ -27,7 +27,7 @@ func camera_height_change(delta):
|
||||
if Input.is_action_just_pressed("scroll_down"):
|
||||
height_target = clamp(height_target + CHANGE_AMT_ON_SCROLL,MIN_CAM_HEIGHT,MAX_CAM_HEIGHT)
|
||||
|
||||
global_position.y = height_target
|
||||
global_position.y = lerp(global_position.y,height_target,delta * CAM_CHANGE_SPEED)
|
||||
#else:
|
||||
#var direction_to_target = global_position.y - height_target
|
||||
#var move_amount = direction_to_target * delta * CAM_CHANGE_SPEED
|
||||
|
||||
@@ -3,15 +3,13 @@ extends Node3D
|
||||
const GOLDCOIN = preload("res://Prefabs/goldcoin.tscn")
|
||||
|
||||
|
||||
|
||||
const MAX_AV = 15
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
var instance_coin = GOLDCOIN.instantiate()
|
||||
var av_x = randf_range(-10,10)
|
||||
var av_y = randf_range(-10,10)
|
||||
var av_z = randf_range(-10,10)
|
||||
|
||||
instance_coin.global_basis = global_basis
|
||||
var av_x = randf_range(-MAX_AV,MAX_AV)
|
||||
var av_y = randf_range(-MAX_AV,MAX_AV)
|
||||
var av_z = randf_range(-MAX_AV,MAX_AV)
|
||||
get_tree().current_scene.add_child(instance_coin)
|
||||
instance_coin.global_position = global_position
|
||||
instance_coin.angular_velocity = Vector3(av_x,av_y,av_z)
|
||||
get_tree().current_scene.add_child(instance_coin)
|
||||
|
||||
@@ -1,2 +1,24 @@
|
||||
extends RigidBody3D
|
||||
class_name Gold
|
||||
|
||||
var amount = 1
|
||||
var follow_target
|
||||
var spawn_out = false
|
||||
const SPAWN_OUT_SIZE = 4.0
|
||||
const SPAWN_OUT_HEIGHT = 14.0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if follow_target != null:
|
||||
if spawn_out:
|
||||
#if global_position.y < SPAWN_OUT_HEIGHT: REMOVED BECAUSE I DIDN'T LIKE THE LOOK, LEAVING FOR NOW IN CASE I WANT TO MAKE A DIFFERENT EFFECT HAPPEN
|
||||
#linear_velocity = Vector3(0,10,0)
|
||||
#else:
|
||||
follow_target.gold += amount
|
||||
queue_free()
|
||||
else:
|
||||
if global_position.distance_to(follow_target.global_position) < .5:
|
||||
spawn_out = true
|
||||
else:
|
||||
var direction_to_player = global_position.direction_to(follow_target.global_position)
|
||||
var distance_to_player = global_position.distance_to(follow_target.global_position)
|
||||
linear_velocity = direction_to_player * (5 + distance_to_player * 3)
|
||||
|
||||
@@ -7,7 +7,10 @@ var dodge_direction
|
||||
@onready var anim_player: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
var gold_to_vacuum = []
|
||||
var current_gold
|
||||
var gold = 0
|
||||
|
||||
const MAX_HEALTH : float = 100
|
||||
var health = MAX_HEALTH
|
||||
|
||||
const MAX_STAMINA : float = 100
|
||||
var stamina = MAX_STAMINA
|
||||
@@ -19,26 +22,11 @@ const DODGE_STAMINA_COST = 30.0
|
||||
func _physics_process(delta: float) -> void:
|
||||
stamina_regen(delta)
|
||||
move_and_slide()
|
||||
vacuum_found_gold()
|
||||
|
||||
func stamina_regen(delta):
|
||||
if stamina < MAX_STAMINA:
|
||||
print("STAMINA : ", stamina)
|
||||
stamina = clamp(stamina + delta * STAMINA_REGEN_RATE,0,MAX_STAMINA)
|
||||
|
||||
func vacuum_found_gold():
|
||||
if gold_to_vacuum.size() > 0:
|
||||
for i in range(0,gold_to_vacuum.size()):
|
||||
#var magnet_target
|
||||
#if i == 0:
|
||||
#magnet_target = self.global_position
|
||||
#else:
|
||||
#magnet_target = gold_to_vacuum[i-1].global_position
|
||||
var direction_to_player = gold_to_vacuum[i].global_position.direction_to(self.global_position)
|
||||
var distance_to_player = gold_to_vacuum[i].global_position.distance_to(self.global_position)
|
||||
|
||||
gold_to_vacuum[i].linear_velocity = direction_to_player * (5 + distance_to_player)
|
||||
|
||||
func _on_area_3d_body_entered(body: Node3D) -> void:
|
||||
if body is Gold:
|
||||
gold_to_vacuum.append(body)
|
||||
body.follow_target = self
|
||||
|
||||
@@ -2,11 +2,18 @@ extends Node3D
|
||||
|
||||
@export var player : Player
|
||||
|
||||
@onready var gold_label: Label = $Camera3D/Control/BoxContainer/GOLD
|
||||
@onready var health_bar: ProgressBar = $Camera3D/Control/BoxContainer/VBoxContainer/HealthBar
|
||||
@onready var stamina_bar: ProgressBar = $Camera3D/Control/BoxContainer/VBoxContainer/StaminaBar
|
||||
|
||||
|
||||
const CAM_MOVE_SPEED = 5
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
follow_player(delta)
|
||||
|
||||
gold_label.text = "Gold : " + str(player.gold)
|
||||
stamina_bar.value = player.stamina
|
||||
health_bar.value = player.health
|
||||
|
||||
func follow_player(delta):
|
||||
var player_pos = player.global_position
|
||||
|
||||
@@ -3,7 +3,7 @@ class_name PlayerState
|
||||
|
||||
@export var move_speed = 10.0
|
||||
@export var move_transition_speed = 10.0
|
||||
@export var health_lost_on_fall = 2.0
|
||||
@export var health_lost_on_fall = 20.0
|
||||
|
||||
# respawn after falling
|
||||
const FALL_TIME_TO_RESPAWN : float = 3.0
|
||||
@@ -32,6 +32,7 @@ func respawn_on_fall(delta):
|
||||
else:
|
||||
fall_timer = FALL_TIME_TO_RESPAWN
|
||||
character.global_position = ground_pos_cached[0]
|
||||
character.health -= health_lost_on_fall
|
||||
|
||||
func apply_gravity(delta):
|
||||
if !character.is_on_floor():
|
||||
|
||||
Reference in New Issue
Block a user