forked from 2121578/gai-ca2
BoatParrtProgress und CampUI hinzugefügt
parent
da1fdf10d0
commit
08647a4188
|
|
@ -3,15 +3,15 @@
|
||||||
importer="texture"
|
importer="texture"
|
||||||
type="CompressedTexture2D"
|
type="CompressedTexture2D"
|
||||||
uid="uid://di16cmfomo60u"
|
uid="uid://di16cmfomo60u"
|
||||||
path="res://.godot/imported/intro.png-5733d5421d999e0273f5c7e8c62d2491.ctex"
|
path="res://.godot/imported/Intro.png-ef37c38298536b7c161e4863253f3325.ctex"
|
||||||
metadata={
|
metadata={
|
||||||
"vram_texture": false
|
"vram_texture": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://assets/images/intro.png"
|
source_file="res://assets/images/Intro.png"
|
||||||
dest_files=["res://.godot/imported/intro.png-5733d5421d999e0273f5c7e8c62d2491.ctex"]
|
dest_files=["res://.godot/imported/Intro.png-ef37c38298536b7c161e4863253f3325.ctex"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -15,6 +15,7 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
||||||
@onready var time_of_day_bar: ProgressBar = %TimeOfDayBar
|
@onready var time_of_day_bar: ProgressBar = %TimeOfDayBar
|
||||||
|
|
||||||
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
|
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
|
||||||
|
var camp: CampManager = CampManager.new()
|
||||||
|
|
||||||
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
|
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
|
||||||
|
|
||||||
|
|
@ -25,217 +26,298 @@ var waiting_for_input: bool = true
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
tilemap_navigation.world = world
|
tilemap_navigation.world = world
|
||||||
tilemap_navigation.player = player
|
tilemap_navigation.player = player
|
||||||
player.game_manager = self
|
player.game_manager = self
|
||||||
world.camp_manager.game_manager = self
|
world.camp_manager.game_manager = self
|
||||||
world.step_visualizer.game_manager = self
|
world.step_visualizer.game_manager = self
|
||||||
world.step_visualizer.world = world
|
world.step_visualizer.world = world
|
||||||
update_bars()
|
camp.camp_add_item(tilemap_types.OBJECT_I_BERRY)
|
||||||
call_deferred("defer_ready")
|
camp.camp_add_item(tilemap_types.OBJECT_I_STICK)
|
||||||
|
update_bars()
|
||||||
|
update_camp_ui()
|
||||||
|
update_boat_progress()
|
||||||
|
call_deferred("defer_ready")
|
||||||
|
|
||||||
|
|
||||||
func defer_ready() -> void:
|
func defer_ready() -> void:
|
||||||
tree_visualizer.behavior_tree = player.behavior_tree
|
tree_visualizer.behavior_tree = player.behavior_tree
|
||||||
tree_visualizer.build_tree()
|
tree_visualizer.build_tree()
|
||||||
|
|
||||||
intro_image.visible = true
|
intro_image.visible = true
|
||||||
await wait_for_key_press()
|
await wait_for_key_press()
|
||||||
get_tree().create_tween().tween_method(set_intro_opacity, 1.0, 0.0, 1.0)
|
get_tree().create_tween().tween_method(set_intro_opacity, 1.0, 0.0, 1.0)
|
||||||
get_tree().create_tween().tween_method(set_instructions_opacity, 0.0, 1.0, 1.0)
|
get_tree().create_tween().tween_method(set_instructions_opacity, 0.0, 1.0, 1.0)
|
||||||
|
|
||||||
|
|
||||||
# game_ticker.start()
|
# game_ticker.start()
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
if Input.is_action_just_pressed("force_game_tick"):
|
if Input.is_action_just_pressed("force_game_tick"):
|
||||||
Task.print_behavior_tree_evaluation = true
|
Task.print_behavior_tree_evaluation = true
|
||||||
_on_game_tick_timeout()
|
_on_game_tick_timeout()
|
||||||
Task.print_behavior_tree_evaluation = false
|
Task.print_behavior_tree_evaluation = false
|
||||||
if Input.is_action_pressed("force_game_tick_fast"):
|
if Input.is_action_pressed("force_game_tick_fast"):
|
||||||
_on_game_tick_timeout()
|
_on_game_tick_timeout()
|
||||||
if Input.is_action_just_pressed("toggle_temperature_layer"):
|
if Input.is_action_just_pressed("toggle_temperature_layer"):
|
||||||
toggle_temperature_layer()
|
toggle_temperature_layer()
|
||||||
camera.print_config()
|
camera.print_config()
|
||||||
if Input.is_action_just_pressed("auto_tick"):
|
if Input.is_action_just_pressed("auto_tick"):
|
||||||
if game_ticker.is_stopped():
|
if game_ticker.is_stopped():
|
||||||
game_ticker.start()
|
game_ticker.start()
|
||||||
else:
|
else:
|
||||||
game_ticker.stop()
|
game_ticker.stop()
|
||||||
if Input.is_action_just_pressed("key_1"):
|
if Input.is_action_just_pressed("key_1"):
|
||||||
get_tree().reload_current_scene()
|
get_tree().reload_current_scene()
|
||||||
if Input.is_action_just_pressed("key_2"):
|
if Input.is_action_just_pressed("key_2"):
|
||||||
player.exploration_task.current_goal = world.tilemap_ground.local_to_cell(world.get_local_mouse_position())
|
player.exploration_task.current_goal = world.tilemap_ground.local_to_cell(world.get_local_mouse_position())
|
||||||
player.behavior_tree.blackboard["cached_paths"] = {}
|
player.behavior_tree.blackboard["cached_paths"] = {}
|
||||||
player.behavior_tree.blackboard["path"] = []
|
player.behavior_tree.blackboard["path"] = []
|
||||||
if Input.is_action_just_pressed("key_3"):
|
if Input.is_action_just_pressed("key_3"):
|
||||||
player.board_position = Vector2i(world.camp_manager.camp)
|
player.board_position = Vector2i(world.camp_manager.camp)
|
||||||
player.board_position.y += 1
|
player.board_position.y += 1
|
||||||
|
|
||||||
if intro_image.is_visible():
|
if intro_image.is_visible():
|
||||||
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
||||||
|
|
||||||
|
|
||||||
func calculate_scale(image_size: Vector2) -> Vector2:
|
func calculate_scale(image_size: Vector2) -> Vector2:
|
||||||
var viewport_size: Vector2 = world.get_viewport_rect().size
|
var viewport_size: Vector2 = world.get_viewport_rect().size
|
||||||
var scale: float = viewport_size.x / image_size.x
|
var scale: float = viewport_size.x / image_size.x
|
||||||
return Vector2(scale, scale)
|
return Vector2(scale, scale)
|
||||||
|
|
||||||
|
|
||||||
# SECTION: intro / outro
|
# SECTION: intro / outro
|
||||||
|
|
||||||
func set_intro_opacity(opacity: float) -> void:
|
func set_intro_opacity(opacity: float) -> void:
|
||||||
intro_image.set_modulate(Color(1, 1, 1, opacity))
|
intro_image.set_modulate(Color(1, 1, 1, opacity))
|
||||||
|
|
||||||
|
|
||||||
func set_instructions_opacity(opacity: float) -> void:
|
func set_instructions_opacity(opacity: float) -> void:
|
||||||
%InstructionsRect.set_modulate(Color(1, 1, 1, opacity))
|
%InstructionsRect.set_modulate(Color(1, 1, 1, opacity))
|
||||||
%InstructionsRect.show()
|
%InstructionsRect.show()
|
||||||
|
|
||||||
|
|
||||||
func set_outro_opacity(opacity: float) -> void:
|
func set_outro_opacity(opacity: float) -> void:
|
||||||
%OutroImageContainer.set_modulate(Color(1, 1, 1, opacity))
|
%OutroImageContainer.set_modulate(Color(1, 1, 1, opacity))
|
||||||
%OutroImageContainer.show()
|
%OutroImageContainer.show()
|
||||||
|
|
||||||
|
|
||||||
# SECTION: game tick
|
# SECTION: game tick
|
||||||
|
|
||||||
func player_health_depleted():
|
func player_health_depleted():
|
||||||
# TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _on_game_tick_timeout() -> void:
|
func _on_game_tick_timeout() -> void:
|
||||||
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
||||||
timer_on_game_tick_timeout.display_name = "frame"
|
timer_on_game_tick_timeout.display_name = "frame"
|
||||||
|
|
||||||
tilemap_navigation.game_tick_start()
|
tilemap_navigation.game_tick_start()
|
||||||
world.game_tick_start()
|
world.game_tick_start()
|
||||||
|
|
||||||
player.game_tick()
|
player.game_tick()
|
||||||
|
|
||||||
apply_player_exploration_distance()
|
apply_player_exploration_distance()
|
||||||
|
|
||||||
tree_visualizer.update_task_statuses(player.behavior_tree.blackboard)
|
tree_visualizer.update_task_statuses(player.behavior_tree.blackboard)
|
||||||
|
|
||||||
tilemap_navigation.game_tick_end()
|
tilemap_navigation.game_tick_end()
|
||||||
world.game_tick_end()
|
world.game_tick_end()
|
||||||
EventsTracker.populate_visual_log(%RecentEventsLog, self)
|
EventsTracker.populate_visual_log(%RecentEventsLog, self)
|
||||||
|
|
||||||
update_bars()
|
update_bars()
|
||||||
handle_result_game_state(player.behavior_tree.blackboard)
|
update_boat_progress()
|
||||||
|
handle_result_game_state(player.behavior_tree.blackboard)
|
||||||
|
|
||||||
if not game_ticker.is_stopped():
|
if not game_ticker.is_stopped():
|
||||||
camera_follow_player()
|
camera_follow_player()
|
||||||
|
|
||||||
timer_on_game_tick_timeout.stop()
|
timer_on_game_tick_timeout.stop()
|
||||||
|
|
||||||
|
|
||||||
func camera_follow_player() -> void:
|
func camera_follow_player() -> void:
|
||||||
var player_position: Vector2 = world.tilemap_player.cell_to_local(player.board_position)
|
var player_position: Vector2 = world.tilemap_player.cell_to_local(player.board_position)
|
||||||
var targeted_position = null
|
var targeted_position = null
|
||||||
|
|
||||||
if player.behavior_tree.blackboard.has("path"):
|
if player.behavior_tree.blackboard.has("path"):
|
||||||
var path: Array = player.behavior_tree.blackboard["path"]
|
var path: Array = player.behavior_tree.blackboard["path"]
|
||||||
if path.size() > 0:
|
if path.size() > 0:
|
||||||
targeted_position = world.tilemap_player.cell_to_local(path[path.size() - 1])
|
targeted_position = world.tilemap_player.cell_to_local(path[path.size() - 1])
|
||||||
|
|
||||||
if not targeted_position:
|
if not targeted_position:
|
||||||
camera.go_to(player_position)
|
camera.go_to(player_position)
|
||||||
return
|
return
|
||||||
|
|
||||||
var avg_position = (player_position + targeted_position) / 2
|
var avg_position = (player_position + targeted_position) / 2
|
||||||
var distance: float = player_position.distance_to(targeted_position)
|
var distance: float = player_position.distance_to(targeted_position)
|
||||||
var zoom_level: float
|
var zoom_level: float
|
||||||
if distance < 200:
|
if distance < 200:
|
||||||
zoom_level = distance_to_zoom_level(200)
|
zoom_level = distance_to_zoom_level(200)
|
||||||
else:
|
else:
|
||||||
zoom_level = distance_to_zoom_level(distance)
|
zoom_level = distance_to_zoom_level(distance)
|
||||||
|
|
||||||
avg_position.x += distance / 2
|
avg_position.x += distance / 2
|
||||||
|
|
||||||
camera.go_to_zooming(avg_position, zoom_level)
|
camera.go_to_zooming(avg_position, zoom_level)
|
||||||
|
|
||||||
|
|
||||||
func apply_player_exploration_distance():
|
func apply_player_exploration_distance():
|
||||||
player.exploration_task.closest_distance_to_goal = min(player.exploration_task.closest_distance_to_goal, TilemapNavigation.manhattan_distance(player.board_position, player.exploration_task.current_goal))
|
player.exploration_task.closest_distance_to_goal = min(player.exploration_task.closest_distance_to_goal, TilemapNavigation.manhattan_distance(player.board_position, player.exploration_task.current_goal))
|
||||||
|
|
||||||
|
|
||||||
func distance_to_zoom_level(distance: float) -> float:
|
func distance_to_zoom_level(distance: float) -> float:
|
||||||
var a: float = 862.08
|
var a: float = 862.08
|
||||||
var b: float = 274.13
|
var b: float = 274.13
|
||||||
return a / (distance + b)
|
return a / (distance + b)
|
||||||
|
|
||||||
|
|
||||||
func handle_result_game_state(blackboard: Dictionary) -> void:
|
func handle_result_game_state(blackboard: Dictionary) -> void:
|
||||||
if blackboard.has("game_state_win"):
|
if blackboard.has("game_state_win"):
|
||||||
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
|
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
|
||||||
game_ticker.stop()
|
game_ticker.stop()
|
||||||
get_tree().create_tween().tween_method(set_outro_opacity, 0.0, 1.0, 1.0)
|
get_tree().create_tween().tween_method(set_outro_opacity, 0.0, 1.0, 1.0)
|
||||||
|
|
||||||
|
|
||||||
|
func update_boat_progress() -> void:
|
||||||
|
|
||||||
|
# Dictionary zur Zählung der Bootsteile
|
||||||
|
var part_counts = {
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_ENGINE: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_FUEL: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_ANCHOR: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_CHEST: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_GEARS: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_PADDLE: 0,
|
||||||
|
tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Teile in boat_items zählen
|
||||||
|
for boat_part in world.camp_manager.boat_items:
|
||||||
|
if part_counts.has(boat_part):
|
||||||
|
part_counts[boat_part] += 1
|
||||||
|
|
||||||
|
# Aktualisiere die UI basierend auf den gezählten Teilen
|
||||||
|
for part in part_counts.keys():
|
||||||
|
var count = part_counts[part]
|
||||||
|
if count > 0:
|
||||||
|
if part == tilemap_types.OBJECT_I_BOAT_PART_ENGINE:
|
||||||
|
%BoatPartEngine.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_ENGINE)
|
||||||
|
%BoatPartEngine.visible = true
|
||||||
|
%EngineCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_FUEL:
|
||||||
|
%BoatPartFuel.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_FUEL)
|
||||||
|
%BoatPartFuel.visible = true
|
||||||
|
%FuelCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_ANCHOR:
|
||||||
|
%BoatPartAnchor.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_ANCHOR)
|
||||||
|
%BoatPartAnchor.visible = true
|
||||||
|
%AnchorCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_CHEST:
|
||||||
|
%BoatPartChest.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_CHEST)
|
||||||
|
%BoatPartChest.visible = true
|
||||||
|
%ChestCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_GEARS:
|
||||||
|
%BoatPartGears.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_GEARS)
|
||||||
|
%BoatPartGears.visible = true
|
||||||
|
%GearsCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT:
|
||||||
|
%BoatPartMedikit.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT)
|
||||||
|
%BoatPartMedikit.visible = true
|
||||||
|
%MedikitCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_PADDLE:
|
||||||
|
%BoatPartPaddle.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_PADDLE)
|
||||||
|
%BoatPartPaddle.visible = true
|
||||||
|
%PaddleCount.text = str(count)
|
||||||
|
elif part == tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE:
|
||||||
|
%BoatPartGasStove.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE)
|
||||||
|
%BoatPartGasStove.visible = true
|
||||||
|
%StoveCount.text = str(count)
|
||||||
|
else:
|
||||||
|
push_error("Unknown boat part: " + str(part))
|
||||||
|
|
||||||
|
|
||||||
|
func update_camp_ui() -> void:
|
||||||
|
# Get the count of berries and sticks from the camp inventory
|
||||||
|
var berry_count_value = camp.camp_item_count(tilemap_types.OBJECT_I_BERRY)
|
||||||
|
var stick_count_value = camp.camp_item_count(tilemap_types.OBJECT_I_STICK)
|
||||||
|
|
||||||
|
# Update Berry UI
|
||||||
|
%BerryCount.text = str(berry_count_value) # Update the count label
|
||||||
|
%BerryTexture.visible = berry_count_value > 0 # Show texture only if count > 0
|
||||||
|
if berry_count_value > 0:
|
||||||
|
%BerryTexture.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BERRY)
|
||||||
|
|
||||||
|
# Update Stick UI
|
||||||
|
%StickCount.text = str(stick_count_value) # Update the count label
|
||||||
|
%StickTexture.visible = stick_count_value > 0 # Show texture only if count > 0
|
||||||
|
if stick_count_value > 0:
|
||||||
|
%StickTexture.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_STICK)
|
||||||
|
|
||||||
func update_bars() -> void:
|
func update_bars() -> void:
|
||||||
if health_bar != null:
|
if health_bar != null:
|
||||||
health_bar.max_value = player.max_health
|
health_bar.max_value = player.max_health
|
||||||
health_bar.value = clamp(player.health, 0, player.max_health)
|
health_bar.value = clamp(player.health, 0, player.max_health)
|
||||||
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
|
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
|
||||||
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
|
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
|
||||||
|
|
||||||
if food_bar != null:
|
if food_bar != null:
|
||||||
food_bar.max_value = player.max_food
|
food_bar.max_value = player.max_food
|
||||||
food_bar.value = clamp(player.food, 0, player.max_food)
|
food_bar.value = clamp(player.food, 0, player.max_food)
|
||||||
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
|
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
|
||||||
|
|
||||||
if temperature_resistance_bar != null:
|
if temperature_resistance_bar != null:
|
||||||
temperature_resistance_bar.max_value = player.temperature_set_buff_value
|
temperature_resistance_bar.max_value = player.temperature_set_buff_value
|
||||||
temperature_resistance_bar.value = clamp(player.temperature_buff_timer, 0, player.temperature_set_buff_value)
|
temperature_resistance_bar.value = clamp(player.temperature_buff_timer, 0, player.temperature_set_buff_value)
|
||||||
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
|
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
|
||||||
|
|
||||||
if temperature_bar != null:
|
if temperature_bar != null:
|
||||||
temperature_bar.max_value = player.temperature_endure
|
temperature_bar.max_value = player.temperature_endure
|
||||||
# invert the value to show the time left
|
# invert the value to show the time left
|
||||||
var countdown: int = player.temperature_endure - player.temperature_timer
|
var countdown: int = player.temperature_endure - player.temperature_timer
|
||||||
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
|
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
|
||||||
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
|
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
|
||||||
|
|
||||||
if time_of_day_bar != null:
|
if time_of_day_bar != null:
|
||||||
time_of_day_bar.max_value = 1
|
time_of_day_bar.max_value = 1
|
||||||
time_of_day_bar.value = float(world.camp_manager.time_of_day) / world.camp_manager.day_length
|
time_of_day_bar.value = float(world.camp_manager.time_of_day) / world.camp_manager.day_length
|
||||||
time_of_day_bar.self_modulate = calculate_time_of_day_color(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
time_of_day_bar.self_modulate = calculate_time_of_day_color(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
||||||
%TimeOfDayLabel.text = calculate_display_time_of_day(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
%TimeOfDayLabel.text = calculate_display_time_of_day(world.camp_manager.time_of_day, world.camp_manager.day_length)
|
||||||
|
|
||||||
|
|
||||||
func calculate_display_time_of_day(current_time: int, day_length: int) -> String:
|
func calculate_display_time_of_day(current_time: int, day_length: int) -> String:
|
||||||
# format as 24 hour clock, start at 06:00 and end at 21:00
|
# format as 24 hour clock, start at 06:00 and end at 21:00
|
||||||
var start: int = 6
|
var start: int = 6
|
||||||
var end: int = 21
|
var end: int = 21
|
||||||
var hours_per_day: int = end - start
|
var hours_per_day: int = end - start
|
||||||
var time_of_day: float = float(current_time) / day_length * hours_per_day + start
|
var time_of_day: float = float(current_time) / day_length * hours_per_day + start
|
||||||
var hours: int = int(time_of_day)
|
var hours: int = int(time_of_day)
|
||||||
var minutes: int = int((time_of_day - hours) * 60)
|
var minutes: int = int((time_of_day - hours) * 60)
|
||||||
hours %= 24
|
hours %= 24
|
||||||
return str(hours).pad_zeros(2) + ":" + str(minutes).pad_zeros(2)
|
return str(hours).pad_zeros(2) + ":" + str(minutes).pad_zeros(2)
|
||||||
|
|
||||||
|
|
||||||
func calculate_time_of_day_color(current_time: int, day_length: int) -> Color:
|
func calculate_time_of_day_color(current_time: int, day_length: int) -> Color:
|
||||||
var start: Color = Color(1, 1, 0)
|
var start: Color = Color(1, 1, 0)
|
||||||
var end: Color = Color(1, 0, 0)
|
var end: Color = Color(1, 0, 0)
|
||||||
var progress: float = float(current_time) / day_length
|
var progress: float = float(current_time) / day_length
|
||||||
progress = clamp(progress, 0, 1)
|
progress = clamp(progress, 0, 1)
|
||||||
progress = pow(progress, 2)
|
progress = pow(progress, 2)
|
||||||
return start.lerp(end, progress)
|
return start.lerp(end, progress)
|
||||||
|
|
||||||
|
|
||||||
func toggle_temperature_layer() -> void:
|
func toggle_temperature_layer() -> void:
|
||||||
world.tilemap_temperature.tilemap.visible = not world.tilemap_temperature.tilemap.visible
|
world.tilemap_temperature.tilemap.visible = not world.tilemap_temperature.tilemap.visible
|
||||||
|
|
||||||
|
|
||||||
func wait_for_key_press():
|
func wait_for_key_press():
|
||||||
waiting_for_input = true
|
waiting_for_input = true
|
||||||
while waiting_for_input:
|
while waiting_for_input:
|
||||||
await get_tree().process_frame
|
await get_tree().process_frame
|
||||||
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event is InputEventKey and event.pressed:
|
if event is InputEventKey and event.pressed:
|
||||||
waiting_for_input = false
|
waiting_for_input = false
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,19 @@ class_name TaskDeliverBoatPart
|
||||||
extends Task
|
extends Task
|
||||||
|
|
||||||
func run(blackboard: Dictionary) -> void:
|
func run(blackboard: Dictionary) -> void:
|
||||||
var world: World = blackboard["world"]
|
var world: World = blackboard["world"]
|
||||||
var player: PlayerManager = blackboard["player"]
|
var player: PlayerManager = blackboard["player"]
|
||||||
|
|
||||||
if tilemap_types.is_part_of_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS, player.inventory_slot):
|
if tilemap_types.is_part_of_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS, player.inventory_slot):
|
||||||
EventsTracker.track(EventsTracker.Event.CAMP_BOAT_PART_DELIVERED, {"item": player.inventory_slot})
|
EventsTracker.track(EventsTracker.Event.CAMP_BOAT_PART_DELIVERED, {"item": player.inventory_slot})
|
||||||
world.camp_manager.boat_items.append(player.inventory_slot)
|
world.camp_manager.boat_items.append(player.inventory_slot)
|
||||||
player.inventory_slot = tilemap_types.EMPTY
|
player.inventory_slot = tilemap_types.EMPTY
|
||||||
if world.camp_manager.boat_items.size() >= world.camp_manager.required_boat_parts:
|
if world.camp_manager.boat_items.size() >= world.camp_manager.required_boat_parts:
|
||||||
EventsTracker.track(EventsTracker.Event.CAMP_BOAT_COMPLETE, {"item": tilemap_types.OBJECT_I_BOAT_WITH_ENGINE})
|
EventsTracker.track(EventsTracker.Event.CAMP_BOAT_COMPLETE, {"item": tilemap_types.OBJECT_I_BOAT_WITH_ENGINE})
|
||||||
world.tilemap_interactive.set_cell(world.camp_manager.boat_build_location, tilemap_types.OBJECT_I_BOAT_WITH_ENGINE)
|
world.tilemap_interactive.set_cell(world.camp_manager.boat_build_location, tilemap_types.OBJECT_I_BOAT_WITH_ENGINE)
|
||||||
status = SUCCESS
|
status = SUCCESS
|
||||||
status_reason = "Player delivered boat part"
|
status_reason = "Player delivered boat part"
|
||||||
return
|
return
|
||||||
|
|
||||||
status = FAILURE
|
status = FAILURE
|
||||||
status_reason = "Player does not have boat part to deliver"
|
status_reason = "Player does not have boat part to deliver"
|
||||||
|
|
|
||||||
|
|
@ -20,136 +20,144 @@ var day_length: int = 1000
|
||||||
|
|
||||||
|
|
||||||
func setup() -> void:
|
func setup() -> void:
|
||||||
tilemap_interactive = game_manager.world.tilemap_interactive
|
tilemap_interactive = game_manager.world.tilemap_interactive
|
||||||
var camp_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TENT)
|
var camp_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TENT)
|
||||||
if len(camp_locations) > 0:
|
if len(camp_locations) > 0:
|
||||||
camp = camp_locations[0]
|
camp = camp_locations[0]
|
||||||
else:
|
else:
|
||||||
push_error("No camp location found on tilemap")
|
push_error("No camp location found on tilemap")
|
||||||
|
|
||||||
var firepit_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_FIREPIT)
|
var firepit_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_FIREPIT)
|
||||||
if len(firepit_locations) > 0:
|
if len(firepit_locations) > 0:
|
||||||
campfire = firepit_locations[0]
|
campfire = firepit_locations[0]
|
||||||
else:
|
else:
|
||||||
push_error("No firepit location found on tilemap")
|
push_error("No firepit location found on tilemap")
|
||||||
|
|
||||||
var boat_build_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_NO_ENIGNE)
|
var boat_build_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_NO_ENIGNE)
|
||||||
if len(boat_build_locations) > 0:
|
if len(boat_build_locations) > 0:
|
||||||
boat_build_location = boat_build_locations[0]
|
boat_build_location = boat_build_locations[0]
|
||||||
else:
|
else:
|
||||||
push_error("No boat build location found on tilemap")
|
push_error("No boat build location found on tilemap")
|
||||||
|
|
||||||
var boat_leave_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_WITH_ENGINE)
|
var boat_leave_locations: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_BOAT_WITH_ENGINE)
|
||||||
if len(boat_leave_locations) > 0:
|
if len(boat_leave_locations) > 0:
|
||||||
boat_leave_location = boat_leave_locations[0]
|
boat_leave_location = boat_leave_locations[0]
|
||||||
tilemap_interactive.set_cell(boat_leave_location, tilemap_types.EMPTY)
|
tilemap_interactive.set_cell(boat_leave_location, tilemap_types.EMPTY)
|
||||||
else:
|
else:
|
||||||
push_error("No boat leave location found on tilemap")
|
push_error("No boat leave location found on tilemap")
|
||||||
|
|
||||||
print("CampManager: camp=", camp, " campfire=", campfire, " boat_build_location=", boat_build_location, " boat_leave_location=", boat_leave_location)
|
print("CampManager: camp=", camp, " campfire=", campfire, " boat_build_location=", boat_build_location, " boat_leave_location=", boat_leave_location)
|
||||||
|
|
||||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
||||||
|
|
||||||
|
|
||||||
func game_tick_start() -> void:
|
func game_tick_start() -> void:
|
||||||
time_of_day += 1
|
time_of_day += 1
|
||||||
|
|
||||||
|
|
||||||
func game_tick_end() -> void:
|
func game_tick_end() -> void:
|
||||||
if time_of_day == day_length:
|
if time_of_day == day_length:
|
||||||
EventsTracker.track(EventsTracker.Event.TIME_SUNDOWN)
|
EventsTracker.track(EventsTracker.Event.TIME_SUNDOWN)
|
||||||
|
|
||||||
|
|
||||||
func is_sundown() -> bool:
|
func is_sundown() -> bool:
|
||||||
return time_of_day >= day_length
|
return time_of_day >= day_length
|
||||||
|
|
||||||
|
|
||||||
func camp_contains_enough_sticks_to_light_campfire() -> bool:
|
func camp_contains_enough_sticks_to_light_campfire() -> bool:
|
||||||
return camp_item_count(tilemap_types.OBJECT_I_STICK) >= 2
|
return camp_item_count(tilemap_types.OBJECT_I_STICK) >= 2
|
||||||
|
|
||||||
|
|
||||||
func camp_contains_item(item: Vector2i) -> bool:
|
func camp_contains_item(item: Vector2i) -> bool:
|
||||||
return camp_items.find(item) != -1
|
return camp_items.find(item) != -1
|
||||||
|
|
||||||
|
|
||||||
func camp_contains_item_collection(item: Array[Vector2i]) -> bool:
|
func camp_contains_item_collection(item: Array[Vector2i]) -> bool:
|
||||||
for i in item:
|
for i in item:
|
||||||
if camp_items.find(i) == -1:
|
if camp_items.find(i) == -1:
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
func camp_item_count(item: Vector2i) -> int:
|
func camp_item_count(item: Vector2i) -> int:
|
||||||
var count: int = 0
|
var count: int = 0
|
||||||
for i in camp_items:
|
for i in camp_items:
|
||||||
if i == item:
|
if i == item:
|
||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
func camp_item_collection_count(item: Array[Vector2i]) -> int:
|
func camp_item_collection_count(item: Array[Vector2i]) -> int:
|
||||||
var count: int = 0
|
var count: int = 0
|
||||||
for i in camp_items:
|
for i in camp_items:
|
||||||
if item.find(i) != -1:
|
if item.find(i) != -1:
|
||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
func camp_take_item(item: Vector2i, count: int = 1) -> bool:
|
func camp_take_item(item: Vector2i, count: int = 1) -> bool:
|
||||||
if camp_item_count(item) < count:
|
if camp_item_count(item) < count:
|
||||||
push_error("CampManager: not enough items to take: " + str(item))
|
push_error("CampManager: not enough items to take: " + str(item))
|
||||||
EventsTracker.track(EventsTracker.Event.CAMP_TAKE_ITEM_FAILED, {"item": item, "count": count})
|
EventsTracker.track(EventsTracker.Event.CAMP_TAKE_ITEM_FAILED, {"item": item, "count": count})
|
||||||
return false
|
return false
|
||||||
|
|
||||||
var taken: int = 0
|
var taken: int = 0
|
||||||
for i in range(camp_items.size() - 1, -1, -1):
|
for i in range(camp_items.size() - 1, -1, -1):
|
||||||
if camp_items[i] == item:
|
if camp_items[i] == item:
|
||||||
camp_items.remove_at(i)
|
camp_items.remove_at(i)
|
||||||
taken += 1
|
taken += 1
|
||||||
if taken == count:
|
if taken == count:
|
||||||
break
|
break
|
||||||
|
|
||||||
EventsTracker.track(EventsTracker.Event.CAMP_TAKEN_ITEM, {"item": item, "count": count})
|
EventsTracker.track(EventsTracker.Event.CAMP_TAKEN_ITEM, {"item": item, "count": count})
|
||||||
return true
|
if game_manager:
|
||||||
|
game_manager.update_camp_ui()
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
func camp_add_item(item: Vector2i) -> void:
|
func camp_add_item(item: Vector2i) -> void:
|
||||||
camp_items.append(item)
|
camp_items.append(item)
|
||||||
EventsTracker.track(EventsTracker.Event.CAMP_ADDED_ITEM, {"item": item, "count": 1, "new_count": camp_item_count(item)})
|
if tilemap_types.is_part_of_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS, item):
|
||||||
|
if not boat_items.has(item):
|
||||||
|
boat_items.append(item)
|
||||||
|
EventsTracker.track(EventsTracker.Event.CAMP_ADDED_ITEM, {"item": item, "count": 1, "new_count": camp_item_count(item)})
|
||||||
|
if game_manager:
|
||||||
|
game_manager.update_camp_ui()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func campfire_light() -> bool:
|
func campfire_light() -> bool:
|
||||||
# requires two sticks in the camp
|
# requires two sticks in the camp
|
||||||
if camp_take_item(tilemap_types.OBJECT_I_STICK, 2):
|
if camp_take_item(tilemap_types.OBJECT_I_STICK, 2):
|
||||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_ON)
|
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_ON)
|
||||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT)
|
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT)
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT_FAILED)
|
EventsTracker.track(EventsTracker.Event.CAMPFIRE_LIT_FAILED)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
func campfire_extinguish() -> void:
|
func campfire_extinguish() -> void:
|
||||||
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
tilemap_interactive.set_cell(campfire, tilemap_types.OBJECT_I_FIREPIT_OFF)
|
||||||
EventsTracker.track(EventsTracker.Event.CAMPFIRE_EXTINGUISHED)
|
EventsTracker.track(EventsTracker.Event.CAMPFIRE_EXTINGUISHED)
|
||||||
|
|
||||||
var is_sleep_active: bool = false
|
var is_sleep_active: bool = false
|
||||||
|
|
||||||
|
|
||||||
func sleep_effect() -> void:
|
func sleep_effect() -> void:
|
||||||
if is_sleep_active:
|
if is_sleep_active:
|
||||||
return
|
return
|
||||||
is_sleep_active = true
|
is_sleep_active = true
|
||||||
EventsTracker.track(EventsTracker.Event.SLEEP)
|
EventsTracker.track(EventsTracker.Event.SLEEP)
|
||||||
|
|
||||||
game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(camp), 3)
|
game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(camp), 3)
|
||||||
var tween_in: Tween = game_manager.world.get_tree().create_tween()
|
var tween_in: Tween = game_manager.world.get_tree().create_tween()
|
||||||
tween_in.tween_method(game_manager.camera.set_vignette_intensity, 0.0, 1.0, 2.0).set_delay(0.5)
|
tween_in.tween_method(game_manager.camera.set_vignette_intensity, 0.0, 1.0, 2.0).set_delay(0.5)
|
||||||
var tween_out: Tween = game_manager.world.get_tree().create_tween()
|
var tween_out: Tween = game_manager.world.get_tree().create_tween()
|
||||||
tween_out.tween_method(game_manager.camera.set_vignette_intensity, 1.0, 0.0, 2.0).set_delay(4.0)
|
tween_out.tween_method(game_manager.camera.set_vignette_intensity, 1.0, 0.0, 2.0).set_delay(4.0)
|
||||||
|
|
||||||
await game_manager.world.get_tree().create_timer(6.0).timeout
|
await game_manager.world.get_tree().create_timer(6.0).timeout
|
||||||
|
|
||||||
print("Sleep effect done")
|
print("Sleep effect done")
|
||||||
is_sleep_active = false
|
is_sleep_active = false
|
||||||
time_of_day = 0
|
time_of_day = 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue