Fade-in bei Spielstart into Tastaturlayout und bei Tastendruck gehts dann los

pull/7/head
Crazyrx7 2025-01-13 11:35:12 +01:00
parent d8bc800077
commit 4b8479e87e
11 changed files with 520 additions and 348 deletions

View File

@ -1,3 +0,0 @@
{
"godotTools.editorPath.godot4": "g:\\Godot\\Godot_v4.3-stable_win64_console.exe"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cec2cyh21jhxh"
path="res://.godot/imported/test-stamp-png.png-b6bc37d9bb89c1a8896950f3d851cde1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/images/test-stamp-png.png"
dest_files=["res://.godot/imported/test-stamp-png.png-b6bc37d9bb89c1a8896950f3d851cde1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=45 format=4 uid="uid://b88asko1ugyd2"]
[gd_scene load_steps=50 format=4 uid="uid://b88asko1ugyd2"]
[ext_resource type="Script" path="res://scripts/global/GameManager.gd" id="1_eeg2d"]
[ext_resource type="Script" path="res://scripts/tilemap/World.gd" id="1_k0rw8"]
[ext_resource type="TileSet" uid="uid://bi836ygcmyvhb" path="res://assets/tilemap/tileset.tres" id="1_vlccq"]
[ext_resource type="Script" path="res://scripts/global/CameraController.gd" id="2_k51iv"]
[ext_resource type="Material" uid="uid://ckg3be082ny3h" path="res://assets/shader/shader_vignette.tres" id="3_7waul"]
[ext_resource type="Texture2D" uid="uid://di16cmfomo60u" path="res://scripts/tilemap/Dein Abschnittstext.png" id="3_oufrl"]
[ext_resource type="Script" path="res://scripts/player/PlayerManager.gd" id="4_1xqo1"]
[ext_resource type="Texture2D" uid="uid://1ae5agveqddp" path="res://icon.svg" id="4_o8ona"]
[ext_resource type="Script" path="res://scripts/visualization/BehaviorTreeVisualizer.gd" id="5_ecfvx"]
@ -45,6 +46,72 @@
[ext_resource type="Script" path="res://scripts/player/tree/impl/game/camp/TaskPutInventoryContentInCamp.gd" id="39_8rirr"]
[ext_resource type="Script" path="res://scripts/player/tree/impl/game/camp/TaskCampSleep.gd" id="39_nbuyx"]
[sub_resource type="Animation" id="Animation_utk5y"]
resource_name = "Fade in"
length = 3.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Camera2D/ColorRect:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(1, 3),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0)]
}
[sub_resource type="Animation" id="Animation_tc843"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Camera2D/ColorRect:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0, 0, 0, 0)]
}
[sub_resource type="Animation" id="Animation_wbxrc"]
resource_name = "Fade out"
length = 3.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = false
tracks/0/path = NodePath("Camera2D/ColorRect:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Camera2D/Sprite2D:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_y25dn"]
_data = {
"Fade in": SubResource("Animation_utk5y"),
"Fade out": SubResource("Animation_wbxrc"),
"RESET": SubResource("Animation_tc843")
}
[node name="Island-scene" type="Node2D"]
script = ExtResource("1_eeg2d")
metadata/_edit_vertical_guides_ = [1900.0, 4004.0]
@ -54,6 +121,28 @@ metadata/_edit_horizontal_guides_ = [2097.0]
position = Vector2(2451, 3007)
script = ExtResource("2_k51iv")
[node name="Sprite2D" type="Sprite2D" parent="Camera2D"]
z_index = 1
position = Vector2(1.50008, -2.00003)
scale = Vector2(0.347656, 0.373264)
texture = ExtResource("3_oufrl")
[node name="ColorRect" type="ColorRect" parent="Camera2D"]
top_level = true
z_index = 1
offset_left = -6230.0
offset_top = -4497.0
offset_right = 5463.0
offset_bottom = 4961.0
color = Color(0, 0, 0, 0)
[node name="AnimationPlayer" type="AnimationPlayer" parent="Camera2D"]
root_node = NodePath("../..")
libraries = {
"": SubResource("AnimationLibrary_y25dn")
}
movie_quit_on_finish = true
[node name="CanvasLayer" type="CanvasLayer" parent="Camera2D"]
[node name="Vignette" type="ColorRect" parent="Camera2D/CanvasLayer"]
@ -213,7 +302,7 @@ size_flags_vertical = 8
[node name="TreeVisualizer" type="Window" parent="Camera2D/CanvasLayer"]
unique_name_in_owner = true
position = Vector2i(35, 405)
position = Vector2i(0, 36)
size = Vector2i(1075, 225)
script = ExtResource("5_ecfvx")
@ -226,7 +315,6 @@ grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
scroll_offset = Vector2(-100, -100)
show_menu = false
show_zoom_buttons = false
show_grid_buttons = false

View File

@ -78,12 +78,12 @@ key_9={
}
force_game_tick={
"deadzone": 0.5,
"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":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
force_game_tick_fast={
"deadzone": 0.5,
"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":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
key_4={

View File

@ -22,115 +22,115 @@ var force_zoom: Vector2 = DISABLE_FORCE
func go_to_zooming(position: Vector2, zoom: float) -> void:
force_target_position = position
force_zoom = Vector2(zoom, zoom)
force_target_position = position
force_zoom = Vector2(zoom, zoom)
func go_to(position: Vector2) -> void:
force_target_position = position
force_target_position = position
func print_config() -> void:
print("camera.go_to_zooming(Vector2(", position.x, ", ", position.y, "), ", zoom.x, ")")
print("camera.go_to_zooming(Vector2(", position.x, ", ", position.y, "), ", zoom.x, ")")
func map_range(value: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float:
return to_min + (value - from_min) / (from_max - from_min) * (to_max - to_min)
return to_min + (value - from_min) / (from_max - from_min) * (to_max - to_min)
func _input(event):
if event is InputEventMouseButton:
if force_zoom == DISABLE_FORCE:
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoom = zoom * 1.1
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom = zoom / 1.1
if event is InputEventMouseButton:
if force_zoom == DISABLE_FORCE:
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoom = zoom * 1.1
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom = zoom / 1.1
func _process(delta):
if Input.is_action_just_pressed("camera_drag"):
drag_active = true
drag_start = get_viewport().get_mouse_position()
if Input.is_action_just_released("camera_drag"):
drag_active = false
if drag_active:
var drag_end: Vector2 = get_viewport().get_mouse_position()
var drag_offset: Vector2 = drag_end - drag_start
drag_start = drag_end
position -= drag_offset / zoom
if Input.is_action_just_pressed("camera_drag"):
drag_active = true
drag_start = get_viewport().get_mouse_position()
if Input.is_action_just_released("camera_drag"):
drag_active = false
if drag_active:
var drag_end: Vector2 = get_viewport().get_mouse_position()
var drag_offset: Vector2 = drag_end - drag_start
drag_start = drag_end
position -= drag_offset / zoom
if force_target_position != DISABLE_FORCE:
# move towards the target position
var offset: Vector2 = force_target_position - position
position += offset * 0.1
if offset.length() < 1:
force_target_position = DISABLE_FORCE
if force_zoom != DISABLE_FORCE:
# move towards the target zoom
var offset: Vector2 = force_zoom - zoom
zoom += offset * 0.04
if offset.length() < 0.02:
force_zoom = DISABLE_FORCE
else:
var is_zoom_in: bool = Input.is_action_pressed("camera_zoom_in")
var is_zoom_out: bool = Input.is_action_pressed("camera_zoom_out")
if force_target_position != DISABLE_FORCE:
# move towards the target position
var offset: Vector2 = force_target_position - position
position += offset * 0.1
if offset.length() < 1:
force_target_position = DISABLE_FORCE
if force_zoom != DISABLE_FORCE:
# move towards the target zoom
var offset: Vector2 = force_zoom - zoom
zoom += offset * 0.04
if offset.length() < 0.02:
force_zoom = DISABLE_FORCE
else:
var is_zoom_in: bool = Input.is_action_pressed("camera_zoom_in")
var is_zoom_out: bool = Input.is_action_pressed("camera_zoom_out")
if is_zoom_in:
zoom = zoom * 1.02
elif is_zoom_out:
zoom = zoom / 1.02
if is_zoom_in:
zoom = zoom * 1.02
elif is_zoom_out:
zoom = zoom / 1.02
if zoom.length() < 0.2:
zoom = Vector2(1, 1).normalized() * 0.2
elif zoom.length() > 10:
zoom = Vector2(1, 1).normalized() * 10
if zoom.length() < 0.2:
zoom = Vector2(1, 1).normalized() * 0.2
elif zoom.length() > 10:
zoom = Vector2(1, 1).normalized() * 10
var mouse_pos: Vector2 = get_viewport().get_mouse_position()
var screen_size: Vector2 = get_viewport().get_visible_rect().size
var acceleration: Vector2 = Vector2.ZERO
var mouse_pos: Vector2 = get_viewport().get_mouse_position()
var screen_size: Vector2 = get_viewport().get_visible_rect().size
var acceleration: Vector2 = Vector2.ZERO
# the bigger the viewport size, the bigger the border threshold
var border_threshold_addition: float = max(0, map_range(screen_size.length(), 1320, 2600, 0, 100))
# the bigger the viewport size, the bigger the border threshold
var border_threshold_addition: float = max(0, map_range(screen_size.length(), 1320, 2600, 0, 100))
var is_up: bool = Input.is_action_pressed("camera_up") or mouse_pos.y < inner_border_threshold + border_threshold_addition and mouse_pos.y > -outer_border_threshold
var is_down: bool = Input.is_action_pressed("camera_down") or mouse_pos.y > screen_size.y - inner_border_threshold - border_threshold_addition and mouse_pos.y < screen_size.y + outer_border_threshold
var is_left: bool = Input.is_action_pressed("camera_left") or mouse_pos.x < inner_border_threshold + border_threshold_addition and mouse_pos.x > -outer_border_threshold
var is_right: bool = Input.is_action_pressed("camera_right") or mouse_pos.x > screen_size.x - inner_border_threshold - border_threshold_addition and mouse_pos.x < screen_size.x + outer_border_threshold
var is_up: bool = Input.is_action_pressed("camera_up") or mouse_pos.y < inner_border_threshold + border_threshold_addition and mouse_pos.y > -outer_border_threshold
var is_down: bool = Input.is_action_pressed("camera_down") or mouse_pos.y > screen_size.y - inner_border_threshold - border_threshold_addition and mouse_pos.y < screen_size.y + outer_border_threshold
var is_left: bool = Input.is_action_pressed("camera_left") or mouse_pos.x < inner_border_threshold + border_threshold_addition and mouse_pos.x > -outer_border_threshold
var is_right: bool = Input.is_action_pressed("camera_right") or mouse_pos.x > screen_size.x - inner_border_threshold - border_threshold_addition and mouse_pos.x < screen_size.x + outer_border_threshold
if is_left:
acceleration.x = -border_acceleration
elif is_right:
acceleration.x = border_acceleration
if is_left:
acceleration.x = -border_acceleration
elif is_right:
acceleration.x = border_acceleration
if is_up:
acceleration.y = -border_acceleration
elif is_down:
acceleration.y = border_acceleration
if is_up:
acceleration.y = -border_acceleration
elif is_down:
acceleration.y = border_acceleration
acceleration *= Vector2.ONE / zoom
acceleration *= Vector2.ONE / zoom
if acceleration.length() > 0:
# if the acceleration is the opposite direction of the velocity, double the acceleration
if acceleration.dot(velocity) < 0:
acceleration = acceleration * 2
velocity = velocity + acceleration * delta
else:
velocity = velocity.move_toward(Vector2.ZERO, border_acceleration * delta)
if acceleration.length() > 0:
# if the acceleration is the opposite direction of the velocity, double the acceleration
if acceleration.dot(velocity) < 0:
acceleration = acceleration * 2
velocity = velocity + acceleration * delta
else:
velocity = velocity.move_toward(Vector2.ZERO, border_acceleration * delta)
if velocity.length() > max_speed:
velocity = velocity.normalized() * max_speed
if velocity.length() > max_speed:
velocity = velocity.normalized() * max_speed
var target_offset = velocity * delta
var target_position = position + target_offset
target_position.x = clamp(target_position.x, min_position.x, max_position.x)
target_position.y = clamp(target_position.y, min_position.y, max_position.y)
var target_offset = velocity * delta
var target_position = position + target_offset
target_position.x = clamp(target_position.x, min_position.x, max_position.x)
target_position.y = clamp(target_position.y, min_position.y, max_position.y)
var offset: Vector2 = target_position - position
position += offset
var offset: Vector2 = target_position - position
position += offset
# SECTION: shader access
func set_vignette_intensity(value: float) -> void:
var material: ShaderMaterial = shader_vignette.material
material.set_shader_parameter("vignette_strength", value)
var material: ShaderMaterial = shader_vignette.material
material.set_shader_parameter("vignette_strength", value)

View File

@ -14,101 +14,120 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
@onready var temperature_resistance_bar: ProgressBar = %TemperatureResistanceBar
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
var waiting_for_input = true
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
@onready var animation_player = $Camera2D/AnimationPlayer
@onready var sprite = $Camera2D/Sprite2D
@onready var color_rect = $Camera2D/ColorRect
func _ready() -> void:
tilemap_navigation.world = world
tilemap_navigation.player = player
player.game_manager = self
world.camp_manager.game_manager = self
world.step_visualizer.game_manager = self
world.step_visualizer.world = world
update_bars()
call_deferred("defer_ready")
tilemap_navigation.world = world
tilemap_navigation.player = player
player.game_manager = self
world.camp_manager.game_manager = self
world.step_visualizer.game_manager = self
world.step_visualizer.world = world
update_bars()
if animation_player and sprite:
animation_player.play("Fade in")
print("Warte auf Tasteneingabe...")
await wait_for_key_press()
animation_player.play("Fade out")
await get_tree().create_timer(3.0).timeout
call_deferred("defer_ready")
else:
print("Knoten nicht gefunden!")
call_deferred("defer_ready")
func defer_ready() -> void:
tree_visualizer.behavior_tree = player.behavior_tree
tree_visualizer.build_tree()
tree_visualizer.behavior_tree = player.behavior_tree
tree_visualizer.build_tree()
# game_ticker.start()
func _process(delta: float) -> void:
if Input.is_action_just_pressed("key_1"):
camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561)
if Input.is_action_just_pressed("key_2"):
camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448)
if Input.is_action_just_pressed("key_9"):
world.camp_manager.campfire_light()
world.camp_manager.sleep_effect()
world.camp_manager.campfire_extinguish()
if Input.is_action_just_pressed("force_game_tick"):
Task.print_behavior_tree_evaluation = true
_on_game_tick_timeout()
Task.print_behavior_tree_evaluation = false
if Input.is_action_pressed("force_game_tick_fast"):
_on_game_tick_timeout()
if Input.is_action_just_pressed("key_6"):
toggle_temperature_layer()
if Input.is_action_just_pressed("key_6"):
camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561)
if Input.is_action_just_pressed("key_3"):
camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448)
if Input.is_action_just_pressed("key_9"):
world.camp_manager.campfire_light()
world.camp_manager.sleep_effect()
world.camp_manager.campfire_extinguish()
if Input.is_action_just_pressed("force_game_tick"):
Task.print_behavior_tree_evaluation = true
_on_game_tick_timeout()
Task.print_behavior_tree_evaluation = false
if Input.is_action_pressed("force_game_tick_fast"):
_on_game_tick_timeout()
if Input.is_action_just_pressed("key_2"):
toggle_temperature_layer()
func player_health_depleted():
# TODO
pass
# TODO
pass
func _on_game_tick_timeout() -> void:
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
timer_on_game_tick_timeout.display_name = "frame"
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
timer_on_game_tick_timeout.display_name = "frame"
tilemap_navigation.game_tick_start()
world.game_tick_start()
tilemap_navigation.game_tick_start()
world.game_tick_start()
player.game_tick()
player.game_tick()
tilemap_navigation.game_tick_end()
world.game_tick_end()
EventsTracker.populate_visual_log(%RecentEventsLog, self)
tilemap_navigation.game_tick_end()
world.game_tick_end()
EventsTracker.populate_visual_log(%RecentEventsLog, self)
update_bars()
handle_result_game_state(player.behavior_tree.blackboard)
update_bars()
handle_result_game_state(player.behavior_tree.blackboard)
timer_on_game_tick_timeout.stop()
timer_on_game_tick_timeout.stop()
func handle_result_game_state(blackboard: Dictionary) -> void:
if blackboard.has("game_state_win"):
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
game_ticker.stop()
if blackboard.has("game_state_win"):
EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN)
game_ticker.stop()
func update_bars() -> void:
if health_bar != null:
health_bar.max_value = player.max_health
health_bar.value = clamp(player.health, 0, player.max_health)
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
if health_bar != null:
health_bar.max_value = player.max_health
health_bar.value = clamp(player.health, 0, player.max_health)
%HealthLabel.text = str(health_bar.value) + "/" + str(player.max_health)
%HealthLabel.add_theme_color_override("font_color", Color(1, 1, 1))
if food_bar != null:
food_bar.max_value = player.max_food
food_bar.value = clamp(player.food, 0, player.max_food)
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
if food_bar != null:
food_bar.max_value = player.max_food
food_bar.value = clamp(player.food, 0, player.max_food)
%FoodLabel.text = str(food_bar.value) + "/" + str(player.max_food)
if temperature_resistance_bar != null:
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)
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
if temperature_resistance_bar != null:
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)
%TemperatureResistanceLabel.text = str(temperature_resistance_bar.value) + "/" + str(player.temperature_set_buff_value)
if temperature_bar != null:
temperature_bar.max_value = player.temperature_endure
# invert the value to show the time left
var countdown: int = player.temperature_endure - player.temperature_timer
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
if temperature_bar != null:
temperature_bar.max_value = player.temperature_endure
# invert the value to show the time left
var countdown: int = player.temperature_endure - player.temperature_timer
temperature_bar.value = clamp(countdown, 0, player.temperature_endure)
%TemperatureLabel.text = str(temperature_bar.value) + "/" + str(player.temperature_endure)
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():
while waiting_for_input:
await get_tree().process_frame
func _input(event):
if event is InputEventKey and event.pressed:
waiting_for_input = false

View File

@ -20,10 +20,10 @@ var game_manager: GameManager = null
var last_board_position: Vector2i = Vector2i(0, 0)
var board_position: Vector2i = Vector2i(0, 0):
set(value):
last_board_position = board_position
board_position = value
update_board()
set(value):
last_board_position = board_position
board_position = value
update_board()
@onready var behavior_tree: BehaviorTree = $BehaviorTree
@ -34,212 +34,212 @@ var temperature_timer: int = 0
var health: int = max_health
var inventory_slot: Vector2i = tilemap_types.EMPTY:
set(value):
inventory_slot = value
update_board()
set(value):
inventory_slot = value
update_board()
var player_memory: Dictionary = {}
func _ready() -> void:
call_deferred("defer_ready")
call_deferred("defer_ready")
func defer_ready() -> void:
behavior_tree.game_manager = game_manager
var player_start_position: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER_DOWN)
if len(player_start_position) > 0:
board_position = player_start_position[0]
else:
push_error("No player start position found on tilemap")
update_board()
behavior_tree.game_manager = game_manager
var player_start_position: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER_DOWN)
if len(player_start_position) > 0:
board_position = player_start_position[0]
else:
push_error("No player start position found on tilemap")
update_board()
func _process(delta: float) -> void:
if Input.is_action_just_pressed("key_3"):
game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(board_position), 2)
if Input.is_action_just_pressed("key_5"):
pick_up_item(Vector2i(5, 8))
pick_up_item(Vector2i(9, 9))
if Input.is_action_just_pressed("key_4"):
var nearest: Vector2i = find_nearest_object([game_manager.world.tilemap_types.OBJECT_I_TREE_FULL])
# nearest.x = nearest.x - 1
walk_towards(nearest)
if Input.is_action_just_pressed("key_1"):
game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(board_position), 2)
if Input.is_action_just_pressed("key_5"):
pick_up_item(Vector2i(5, 8))
pick_up_item(Vector2i(9, 9))
if Input.is_action_just_pressed("key_4"):
var nearest: Vector2i = find_nearest_object([game_manager.world.tilemap_types.OBJECT_I_TREE_FULL])
# nearest.x = nearest.x - 1
walk_towards(nearest)
# SECTION: board access/mangement
func update_board() -> void:
game_manager.world.tilemap_player.clear_cells()
# decide what direction the player is facing tilemap_types.PLAYER_DOWN, ...
var direction: Vector2i = find_direction(last_board_position, board_position)
game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.player_sprite_from_direction(direction))
game_manager.world.tilemap_player.clear_cells()
# decide what direction the player is facing tilemap_types.PLAYER_DOWN, ...
var direction: Vector2i = find_direction(last_board_position, board_position)
game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.player_sprite_from_direction(direction))
if inventory_slot and inventory_slot != tilemap_types.EMPTY:
%InventoryContentRect.texture = game_manager.world.tilemap_interactive.get_cell_texture(inventory_slot)
else:
%InventoryContentRect.texture = null
if inventory_slot and inventory_slot != tilemap_types.EMPTY:
%InventoryContentRect.texture = game_manager.world.tilemap_interactive.get_cell_texture(inventory_slot)
else:
%InventoryContentRect.texture = null
# SECTION: inventory system
func pick_up_item(tilemap_pos: Vector2i) -> void:
var pick_up_cell: TileData = game_manager.world.tilemap_interactive.get_cell(tilemap_pos)
if not pick_up_cell:
push_warning("Player trying to pick up item that does not exist at ", tilemap_pos)
return
var pick_up_cell: TileData = game_manager.world.tilemap_interactive.get_cell(tilemap_pos)
if not pick_up_cell:
push_warning("Player trying to pick up item that does not exist at ", tilemap_pos)
return
var pick_up_item_type: Vector2i = game_manager.world.tilemap_interactive.tilemap.get_cell_atlas_coords(tilemap_pos)
var pick_up_item_type: Vector2i = game_manager.world.tilemap_interactive.tilemap.get_cell_atlas_coords(tilemap_pos)
# check if inventory contains item that needs to be transformed on dropping
# this should never be the case, as the pick up item operation should already reflect this transformation
var tile_drop_item: Vector2i = inventory_slot
if tile_drop_item == tilemap_types.OBJECT_I_FILLED_BUSH:
tile_drop_item = tilemap_types.OBJECT_I_BERRY
elif tile_drop_item == tilemap_types.OBJECT_I_TREE_FULL:
tile_drop_item = tilemap_types.OBJECT_I_STICK
# check if inventory contains item that needs to be transformed on dropping
# this should never be the case, as the pick up item operation should already reflect this transformation
var tile_drop_item: Vector2i = inventory_slot
if tile_drop_item == tilemap_types.OBJECT_I_FILLED_BUSH:
tile_drop_item = tilemap_types.OBJECT_I_BERRY
elif tile_drop_item == tilemap_types.OBJECT_I_TREE_FULL:
tile_drop_item = tilemap_types.OBJECT_I_STICK
# check if tile will transform into another tile upon pickup
var tile_after_pickup_transform = null
if pick_up_item_type == tilemap_types.OBJECT_I_FILLED_BUSH:
tile_after_pickup_transform = tilemap_types.OBJECT_I_EMPTY_BUSH
pick_up_item_type = tilemap_types.OBJECT_I_BERRY
elif pick_up_item_type == tilemap_types.OBJECT_I_TREE_FULL:
tile_after_pickup_transform = tilemap_types.OBJECT_I_TREE_CUT
pick_up_item_type = tilemap_types.OBJECT_I_STICK
# check if tile will transform into another tile upon pickup
var tile_after_pickup_transform = null
if pick_up_item_type == tilemap_types.OBJECT_I_FILLED_BUSH:
tile_after_pickup_transform = tilemap_types.OBJECT_I_EMPTY_BUSH
pick_up_item_type = tilemap_types.OBJECT_I_BERRY
elif pick_up_item_type == tilemap_types.OBJECT_I_TREE_FULL:
tile_after_pickup_transform = tilemap_types.OBJECT_I_TREE_CUT
pick_up_item_type = tilemap_types.OBJECT_I_STICK
# check if the inventory slot is empty
if inventory_slot == tilemap_types.EMPTY:
inventory_slot = pick_up_item_type
if tile_after_pickup_transform:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform)
else:
game_manager.world.tilemap_interactive.clear_cell(tilemap_pos)
print("Picked up item: ", pick_up_item_type)
EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type})
# check if the inventory slot is empty
if inventory_slot == tilemap_types.EMPTY:
inventory_slot = pick_up_item_type
if tile_after_pickup_transform:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform)
else:
game_manager.world.tilemap_interactive.clear_cell(tilemap_pos)
print("Picked up item: ", pick_up_item_type)
EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type})
else:
# inventory is full, swap the item
print("Inventory is full. Swapping item: ", inventory_slot, " with item: ", pick_up_item_type)
EventsTracker.track(EventsTracker.Event.PLAYER_DROPPED_ITEM, {"item": inventory_slot})
EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type})
if tile_after_pickup_transform:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform)
var drop_location: Vector2i = game_manager.world.find_item_drop_location(tilemap_pos)
if drop_location != tilemap_types.EMPTY:
game_manager.world.tilemap_interactive.set_cell(drop_location, tile_drop_item)
else:
push_warning("Could not find valid drop position for ", inventory_slot)
else:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_drop_item)
inventory_slot = pick_up_item_type
else:
# inventory is full, swap the item
print("Inventory is full. Swapping item: ", inventory_slot, " with item: ", pick_up_item_type)
EventsTracker.track(EventsTracker.Event.PLAYER_DROPPED_ITEM, {"item": inventory_slot})
EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type})
if tile_after_pickup_transform:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform)
var drop_location: Vector2i = game_manager.world.find_item_drop_location(tilemap_pos)
if drop_location != tilemap_types.EMPTY:
game_manager.world.tilemap_interactive.set_cell(drop_location, tile_drop_item)
else:
push_warning("Could not find valid drop position for ", inventory_slot)
else:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_drop_item)
inventory_slot = pick_up_item_type
# SECTION: player movement
func walk_towards(position: Vector2i) -> void:
var path: Array[Vector2i] = game_manager.tilemap_navigation.find_path(board_position, position)
walk_along(path)
var path: Array[Vector2i] = game_manager.tilemap_navigation.find_path(board_position, position)
walk_along(path)
func walk_along(path: Array[Vector2i]) -> void:
if len(path) > 1:
if len(path) > 1:
var next_position: Vector2i
if path.has(board_position):
var current_index: int = path.find(board_position)
if current_index < path.size() - 1:
next_position = path[current_index + 1]
else:
next_position = path[1]
else:
next_position = path[1]
var next_position: Vector2i
if path.has(board_position):
var current_index: int = path.find(board_position)
if current_index < path.size() - 1:
next_position = path[current_index + 1]
else:
next_position = path[1]
else:
next_position = path[1]
var direction: Vector2i = find_direction(board_position, next_position)
move_player(direction)
game_manager.tilemap_navigation.chosen_path = path
else:
push_warning("walk_along path is empty")
var direction: Vector2i = find_direction(board_position, next_position)
move_player(direction)
game_manager.tilemap_navigation.chosen_path = path
else:
push_warning("walk_along path is empty")
func move_player(direction: Vector2i) -> void:
var new_position: Vector2 = board_position + direction
if game_manager.world.is_walkable(new_position):
board_position = new_position
else:
push_warning("Player trying to move to non-walkable position, prevented ", new_position)
var new_position: Vector2 = board_position + direction
if game_manager.world.is_walkable(new_position):
board_position = new_position
else:
push_warning("Player trying to move to non-walkable position, prevented ", new_position)
func find_nearest_object(object_collection: Array[Vector2i]) -> Vector2i:
var object_positions: Array[Vector2i] = []
var object_positions: Array[Vector2i] = []
for obj in object_collection:
object_positions.append_array(game_manager.world.tilemap_interactive.get_cells_by_type(obj))
for obj in object_collection:
object_positions.append_array(game_manager.world.tilemap_interactive.get_cells_by_type(obj))
if object_positions.size() == 0:
push_warning("No " + str(object_collection) + " found!")
return tilemap_types.NO_TILE_FOUND
if object_positions.size() == 0:
push_warning("No " + str(object_collection) + " found!")
return tilemap_types.NO_TILE_FOUND
var closest_object: Vector2i = tilemap_types.NO_TILE_FOUND
var shortest_distance: float = 99999999
var closest_object: Vector2i = tilemap_types.NO_TILE_FOUND
var shortest_distance: float = 99999999
for position in object_positions:
var distance: float = game_manager.tilemap_navigation.manhattan_distance(board_position, position)
if closest_object == tilemap_types.NO_TILE_FOUND or distance < shortest_distance:
closest_object = position
shortest_distance = distance
for position in object_positions:
var distance: float = game_manager.tilemap_navigation.manhattan_distance(board_position, position)
if closest_object == tilemap_types.NO_TILE_FOUND or distance < shortest_distance:
closest_object = position
shortest_distance = distance
print("Find nearest " + str(object_collection) + " at:", closest_object)
return closest_object
print("Find nearest " + str(object_collection) + " at:", closest_object)
return closest_object
func find_direction(pos_a: Vector2i, pos_b: Vector2i) -> Vector2i:
var direction: Vector2i = Vector2i(0, 0)
if pos_a.x < pos_b.x:
direction.x = 1
elif pos_a.x > pos_b.x:
direction.x = -1
var direction: Vector2i = Vector2i(0, 0)
if pos_a.x < pos_b.x:
direction.x = 1
elif pos_a.x > pos_b.x:
direction.x = -1
if pos_a.y < pos_b.y:
direction.y = 1
elif pos_a.y > pos_b.y:
direction.y = -1
if pos_a.y < pos_b.y:
direction.y = 1
elif pos_a.y > pos_b.y:
direction.y = -1
return direction
return direction
# SECTION: game tick
func get_current_temperature() -> int:
return game_manager.world.tilemap_temperature.get_custom_data(board_position, "temperature", 0) as int
return game_manager.world.tilemap_temperature.get_custom_data(board_position, "temperature", 0) as int
func tick_handle_temperature(cell_temperature: int) -> void:
if temperature_buff_timer > 0:
temperature_buff_timer -= 1
return
if temperature_buff_timer > 0:
temperature_buff_timer -= 1
return
if cell_temperature == 0:
temperature_timer = 0
elif temperature_timer > temperature_endure:
temperature_timer += cell_temperature
health -= temperature_damage
if cell_temperature == 0:
temperature_timer = 0
elif temperature_timer > temperature_endure:
temperature_timer += cell_temperature
health -= temperature_damage
func tick_handle_food():
if food > 0:
food -= 1
if food <= 0:
health -= food_damage
if food > 0:
food -= 1
if food <= 0:
health -= food_damage
func game_tick() -> void:
behavior_tree.game_tick()
StepVisualization.add_circle_tileset(board_position, view_distance / 1.2, StepVisualization.CircleType.PLAYER_VIEW)
behavior_tree.game_tick()
StepVisualization.add_circle_tileset(board_position, view_distance / 1.2, StepVisualization.CircleType.PLAYER_VIEW)
tick_handle_temperature(get_current_temperature())
tick_handle_food()
tick_handle_temperature(get_current_temperature())
tick_handle_food()
if health < 0:
game_manager.player_health_depleted()
if health < 0:
game_manager.player_health_depleted()
update_board()
update_board()

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://di16cmfomo60u"
path="res://.godot/imported/Dein Abschnittstext.png-6c4790c5adae04235efb3264c83686ea.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://scripts/tilemap/Dein Abschnittstext.png"
dest_files=["res://.godot/imported/Dein Abschnittstext.png-6c4790c5adae04235efb3264c83686ea.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -17,30 +17,30 @@ var camp_manager: CampManager = CampManager.new()
func _ready() -> void:
tilemap_ground.sid = 0
tilemap_ground.tilemap = $GroundLayer
tilemap_non_interactive.sid = 1
tilemap_non_interactive.tilemap = $NonInteractiveObjectsLayer
tilemap_interactive.sid = 1
tilemap_interactive.tilemap = $InteractiveObjectsLayer
tilemap_player.sid = 3
tilemap_player.tilemap = $PlayerLayer
tilemap_temperature.sid = 2
tilemap_temperature.tilemap = $TemperatureLayer
tilemap_nav_vis.sid = 2
tilemap_nav_vis.tilemap = $NavigationVisualization
tilemap_ground.sid = 0
tilemap_ground.tilemap = $GroundLayer
tilemap_non_interactive.sid = 1
tilemap_non_interactive.tilemap = $NonInteractiveObjectsLayer
tilemap_interactive.sid = 1
tilemap_interactive.tilemap = $InteractiveObjectsLayer
tilemap_player.sid = 3
tilemap_player.tilemap = $PlayerLayer
tilemap_temperature.sid = 2
tilemap_temperature.tilemap = $TemperatureLayer
tilemap_nav_vis.sid = 2
tilemap_nav_vis.tilemap = $NavigationVisualization
tilemap_ground.setup()
tilemap_non_interactive.setup()
tilemap_interactive.setup()
tilemap_player.setup()
tilemap_temperature.setup()
tilemap_ground.setup()
tilemap_non_interactive.setup()
tilemap_interactive.setup()
tilemap_player.setup()
tilemap_temperature.setup()
call_deferred("defer_ready")
call_deferred("defer_ready")
func defer_ready() -> void:
camp_manager.setup()
camp_manager.setup()
# example usage
@ -52,53 +52,53 @@ func defer_ready() -> void:
# print(tilemap_ground.local_to_cell(get_local_mouse_position()))
func tilemap_mouse_position() -> Vector2i:
return tilemap_ground.local_to_cell(get_local_mouse_position())
return tilemap_ground.local_to_cell(get_local_mouse_position())
func find_item_drop_location(center_pos: Vector2i) -> Vector2i:
for x in range(center_pos.x - 1, center_pos.x + 1):
for y in range(center_pos.y - 1, center_pos.y + 1):
var check_pos: Vector2i = Vector2i(x, y)
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
return check_pos
for x in range(center_pos.x - 2, center_pos.x + 2):
for y in range(center_pos.y - 2, center_pos.y + 2):
var check_pos: Vector2i = Vector2i(x, y)
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
return check_pos
return Vector2i(-1, -1)
for x in range(center_pos.x - 1, center_pos.x + 1):
for y in range(center_pos.y - 1, center_pos.y + 1):
var check_pos: Vector2i = Vector2i(x, y)
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
return check_pos
for x in range(center_pos.x - 2, center_pos.x + 2):
for y in range(center_pos.y - 2, center_pos.y + 2):
var check_pos: Vector2i = Vector2i(x, y)
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
return check_pos
return Vector2i(-1, -1)
func is_walkable(position: Vector2i) -> bool:
var ground_tile_walkable: bool = tilemap_ground.get_custom_data(position, "walkable", false)
var non_interactive_walkable: bool = tilemap_non_interactive.get_custom_data(position, "walkable", true)
var interactive_walkable: bool = tilemap_interactive.get_custom_data(position, "walkable", true)
var ground_tile_walkable: bool = tilemap_ground.get_custom_data(position, "walkable", false)
var non_interactive_walkable: bool = tilemap_non_interactive.get_custom_data(position, "walkable", true)
var interactive_walkable: bool = tilemap_interactive.get_custom_data(position, "walkable", true)
return ground_tile_walkable and non_interactive_walkable and interactive_walkable
return ground_tile_walkable and non_interactive_walkable and interactive_walkable
func game_tick_start() -> void:
step_visualizer.game_tick_start()
camp_manager.game_tick_start()
step_visualizer.game_tick_start()
camp_manager.game_tick_start()
# refill empty bushes
var empty_bushes: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_EMPTY_BUSH)
for bush in empty_bushes:
if randf() < 0.01:
tilemap_interactive.set_cell(bush, tilemap_types.OBJECT_I_FILLED_BUSH)
# refill empty bushes
var empty_bushes: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_EMPTY_BUSH)
for bush in empty_bushes:
if randf() < 0.01:
tilemap_interactive.set_cell(bush, tilemap_types.OBJECT_I_FILLED_BUSH)
# refill empty trees
var empty_trees: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TREE_CUT)
for tree in empty_trees:
if randf() < 0.01:
tilemap_interactive.set_cell(tree, tilemap_types.OBJECT_I_TREE_FULL)
# refill empty trees
var empty_trees: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TREE_CUT)
for tree in empty_trees:
if randf() < 0.01:
tilemap_interactive.set_cell(tree, tilemap_types.OBJECT_I_TREE_FULL)
# mark all boat parts on the map
var boat_parts: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS)
for part in boat_parts:
StepVisualization.add_circle_tileset(part, 1, StepVisualization.CircleType.BOAT_PART)
# mark all boat parts on the map
var boat_parts: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS)
for part in boat_parts:
StepVisualization.add_circle_tileset(part, 1, StepVisualization.CircleType.BOAT_PART)
func game_tick_end() -> void:
step_visualizer.game_tick_end()
camp_manager.game_tick_end()
step_visualizer.game_tick_end()
camp_manager.game_tick_end()