feat: add user interaction with the task zones
This commit is contained in:
@@ -75,10 +75,17 @@ skeleton = NodePath("../../..")
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.18380833, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.18380833, 0)
|
||||||
shape = SubResource("BoxShape3D_lquwl")
|
shape = SubResource("BoxShape3D_lquwl")
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody3D" parent="." node_paths=PackedStringArray("camera_rig")]
|
[node name="Player" type="CharacterBody3D" parent="." node_paths=PackedStringArray("camera_rig", "simulation_manager", "farm_zone", "forest_zone", "food_zone", "guard_zone", "study_zone")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
|
||||||
script = ExtResource("1_h2yge")
|
script = ExtResource("1_h2yge")
|
||||||
camera_rig = NodePath("../CameraRig")
|
camera_rig = NodePath("../CameraRig")
|
||||||
|
simulation_manager = NodePath("../SimulationManager")
|
||||||
|
farm_zone = NodePath("../TaskZone/FarmZone")
|
||||||
|
forest_zone = NodePath("../TaskZone/ForestZone")
|
||||||
|
food_zone = NodePath("../TaskZone/FoodZone")
|
||||||
|
guard_zone = NodePath("../TaskZone/GuardZone")
|
||||||
|
study_zone = NodePath("../TaskZone/StudyZone")
|
||||||
|
stomach_capacity_for_food = 10
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
|
||||||
@@ -185,9 +192,10 @@ offset_bottom = 140.0
|
|||||||
[node name="MarginContainer" type="MarginContainer" parent="UI/VillagePanel"]
|
[node name="MarginContainer" type="MarginContainer" parent="UI/VillagePanel"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_constants/margin_left = 12
|
theme_override_constants/margin_left = 12
|
||||||
theme_override_constants/margin_top = 12
|
theme_override_constants/margin_top = 4
|
||||||
theme_override_constants/margin_right = 12
|
theme_override_constants/margin_right = 12
|
||||||
theme_override_constants/margin_bottom = 12
|
theme_override_constants/margin_bottom = 4
|
||||||
|
|
||||||
[node name="VillageStatsLabel" type="Label" parent="UI/VillagePanel/MarginContainer"]
|
[node name="VillageStatsLabel" type="Label" parent="UI/VillagePanel/MarginContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/font_size = 10
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ extends CharacterBody3D
|
|||||||
@export var rotation_speed := 12.0
|
@export var rotation_speed := 12.0
|
||||||
@export var camera_rig: Node3D
|
@export var camera_rig: Node3D
|
||||||
|
|
||||||
|
@export var simulation_manager: Node
|
||||||
|
|
||||||
|
@export var farm_zone: Marker3D
|
||||||
|
@export var forest_zone: Marker3D
|
||||||
|
@export var food_zone: Marker3D
|
||||||
|
@export var guard_zone: Marker3D
|
||||||
|
@export var study_zone: Marker3D
|
||||||
|
|
||||||
|
@export var stomach_capacity_for_food := 5
|
||||||
|
@export var interaction_range := 3.0
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
var input := Input.get_vector(
|
var input := Input.get_vector(
|
||||||
"move_left",
|
"move_left",
|
||||||
@@ -39,3 +50,36 @@ func _physics_process(delta: float) -> void:
|
|||||||
if direction.length() > 0.01:
|
if direction.length() > 0.01:
|
||||||
var target_angle := atan2(direction.x, direction.z)
|
var target_angle := atan2(direction.x, direction.z)
|
||||||
rotation.y = lerp_angle(rotation.y, target_angle, rotation_speed * delta)
|
rotation.y = lerp_angle(rotation.y, target_angle, rotation_speed * delta)
|
||||||
|
|
||||||
|
|
||||||
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
|
# keep your camera mouse code here too
|
||||||
|
if event.is_action_pressed("interact"):
|
||||||
|
try_interact()
|
||||||
|
|
||||||
|
|
||||||
|
func try_interact() -> void:
|
||||||
|
if simulation_manager == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
if is_near(farm_zone):
|
||||||
|
simulation_manager.add_food(5.0)
|
||||||
|
print("Player gathered food for the village.")
|
||||||
|
elif is_near(forest_zone):
|
||||||
|
simulation_manager.add_wood(5.0)
|
||||||
|
print("Player gathered wood for the village.")
|
||||||
|
elif is_near(guard_zone):
|
||||||
|
simulation_manager.add_safety(3.0)
|
||||||
|
print("Player helped guard the village.")
|
||||||
|
elif is_near(study_zone):
|
||||||
|
simulation_manager.add_knowledge(2.0)
|
||||||
|
print("Player shared knowledge.")
|
||||||
|
elif is_near(food_zone):
|
||||||
|
simulation_manager.eat_food(stomach_capacity_for_food)
|
||||||
|
print("Player eating shit up.")
|
||||||
|
|
||||||
|
func is_near(zone: Marker3D) -> bool:
|
||||||
|
if zone == null:
|
||||||
|
return false
|
||||||
|
|
||||||
|
return global_position.distance_to(zone.global_position) <= interaction_range
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ move_right={
|
|||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Interaction={
|
interact={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ var village := SimVillage.new()
|
|||||||
const DEBUG_LOGS := true
|
const DEBUG_LOGS := true
|
||||||
|
|
||||||
var npcs: Array[SimNPC] = []
|
var npcs: Array[SimNPC] = []
|
||||||
var tick_interval := 1.0
|
var tick_interval := 1.2
|
||||||
var tick_timer := 0.0
|
var tick_timer := 0.0
|
||||||
var tick_count := 0
|
var tick_count := 0
|
||||||
|
|
||||||
var names := [
|
var names := [
|
||||||
"Rafi", "Mira", "Adem", "Nura", "Sahin",
|
"Amina", "Tarik", "Jasmin"
|
||||||
"Lejla", "Tarik", "Hana", "Idris", "Zejd"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
var professions := [
|
var professions := [
|
||||||
@@ -38,7 +37,7 @@ func _process(delta: float) -> void:
|
|||||||
simulate_tick()
|
simulate_tick()
|
||||||
|
|
||||||
func generate_npcs() -> void:
|
func generate_npcs() -> void:
|
||||||
for i in range(10):
|
for i in range(names.size()):
|
||||||
var npc := SimNPC.new(
|
var npc := SimNPC.new(
|
||||||
i,
|
i,
|
||||||
names[i],
|
names[i],
|
||||||
@@ -78,6 +77,10 @@ func simulate_tick() -> void:
|
|||||||
village_changed.emit(village)
|
village_changed.emit(village)
|
||||||
if DEBUG_LOGS:
|
if DEBUG_LOGS:
|
||||||
print(village.get_summary())
|
print(village.get_summary())
|
||||||
|
|
||||||
|
func eat_food(amount: float) -> void:
|
||||||
|
village.food -= amount
|
||||||
|
village_changed.emit(village)
|
||||||
|
|
||||||
func add_food(amount: float) -> void:
|
func add_food(amount: float) -> void:
|
||||||
village.food += amount
|
village.food += amount
|
||||||
|
|||||||
Reference in New Issue
Block a user