Added auto-waking toggle with auto-follow and zoom, and better different screen sizes support
parent
d026c07804
commit
dc3ead30b4
Binary file not shown.
|
Before Width: | Height: | Size: 941 KiB After Width: | Height: | Size: 436 KiB |
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=50 format=4 uid="uid://b88asko1ugyd2"]
|
[gd_scene load_steps=46 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/global/GameManager.gd" id="1_eeg2d"]
|
||||||
[ext_resource type="Script" path="res://scripts/tilemap/World.gd" id="1_k0rw8"]
|
[ext_resource type="Script" path="res://scripts/tilemap/World.gd" id="1_k0rw8"]
|
||||||
|
|
@ -46,72 +46,6 @@
|
||||||
[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/TaskPutInventoryContentInCamp.gd" id="39_8rirr"]
|
||||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/game/camp/TaskCampSleep.gd" id="39_nbuyx"]
|
[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_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="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="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"]
|
[node name="Island-scene" type="Node2D"]
|
||||||
script = ExtResource("1_eeg2d")
|
script = ExtResource("1_eeg2d")
|
||||||
metadata/_edit_vertical_guides_ = [1900.0, 4004.0]
|
metadata/_edit_vertical_guides_ = [1900.0, 4004.0]
|
||||||
|
|
@ -121,28 +55,6 @@ metadata/_edit_horizontal_guides_ = [2097.0]
|
||||||
position = Vector2(2451, 3007)
|
position = Vector2(2451, 3007)
|
||||||
script = ExtResource("2_k51iv")
|
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="CanvasLayer" type="CanvasLayer" parent="Camera2D"]
|
||||||
|
|
||||||
[node name="Vignette" type="ColorRect" parent="Camera2D/CanvasLayer"]
|
[node name="Vignette" type="ColorRect" parent="Camera2D/CanvasLayer"]
|
||||||
|
|
@ -157,6 +69,7 @@ size_flags_horizontal = 4
|
||||||
[node name="TopLeftContainer" type="MarginContainer" parent="Camera2D/CanvasLayer"]
|
[node name="TopLeftContainer" type="MarginContainer" parent="Camera2D/CanvasLayer"]
|
||||||
offset_right = 204.0
|
offset_right = 204.0
|
||||||
offset_bottom = 122.0
|
offset_bottom = 122.0
|
||||||
|
scale = Vector2(1.3, 1.3)
|
||||||
theme_override_constants/margin_left = 5
|
theme_override_constants/margin_left = 5
|
||||||
theme_override_constants/margin_top = 5
|
theme_override_constants/margin_top = 5
|
||||||
|
|
||||||
|
|
@ -291,6 +204,7 @@ anchor_bottom = 1.0
|
||||||
offset_top = -5.0
|
offset_top = -5.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
size_flags_vertical = 8
|
||||||
theme_override_constants/margin_left = 5
|
theme_override_constants/margin_left = 5
|
||||||
theme_override_constants/margin_bottom = 5
|
theme_override_constants/margin_bottom = 5
|
||||||
|
|
||||||
|
|
@ -304,6 +218,7 @@ size_flags_vertical = 8
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
position = Vector2i(0, 36)
|
position = Vector2i(0, 36)
|
||||||
size = Vector2i(1075, 225)
|
size = Vector2i(1075, 225)
|
||||||
|
visible = false
|
||||||
script = ExtResource("5_ecfvx")
|
script = ExtResource("5_ecfvx")
|
||||||
|
|
||||||
[node name="GraphEdit" type="GraphEdit" parent="Camera2D/CanvasLayer/TreeVisualizer"]
|
[node name="GraphEdit" type="GraphEdit" parent="Camera2D/CanvasLayer/TreeVisualizer"]
|
||||||
|
|
@ -321,6 +236,12 @@ show_grid_buttons = false
|
||||||
show_minimap_button = false
|
show_minimap_button = false
|
||||||
show_arrange_button = false
|
show_arrange_button = false
|
||||||
|
|
||||||
|
[node name="IntroImage" type="Sprite2D" parent="Camera2D"]
|
||||||
|
visible = false
|
||||||
|
z_index = 1
|
||||||
|
scale = Vector2(0.347656, 0.373264)
|
||||||
|
texture = ExtResource("3_oufrl")
|
||||||
|
|
||||||
[node name="Tileset" type="Node2D" parent="."]
|
[node name="Tileset" type="Node2D" parent="."]
|
||||||
script = ExtResource("1_k0rw8")
|
script = ExtResource("1_k0rw8")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,11 @@ key_6={
|
||||||
"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":54,"key_label":0,"unicode":54,"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":54,"key_label":0,"unicode":54,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
auto_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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,115 +22,115 @@ var force_zoom: Vector2 = DISABLE_FORCE
|
||||||
|
|
||||||
|
|
||||||
func go_to_zooming(position: Vector2, zoom: float) -> void:
|
func go_to_zooming(position: Vector2, zoom: float) -> void:
|
||||||
force_target_position = position
|
force_target_position = position
|
||||||
force_zoom = Vector2(zoom, zoom)
|
force_zoom = Vector2(zoom, zoom)
|
||||||
|
|
||||||
|
|
||||||
func go_to(position: Vector2) -> void:
|
func go_to(position: Vector2) -> void:
|
||||||
force_target_position = position
|
force_target_position = position
|
||||||
|
|
||||||
|
|
||||||
func print_config() -> void:
|
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:
|
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):
|
func _input(event):
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
if force_zoom == DISABLE_FORCE:
|
if force_zoom == DISABLE_FORCE:
|
||||||
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||||
zoom = zoom * 1.1
|
zoom = zoom * 1.1
|
||||||
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||||
zoom = zoom / 1.1
|
zoom = zoom / 1.1
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if Input.is_action_just_pressed("camera_drag"):
|
if Input.is_action_just_pressed("camera_drag"):
|
||||||
drag_active = true
|
drag_active = true
|
||||||
drag_start = get_viewport().get_mouse_position()
|
drag_start = get_viewport().get_mouse_position()
|
||||||
if Input.is_action_just_released("camera_drag"):
|
if Input.is_action_just_released("camera_drag"):
|
||||||
drag_active = false
|
drag_active = false
|
||||||
if drag_active:
|
if drag_active:
|
||||||
var drag_end: Vector2 = get_viewport().get_mouse_position()
|
var drag_end: Vector2 = get_viewport().get_mouse_position()
|
||||||
var drag_offset: Vector2 = drag_end - drag_start
|
var drag_offset: Vector2 = drag_end - drag_start
|
||||||
drag_start = drag_end
|
drag_start = drag_end
|
||||||
position -= drag_offset / zoom
|
position -= drag_offset / zoom
|
||||||
|
|
||||||
if force_target_position != DISABLE_FORCE:
|
if force_target_position != DISABLE_FORCE:
|
||||||
# move towards the target position
|
# move towards the target position
|
||||||
var offset: Vector2 = force_target_position - position
|
var offset: Vector2 = force_target_position - position
|
||||||
position += offset * 0.1
|
position += offset * 0.1
|
||||||
if offset.length() < 1:
|
if offset.length() < 1:
|
||||||
force_target_position = DISABLE_FORCE
|
force_target_position = DISABLE_FORCE
|
||||||
if force_zoom != DISABLE_FORCE:
|
if force_zoom != DISABLE_FORCE:
|
||||||
# move towards the target zoom
|
# move towards the target zoom
|
||||||
var offset: Vector2 = force_zoom - zoom
|
var offset: Vector2 = force_zoom - zoom
|
||||||
zoom += offset * 0.04
|
zoom += offset * 0.04
|
||||||
if offset.length() < 0.02:
|
if offset.length() < 0.02:
|
||||||
force_zoom = DISABLE_FORCE
|
force_zoom = DISABLE_FORCE
|
||||||
else:
|
else:
|
||||||
var is_zoom_in: bool = Input.is_action_pressed("camera_zoom_in")
|
var is_zoom_in: bool = Input.is_action_pressed("camera_zoom_in")
|
||||||
var is_zoom_out: bool = Input.is_action_pressed("camera_zoom_out")
|
var is_zoom_out: bool = Input.is_action_pressed("camera_zoom_out")
|
||||||
|
|
||||||
if is_zoom_in:
|
if is_zoom_in:
|
||||||
zoom = zoom * 1.02
|
zoom = zoom * 1.02
|
||||||
elif is_zoom_out:
|
elif is_zoom_out:
|
||||||
zoom = zoom / 1.02
|
zoom = zoom / 1.02
|
||||||
|
|
||||||
if zoom.length() < 0.2:
|
if zoom.length() < 0.2:
|
||||||
zoom = Vector2(1, 1).normalized() * 0.2
|
zoom = Vector2(1, 1).normalized() * 0.2
|
||||||
elif zoom.length() > 10:
|
elif zoom.length() > 10:
|
||||||
zoom = Vector2(1, 1).normalized() * 10
|
zoom = Vector2(1, 1).normalized() * 10
|
||||||
|
|
||||||
var mouse_pos: Vector2 = get_viewport().get_mouse_position()
|
var mouse_pos: Vector2 = get_viewport().get_mouse_position()
|
||||||
var screen_size: Vector2 = get_viewport().get_visible_rect().size
|
var screen_size: Vector2 = get_viewport().get_visible_rect().size
|
||||||
var acceleration: Vector2 = Vector2.ZERO
|
var acceleration: Vector2 = Vector2.ZERO
|
||||||
|
|
||||||
# the bigger the viewport size, the bigger the border threshold
|
# 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 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_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_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_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_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:
|
if is_left:
|
||||||
acceleration.x = -border_acceleration
|
acceleration.x = -border_acceleration
|
||||||
elif is_right:
|
elif is_right:
|
||||||
acceleration.x = border_acceleration
|
acceleration.x = border_acceleration
|
||||||
|
|
||||||
if is_up:
|
if is_up:
|
||||||
acceleration.y = -border_acceleration
|
acceleration.y = -border_acceleration
|
||||||
elif is_down:
|
elif is_down:
|
||||||
acceleration.y = border_acceleration
|
acceleration.y = border_acceleration
|
||||||
|
|
||||||
acceleration *= Vector2.ONE / zoom
|
acceleration *= Vector2.ONE / zoom
|
||||||
|
|
||||||
if acceleration.length() > 0:
|
if acceleration.length() > 0:
|
||||||
# if the acceleration is the opposite direction of the velocity, double the acceleration
|
# if the acceleration is the opposite direction of the velocity, double the acceleration
|
||||||
if acceleration.dot(velocity) < 0:
|
if acceleration.dot(velocity) < 0:
|
||||||
acceleration = acceleration * 2
|
acceleration = acceleration * 2
|
||||||
velocity = velocity + acceleration * delta
|
velocity = velocity + acceleration * delta
|
||||||
else:
|
else:
|
||||||
velocity = velocity.move_toward(Vector2.ZERO, border_acceleration * delta)
|
velocity = velocity.move_toward(Vector2.ZERO, border_acceleration * delta)
|
||||||
|
|
||||||
if velocity.length() > max_speed:
|
if velocity.length() > max_speed:
|
||||||
velocity = velocity.normalized() * max_speed
|
velocity = velocity.normalized() * max_speed
|
||||||
|
|
||||||
var target_offset = velocity * delta
|
var target_offset = velocity * delta
|
||||||
var target_position = position + target_offset
|
var target_position = position + target_offset
|
||||||
target_position.x = clamp(target_position.x, min_position.x, max_position.x)
|
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)
|
target_position.y = clamp(target_position.y, min_position.y, max_position.y)
|
||||||
|
|
||||||
var offset: Vector2 = target_position - position
|
var offset: Vector2 = target_position - position
|
||||||
position += offset
|
position += offset
|
||||||
|
|
||||||
|
|
||||||
# SECTION: shader access
|
# SECTION: shader access
|
||||||
|
|
||||||
func set_vignette_intensity(value: float) -> void:
|
func set_vignette_intensity(value: float) -> void:
|
||||||
var material: ShaderMaterial = shader_vignette.material
|
var material: ShaderMaterial = shader_vignette.material
|
||||||
material.set_shader_parameter("vignette_strength", value)
|
material.set_shader_parameter("vignette_strength", value)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ enum Event {
|
||||||
};
|
};
|
||||||
#
|
#
|
||||||
static var events: Array[TrackedEvent] = []
|
static var events: Array[TrackedEvent] = []
|
||||||
static var max_events: int = 20
|
static var max_events: int = 14
|
||||||
static var callbacks: Array[Callable] = []
|
static var callbacks: Array[Callable] = []
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,9 +79,9 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con
|
||||||
elif event_id == Event.GAME_STATE_WIN:
|
elif event_id == Event.GAME_STATE_WIN:
|
||||||
text = "Game won"
|
text = "Game won"
|
||||||
elif event_id == Event.NEW_EXPLORATION_GOAL:
|
elif event_id == Event.NEW_EXPLORATION_GOAL:
|
||||||
text = "New exploration goal " + str(params["goal"])
|
text = "New goal " + str(params["goal"])
|
||||||
elif event_id == Event.EXPLORATION_GOAL_REACHED:
|
elif event_id == Event.EXPLORATION_GOAL_REACHED:
|
||||||
text = "Exploration goal reached " + str(params["goal"])
|
text = "Goal reached"
|
||||||
elif event_id == Event.TEMPERATURE_COLD:
|
elif event_id == Event.TEMPERATURE_COLD:
|
||||||
text = "Temperature is cold: -" + str(params["temperature"])
|
text = "Temperature is cold: -" + str(params["temperature"])
|
||||||
elif event_id == Event.TIME_SUNDOWN:
|
elif event_id == Event.TIME_SUNDOWN:
|
||||||
|
|
@ -91,6 +91,7 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con
|
||||||
|
|
||||||
var event_label: Label = Label.new()
|
var event_label: Label = Label.new()
|
||||||
event_label.text = text
|
event_label.text = text
|
||||||
|
event_label.add_theme_font_size_override("font_size", 24 * game_manager.calculate_scale(Vector2(1200, 1200)).y)
|
||||||
event_label.add_theme_color_override("font_color", Color(0, 0, 0))
|
event_label.add_theme_color_override("font_color", Color(0, 0, 0))
|
||||||
|
|
||||||
var event_container: HBoxContainer = HBoxContainer.new()
|
var event_container: HBoxContainer = HBoxContainer.new()
|
||||||
|
|
@ -101,6 +102,8 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con
|
||||||
if item_texture:
|
if item_texture:
|
||||||
var item_texture_rect: TextureRect = TextureRect.new()
|
var item_texture_rect: TextureRect = TextureRect.new()
|
||||||
item_texture_rect.texture = item_texture
|
item_texture_rect.texture = item_texture
|
||||||
|
item_texture_rect.set_expand_mode(TextureRect.EXPAND_FIT_WIDTH)
|
||||||
|
item_texture_rect.set_stretch_mode(TextureRect.STRETCH_KEEP_ASPECT_CENTERED)
|
||||||
event_container.add_child(item_texture_rect)
|
event_container.add_child(item_texture_rect)
|
||||||
|
|
||||||
container.add_child(event_container)
|
container.add_child(event_container)
|
||||||
|
|
|
||||||
|
|
@ -14,120 +14,167 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
||||||
@onready var temperature_resistance_bar: ProgressBar = %TemperatureResistanceBar
|
@onready var temperature_resistance_bar: ProgressBar = %TemperatureResistanceBar
|
||||||
|
|
||||||
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
|
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
|
||||||
var waiting_for_input = true
|
|
||||||
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
|
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
|
||||||
@onready var animation_player = $Camera2D/AnimationPlayer
|
|
||||||
@onready var sprite = $Camera2D/Sprite2D
|
#
|
||||||
@onready var color_rect = $Camera2D/ColorRect
|
var waiting_for_input: bool = true
|
||||||
|
|
||||||
|
@onready var intro_image: Sprite2D = $Camera2D/IntroImage
|
||||||
|
|
||||||
|
|
||||||
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()
|
update_bars()
|
||||||
if animation_player and sprite:
|
call_deferred("defer_ready")
|
||||||
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:
|
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
|
||||||
|
await wait_for_key_press()
|
||||||
|
get_tree().create_tween().tween_method(set_intro_opacity, 1.0, 0.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("key_6"):
|
if Input.is_action_just_pressed("force_game_tick"):
|
||||||
camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561)
|
Task.print_behavior_tree_evaluation = true
|
||||||
if Input.is_action_just_pressed("key_3"):
|
_on_game_tick_timeout()
|
||||||
camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448)
|
Task.print_behavior_tree_evaluation = false
|
||||||
if Input.is_action_just_pressed("key_9"):
|
if Input.is_action_pressed("force_game_tick_fast"):
|
||||||
world.camp_manager.campfire_light()
|
_on_game_tick_timeout()
|
||||||
world.camp_manager.sleep_effect()
|
if Input.is_action_just_pressed("key_2"):
|
||||||
world.camp_manager.campfire_extinguish()
|
toggle_temperature_layer()
|
||||||
if Input.is_action_just_pressed("force_game_tick"):
|
camera.print_config()
|
||||||
Task.print_behavior_tree_evaluation = true
|
if Input.is_action_just_pressed("auto_tick"):
|
||||||
_on_game_tick_timeout()
|
if game_ticker.is_stopped():
|
||||||
Task.print_behavior_tree_evaluation = false
|
game_ticker.start()
|
||||||
if Input.is_action_pressed("force_game_tick_fast"):
|
else:
|
||||||
_on_game_tick_timeout()
|
game_ticker.stop()
|
||||||
if Input.is_action_just_pressed("key_2"):
|
|
||||||
toggle_temperature_layer()
|
|
||||||
|
|
||||||
|
if intro_image.is_visible():
|
||||||
|
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
||||||
|
|
||||||
|
|
||||||
|
func calculate_scale(image_size: Vector2) -> Vector2:
|
||||||
|
var viewport_size: Vector2 = world.get_viewport_rect().size
|
||||||
|
var scale: float = viewport_size.x / image_size.x
|
||||||
|
return Vector2(scale, scale)
|
||||||
|
|
||||||
|
|
||||||
|
# SECTION: intro
|
||||||
|
|
||||||
|
func set_intro_opacity(opacity: float) -> void:
|
||||||
|
intro_image.set_modulate(Color(1, 1, 1, opacity))
|
||||||
|
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
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)
|
handle_result_game_state(player.behavior_tree.blackboard)
|
||||||
|
|
||||||
timer_on_game_tick_timeout.stop()
|
if not game_ticker.is_stopped():
|
||||||
|
camera_follow_player()
|
||||||
|
|
||||||
|
timer_on_game_tick_timeout.stop()
|
||||||
|
|
||||||
|
|
||||||
|
func camera_follow_player() -> void:
|
||||||
|
var player_position: Vector2 = world.tilemap_player.cell_to_local(player.board_position)
|
||||||
|
var targeted_position = null
|
||||||
|
|
||||||
|
if player.behavior_tree.blackboard.has("path"):
|
||||||
|
var path: Array = player.behavior_tree.blackboard["path"]
|
||||||
|
if path.size() > 0:
|
||||||
|
targeted_position = world.tilemap_player.cell_to_local(path[path.size() - 1])
|
||||||
|
|
||||||
|
if not targeted_position:
|
||||||
|
camera.go_to(player_position)
|
||||||
|
return
|
||||||
|
|
||||||
|
var avg_position = (player_position + targeted_position) / 2
|
||||||
|
var distance: float = player_position.distance_to(targeted_position)
|
||||||
|
if distance < 200:
|
||||||
|
camera.go_to_zooming(avg_position, distance_to_zoom_level(200))
|
||||||
|
else:
|
||||||
|
var zoom_level: float = distance_to_zoom_level(distance)
|
||||||
|
camera.go_to_zooming(avg_position, zoom_level)
|
||||||
|
|
||||||
|
|
||||||
|
func distance_to_zoom_level(distance: float) -> float:
|
||||||
|
var a: float = 862.08
|
||||||
|
var b: float = 274.13
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
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():
|
||||||
while waiting_for_input:
|
waiting_for_input = true
|
||||||
await get_tree().process_frame
|
while waiting_for_input:
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -17,30 +17,30 @@ var camp_manager: CampManager = CampManager.new()
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
tilemap_ground.sid = 0
|
tilemap_ground.sid = 0
|
||||||
tilemap_ground.tilemap = $GroundLayer
|
tilemap_ground.tilemap = $GroundLayer
|
||||||
tilemap_non_interactive.sid = 1
|
tilemap_non_interactive.sid = 1
|
||||||
tilemap_non_interactive.tilemap = $NonInteractiveObjectsLayer
|
tilemap_non_interactive.tilemap = $NonInteractiveObjectsLayer
|
||||||
tilemap_interactive.sid = 1
|
tilemap_interactive.sid = 1
|
||||||
tilemap_interactive.tilemap = $InteractiveObjectsLayer
|
tilemap_interactive.tilemap = $InteractiveObjectsLayer
|
||||||
tilemap_player.sid = 3
|
tilemap_player.sid = 3
|
||||||
tilemap_player.tilemap = $PlayerLayer
|
tilemap_player.tilemap = $PlayerLayer
|
||||||
tilemap_temperature.sid = 2
|
tilemap_temperature.sid = 2
|
||||||
tilemap_temperature.tilemap = $TemperatureLayer
|
tilemap_temperature.tilemap = $TemperatureLayer
|
||||||
tilemap_nav_vis.sid = 2
|
tilemap_nav_vis.sid = 2
|
||||||
tilemap_nav_vis.tilemap = $NavigationVisualization
|
tilemap_nav_vis.tilemap = $NavigationVisualization
|
||||||
|
|
||||||
tilemap_ground.setup()
|
tilemap_ground.setup()
|
||||||
tilemap_non_interactive.setup()
|
tilemap_non_interactive.setup()
|
||||||
tilemap_interactive.setup()
|
tilemap_interactive.setup()
|
||||||
tilemap_player.setup()
|
tilemap_player.setup()
|
||||||
tilemap_temperature.setup()
|
tilemap_temperature.setup()
|
||||||
|
|
||||||
call_deferred("defer_ready")
|
call_deferred("defer_ready")
|
||||||
|
|
||||||
|
|
||||||
func defer_ready() -> void:
|
func defer_ready() -> void:
|
||||||
camp_manager.setup()
|
camp_manager.setup()
|
||||||
|
|
||||||
|
|
||||||
# example usage
|
# example usage
|
||||||
|
|
@ -52,53 +52,53 @@ func defer_ready() -> void:
|
||||||
# print(tilemap_ground.local_to_cell(get_local_mouse_position()))
|
# print(tilemap_ground.local_to_cell(get_local_mouse_position()))
|
||||||
|
|
||||||
func tilemap_mouse_position() -> Vector2i:
|
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:
|
func find_item_drop_location(center_pos: Vector2i) -> Vector2i:
|
||||||
for x in range(center_pos.x - 1, center_pos.x + 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):
|
for y in range(center_pos.y - 1, center_pos.y + 1):
|
||||||
var check_pos: Vector2i = Vector2i(x, y)
|
var check_pos: Vector2i = Vector2i(x, y)
|
||||||
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
|
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
|
||||||
return check_pos
|
return check_pos
|
||||||
for x in range(center_pos.x - 2, center_pos.x + 2):
|
for x in range(center_pos.x - 2, center_pos.x + 2):
|
||||||
for y in range(center_pos.y - 2, center_pos.y + 2):
|
for y in range(center_pos.y - 2, center_pos.y + 2):
|
||||||
var check_pos: Vector2i = Vector2i(x, y)
|
var check_pos: Vector2i = Vector2i(x, y)
|
||||||
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
|
if not tilemap_interactive.get_cell(check_pos) and is_walkable(check_pos):
|
||||||
return check_pos
|
return check_pos
|
||||||
return Vector2i(-1, -1)
|
return Vector2i(-1, -1)
|
||||||
|
|
||||||
|
|
||||||
func is_walkable(position: Vector2i) -> bool:
|
func is_walkable(position: Vector2i) -> bool:
|
||||||
var ground_tile_walkable: bool = tilemap_ground.get_custom_data(position, "walkable", false)
|
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 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 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:
|
func game_tick_start() -> void:
|
||||||
step_visualizer.game_tick_start()
|
step_visualizer.game_tick_start()
|
||||||
camp_manager.game_tick_start()
|
camp_manager.game_tick_start()
|
||||||
|
|
||||||
# refill empty bushes
|
# refill empty bushes
|
||||||
var empty_bushes: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_EMPTY_BUSH)
|
var empty_bushes: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_EMPTY_BUSH)
|
||||||
for bush in empty_bushes:
|
for bush in empty_bushes:
|
||||||
if randf() < 0.01:
|
if randf() < 0.01:
|
||||||
tilemap_interactive.set_cell(bush, tilemap_types.OBJECT_I_FILLED_BUSH)
|
tilemap_interactive.set_cell(bush, tilemap_types.OBJECT_I_FILLED_BUSH)
|
||||||
|
|
||||||
# refill empty trees
|
# refill empty trees
|
||||||
var empty_trees: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TREE_CUT)
|
var empty_trees: Array[Vector2i] = tilemap_interactive.get_cells_by_type(tilemap_types.OBJECT_I_TREE_CUT)
|
||||||
for tree in empty_trees:
|
for tree in empty_trees:
|
||||||
if randf() < 0.01:
|
if randf() < 0.01:
|
||||||
tilemap_interactive.set_cell(tree, tilemap_types.OBJECT_I_TREE_FULL)
|
tilemap_interactive.set_cell(tree, tilemap_types.OBJECT_I_TREE_FULL)
|
||||||
|
|
||||||
# mark all boat parts on the map
|
# 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)
|
var boat_parts: Array[Vector2i] = tilemap_interactive.get_cells_by_type_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS)
|
||||||
for part in boat_parts:
|
for part in boat_parts:
|
||||||
StepVisualization.add_circle_tileset(part, 1, StepVisualization.CircleType.BOAT_PART)
|
StepVisualization.add_circle_tileset(part, 1, StepVisualization.CircleType.BOAT_PART)
|
||||||
|
|
||||||
|
|
||||||
func game_tick_end() -> void:
|
func game_tick_end() -> void:
|
||||||
step_visualizer.game_tick_end()
|
step_visualizer.game_tick_end()
|
||||||
camp_manager.game_tick_end()
|
camp_manager.game_tick_end()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue