Villager and Cultist changes

This commit is contained in:
ncusimano 2023-08-20 13:31:07 -06:00
parent 3bf7a73c1b
commit 47b6c465de
8 changed files with 61 additions and 6 deletions

View File

@ -31,6 +31,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -22, 3, 43)
[node name="Node3D2" parent="." instance=ExtResource("3_renxb")] [node name="Node3D2" parent="." instance=ExtResource("3_renxb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 29, 4, 33) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 29, 4, 33)
walk_chance = 0.1
spin_chance = 0.2
walk_speed = 0.5
dir_correction_rate = 0.95
dir_accuracy = 0.00174533
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] [node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = SubResource("CylinderMesh_c2b6h") mesh = SubResource("CylinderMesh_c2b6h")

View File

@ -23,7 +23,7 @@
[ext_resource type="PackedScene" uid="uid://c4s6y758n77lw" path="res://villager_shared.tscn" id="24_ddfvk"] [ext_resource type="PackedScene" uid="uid://c4s6y758n77lw" path="res://villager_shared.tscn" id="24_ddfvk"]
[ext_resource type="PackedScene" uid="uid://b3aus2kigf8xt" path="res://Models/beach_decor/cooler.tscn" id="24_sl7ne"] [ext_resource type="PackedScene" uid="uid://b3aus2kigf8xt" path="res://Models/beach_decor/cooler.tscn" id="24_sl7ne"]
[ext_resource type="PackedScene" uid="uid://cft26nug7kyqb" path="res://ambient_light_1.tscn" id="25_novxt"] [ext_resource type="PackedScene" uid="uid://cft26nug7kyqb" path="res://ambient_light_1.tscn" id="25_novxt"]
[ext_resource type="PackedScene" uid="uid://ukful430mmkn" path="res://color_cube.tscn" id="25_rm0cr"] [ext_resource type="PackedScene" path="res://color_cube.tscn" id="25_rm0cr"]
[ext_resource type="PackedScene" uid="uid://bw3k2c75qavce" path="res://Models/beach_decor/bucket.tscn" id="27_f3p1i"] [ext_resource type="PackedScene" uid="uid://bw3k2c75qavce" path="res://Models/beach_decor/bucket.tscn" id="27_f3p1i"]
[ext_resource type="PackedScene" uid="uid://g4gmc0pwlak1" path="res://Models/buildings/fence.tscn" id="28_prydb"] [ext_resource type="PackedScene" uid="uid://g4gmc0pwlak1" path="res://Models/buildings/fence.tscn" id="28_prydb"]

View File

@ -3,6 +3,39 @@ class_name Villager
var color_changes = true var color_changes = true
var hp = 100
var aggressor
func _process(delta):
super._process(delta)
if task == "become_corrupted":
become_corrupted()
func become_corrupted():
if location_xz.distance_to(aggressor.location_xy) <= 1:
# Spin for effect and lose hp.
rotate_y(deg_to_rad(-15))
hp -= 0.5
else:
hp = 100
task = "idle"
# Create a new cultist and then destroy self.
if hp <= 0:
# Disable hitbox
$slime_collision.disabled = true
$CollisionDetection/slime_collision.disabled = true
# Load and instantiate a new cultist.
var cultist = load("res://cultist.tscn")
cultist = cultist.instantiate()
get_tree().get_root().add_child(cultist)
cultist.location_xz = location_xz
# Destroy self.
queue_free()
func get_color_idx() -> int: func get_color_idx() -> int:
return $slime.color_idx return $slime.color_idx
@ -24,3 +57,7 @@ func _on_area_3d_body_entered(body):
$slime.change_color(other) $slime.change_color(other)
func _on_collision_detection_body_entered(body):
if body.is_class("Cultist"):
aggressor = body
task = "become_corrupted"

View File

@ -7,8 +7,17 @@ func _process(delta):
super._process(delta) super._process(delta)
if task == "corrupt": if task == "corrupt":
pass corrupt()
func corrupt():
# Make sure the victim is still next to the cultist.
if location_xz.distance_to(victim.location_xy) <= 1 and victim != null:
rotate_y(deg_to_rad(15))
if victim.hp <= 0:
$evilslime.play()
task = "idle"
else:
task = "idle"
# For corruption detection range. # For corruption detection range.
func _on_target_radius_body_entered(body): func _on_target_radius_body_entered(body):

View File

@ -1,16 +1,17 @@
[gd_scene load_steps=6 format=3 uid="uid://e0s4phx2jiit"] [gd_scene load_steps=7 format=3 uid="uid://e0s4phx2jiit"]
[ext_resource type="Script" path="res://cultist.gd" id="1_k6djk"] [ext_resource type="Script" path="res://cultist.gd" id="1_k6djk"]
[ext_resource type="PackedScene" uid="uid://c3q6fva1c1baa" path="res://Models/slime.tscn" id="2_004fn"] [ext_resource type="PackedScene" uid="uid://c3q6fva1c1baa" path="res://Models/slime.tscn" id="2_004fn"]
[ext_resource type="AudioStream" uid="uid://cxadu5w3jwv0b" path="res://Sounds/evilslime.ogg" id="3_novm4"]
[sub_resource type="SphereShape3D" id="SphereShape3D_rypky"] [sub_resource type="SphereShape3D" id="SphereShape3D_rypky"]
radius = 5.0 radius = 5.0
[sub_resource type="SphereShape3D" id="SphereShape3D_pa038"] [sub_resource type="SphereShape3D" id="SphereShape3D_pa038"]
radius = 3.0 radius = 0.05
[sub_resource type="SphereShape3D" id="SphereShape3D_bmc5i"] [sub_resource type="SphereShape3D" id="SphereShape3D_bmc5i"]
radius = 0.3 radius = 0.05
[node name="Cultist" type="CharacterBody3D"] [node name="Cultist" type="CharacterBody3D"]
script = ExtResource("1_k6djk") script = ExtResource("1_k6djk")
@ -30,5 +31,8 @@ shape = SubResource("SphereShape3D_pa038")
[node name="cultist_collision" type="CollisionShape3D" parent="."] [node name="cultist_collision" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_bmc5i") shape = SubResource("SphereShape3D_bmc5i")
[node name="evilslime" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("3_novm4")
[connection signal="body_entered" from="TargetRadius" to="." method="_on_target_radius_body_entered"] [connection signal="body_entered" from="TargetRadius" to="." method="_on_target_radius_body_entered"]
[connection signal="body_entered" from="CollisionDetection" to="." method="_on_collision_detection_body_entered"] [connection signal="body_entered" from="CollisionDetection" to="." method="_on_collision_detection_body_entered"]