diff options
Diffstat (limited to 'client/player/character')
| -rw-r--r-- | client/player/character/character.gd | 106 | ||||
| -rw-r--r-- | client/player/character/character.tscn | 8 | 
2 files changed, 61 insertions, 53 deletions
diff --git a/client/player/character/character.gd b/client/player/character/character.gd index 66a3435b..65275549 100644 --- a/client/player/character/character.gd +++ b/client/player/character/character.gd @@ -42,11 +42,16 @@ var current_animation := "idle"  @onready var tie = $Main/Tie  @onready var knife = $Main/HandRight/Knife -@onready var hairstyles := { -	"Brown": $Main/HeadDefault/Hair, -	"Blond": $Main/HeadDefault/Hair2, -	"E. Parsley": $Main/HeadDefault/Hair3 -} +const NUM_COLORS = 5; +const NUM_HAIRS = 3; +@onready var hairstyles := [$Main/HeadDefault/Hair, $Main/HeadDefault/Hair2, $Main/HeadDefault/Hair3] +var colors = [ +	Color(0.204, 0.361, 0.624), +	Color(0.568, 0.256, 0.602), +	Color(0.575, 0.341, 0.117), +	Color(0.3, 0.455, 0.221), +	Color(0.101, 0.452, 0.521) +]  @onready var head_default: MeshInstance3D = $Main/HeadDefault  @onready var head_robot: MeshInstance3D = $Main/HeadRobot @@ -54,28 +59,41 @@ var current_animation := "idle"  @onready var step_sounds: PlayRandom = $Steps  @onready var boost_sounds: PlayRandom = $Boosts +class ParsedStyle: +	var color: int +	var hair: int +	var robot: bool +	var customer: bool +	func _init(n: int) -> void: +		customer = n < 0 +		if customer: n *= -1 +		if n == 51: robot = true +		else: +			hair = n % NUM_HAIRS +			color = n / NUM_HAIRS % NUM_COLORS +	func pack() -> int: +		if robot: return 51 +		return (hair + color * NUM_HAIRS) * (-1 if customer else 1) +  func _ready():  	play_animation("idle")  var t := 0.0  func _process(delta): -	if walking: -		t += delta -		main_height_target = default_height + sin(t * WALK_ANIM_SPEED) * WALK_ANIM_STRENGTH -	else: -		t = 0 +	t += delta +	if walking: main_height_target = default_height + sin(t * WALK_ANIM_SPEED) * WALK_ANIM_STRENGTH +	else: t = 0  	main.position.y = main_height_target  	# Update animation:  	var next_animation: String -	if holding: -		next_animation = "hold" -	elif cutting: -		next_animation = "cut" -	elif walking: -		next_animation = "walk" -	else: -		next_animation = "idle" +	if holding: next_animation = "hold" +	elif cutting: next_animation = "cut" +	elif walking: next_animation = "walk" +	else: next_animation = "idle" +	 +	if current_animation != next_animation: +		play_animation(next_animation)  	walking_particles.emitting = walking  	if boosting and walking and not was_boosting: @@ -85,47 +103,31 @@ func _process(delta):  		boosting_particles.emitting = false  	was_boosting = boosting and walking -	if current_animation != next_animation: -		play_animation(next_animation) - -func select_hairstyle(id: int): -	if id == 51: -		toggle_robot(true) -		return -	if id < 0: -		to_customer() -		id *= -1 -	var hairstyle_count = hairstyles.keys().size() -	id = id % hairstyle_count -	var target = hairstyles.keys()[id] -	for k in hairstyles.keys(): -		if k == target: -			hairstyles[k].show() -		else: -			hairstyles[k].hide() - -func to_customer(): -	main.mesh = CUSTOMER_MAIN_MESH -	tie.queue_free() +func set_style(id: int): +	var p = ParsedStyle.new(id) +	set_customer(p.customer) +	set_robot(p.robot) +	for h in hairstyles: h.hide() +	hairstyles[p.hair].show() +	$Main.get_active_material(0).albedo_color = colors[p.color] -func toggle_robot(b: bool): +func set_customer(b: bool):  	if b: -		head_robot.show() -		head_default.hide() -		main.mesh = ROBOT_MAIN_MESH -	else: -		head_robot.hide() -		head_default.show() -		main.mesh = DEFAULT_MAIN_MESH +		main.mesh = CUSTOMER_MAIN_MESH +		tie.queue_free() +	else: pass # TODO + +func set_robot(b: bool): +	head_robot.visible = b +	head_default.visible = not b +	main.mesh = ROBOT_MAIN_MESH if b else DEFAULT_MAIN_MESH  func play_animation(name_: String):  	current_animation = name_  	hand_animations.play(name_) -	if name_ == "walk": -		step_sounds.start_autoplay() -	else: -		step_sounds.stop_autoplay() +	if name_ == "walk": step_sounds.start_autoplay() +	else: step_sounds.stop_autoplay()  	knife.visible = name_ == "cut" diff --git a/client/player/character/character.tscn b/client/player/character/character.tscn index a7c09c01..aca0658a 100644 --- a/client/player/character/character.tscn +++ b/client/player/character/character.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=27 format=3 uid="uid://b3hhir2fvnunu"] +[gd_scene load_steps=28 format=3 uid="uid://b3hhir2fvnunu"]  [ext_resource type="Script" path="res://player/character/character.gd" id="1_12lbh"]  [ext_resource type="ArrayMesh" uid="uid://bnmm01yjwultj" path="res://player/character/default/main.res" id="2_uovyg"] @@ -18,6 +18,11 @@  [ext_resource type="AudioStream" uid="uid://1jsqpnk3igj3" path="res://player/sounds/woosh1.ogg" id="14_ikcec"]  [ext_resource type="AudioStream" uid="uid://cwme7eatip0jc" path="res://player/sounds/woosh2.ogg" id="15_iv4wu"] +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_7ojaw"] +resource_local_to_scene = true +resource_name = "main" +cull_mode = 2 +  [sub_resource type="Animation" id="Animation_tdhvg"]  length = 0.001  tracks/0/type = "bezier" @@ -729,6 +734,7 @@ script = ExtResource("1_12lbh")  transform = Transform3D(0.33, 0, 0, 0, 0.33, 0, 0, 0, 0.33, 0, 0.33, 0)  mesh = ExtResource("2_uovyg")  skeleton = NodePath("") +surface_material_override/0 = SubResource("StandardMaterial3D_7ojaw")  [node name="HandRight" type="MeshInstance3D" parent="Main"]  transform = Transform3D(0.287144, 0.2864, -1.17785e-06, 0.402357, -0.133775, 0.337554, 0.292329, -0.0971941, -0.464603, -1.302, -0.17, 0)  |