forked from 2121578/gai-ca2
Started writing visualization and added new state machine mode
parent
bfca1ff23f
commit
3c61ce4e7f
|
@ -4,14 +4,14 @@
|
|||
[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="2_spils"]
|
||||
[ext_resource type="Script" path="res://scripts/player/PlayerManager.gd" id="4_1xqo1"]
|
||||
[ext_resource type="Script" path="res://scripts/tilemap/StepVisualization.gd" id="5_sr2su"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/BehaviorTree.gd" id="6_efs30"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/base/TaskSelector.gd" id="7_1jajd"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/testing/WalkUpToMouse.gd" id="8_s6mqc"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/base/TaskSequence.gd" id="9_i67mw"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/base/GoToWhileRunningSuccessStop.gd" id="10_4v1m1"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/game/critical_survival/TaskCheckFoodCritical.gd" id="10_sf2pi"]
|
||||
[ext_resource type="Script" path="res://scripts/player/tree/impl/base/GoToSuccess.gd" id="11_84a4v"]
|
||||
|
||||
[node name="Island-scene" type="Node2D"]
|
||||
script = ExtResource("1_eeg2d")
|
||||
|
@ -22,7 +22,7 @@ script = ExtResource("2_k51iv")
|
|||
[node name="CanvasLayer" type="CanvasLayer" parent="Camera2D"]
|
||||
|
||||
[node name="Vignette" type="ColorRect" parent="Camera2D/CanvasLayer"]
|
||||
material = ExtResource("2_spils")
|
||||
visible = false
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -65,6 +65,9 @@ tile_set = ExtResource("1_vlccq")
|
|||
[node name="NavigationVisualization" type="TileMapLayer" parent="Tileset"]
|
||||
tile_set = ExtResource("1_vlccq")
|
||||
|
||||
[node name="StepVisualization" type="Node2D" parent="Tileset"]
|
||||
script = ExtResource("5_sr2su")
|
||||
|
||||
[node name="PlayerManager" type="Node" parent="."]
|
||||
script = ExtResource("4_1xqo1")
|
||||
|
||||
|
@ -83,8 +86,8 @@ script = ExtResource("9_i67mw")
|
|||
[node name="TaskCheckFoodCritical" type="Node" parent="PlayerManager/BehaviorTree/sl_Root/sl_CriticalSurvival/sq_Food"]
|
||||
script = ExtResource("10_sf2pi")
|
||||
|
||||
[node name="GoToSuccess" type="Node" parent="PlayerManager/BehaviorTree/sl_Root/sl_CriticalSurvival/sq_Food"]
|
||||
script = ExtResource("11_84a4v")
|
||||
[node name="GoToWhileRunningSuccessStop" type="Node" parent="PlayerManager/BehaviorTree/sl_Root/sl_CriticalSurvival/sq_Food"]
|
||||
script = ExtResource("10_4v1m1")
|
||||
|
||||
[node name="WalkUpToMouse" type="Node" parent="PlayerManager/BehaviorTree/sl_Root"]
|
||||
script = ExtResource("8_s6mqc")
|
||||
|
|
|
@ -3,7 +3,7 @@ extends Camera2D
|
|||
|
||||
@onready var shader_vignette: ColorRect = $CanvasLayer/Vignette
|
||||
|
||||
@export var border_acceleration: float = 0 # 2000.0
|
||||
@export var border_acceleration: float = 2000.0
|
||||
@export var max_speed: float = 500.0
|
||||
@export var inner_border_threshold: float = 60.0
|
||||
@export var outer_border_threshold: float = 40.0
|
||||
|
|
|
@ -14,6 +14,10 @@ func _ready() -> void:
|
|||
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
|
||||
|
||||
|
||||
# game_ticker.start()
|
||||
|
||||
|
||||
|
@ -27,7 +31,7 @@ func _process(delta: float) -> void:
|
|||
world.camp_manager.sleep_effect()
|
||||
world.camp_manager.campfire_extinguish()
|
||||
if Input.is_action_just_pressed("force_game_tick"):
|
||||
player.game_tick()
|
||||
_on_game_tick_timeout()
|
||||
|
||||
|
||||
func player_health_depleted():
|
||||
|
@ -39,6 +43,8 @@ func _on_game_tick_timeout() -> void:
|
|||
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
||||
timer_on_game_tick_timeout.display_name = "game tick duration"
|
||||
tilemap_navigation.game_tick_start()
|
||||
world.step_visualizer.game_tick_start()
|
||||
player.game_tick()
|
||||
tilemap_navigation.game_tick_end()
|
||||
world.step_visualizer.game_tick_end()
|
||||
timer_on_game_tick_timeout.stop()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class_name Task
|
||||
extends Node
|
||||
|
||||
enum {FAILURE = -1, SUCCESS = 1, RUNNING = 0}
|
||||
enum {FAILURE = -1, SUCCESS = 1, RUNNING = 0, SUCCESS_STOP = 2}
|
||||
var status: int = FAILURE
|
||||
var status_reason: String = ""
|
||||
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
||||
|
@ -71,6 +71,8 @@ func human_readable(addon: String = "") -> String:
|
|||
clear_status = "SUCCESS"
|
||||
elif status == RUNNING:
|
||||
clear_status = "RUNNING"
|
||||
elif status == SUCCESS_STOP:
|
||||
clear_status = "SUCCESS_STOP"
|
||||
|
||||
var ret: String = name;
|
||||
if addon != "":
|
||||
|
|
|
@ -16,11 +16,12 @@ func run(blackboard: Dictionary) -> void:
|
|||
status_reason = "path was empty"
|
||||
return
|
||||
|
||||
player.walk_along(path)
|
||||
|
||||
if navigation.has_arrived(player.board_position, path):
|
||||
status = SUCCESS
|
||||
status_reason = "already arrived at destination"
|
||||
return
|
||||
|
||||
player.walk_along(path)
|
||||
status = RUNNING
|
||||
status_reason = "walked along path, now at " + str(player.board_position)
|
||||
|
|
|
@ -16,11 +16,12 @@ func run(blackboard: Dictionary) -> void:
|
|||
status_reason = "path was empty"
|
||||
return
|
||||
|
||||
player.walk_along(path)
|
||||
|
||||
if navigation.has_arrived(player.board_position, path):
|
||||
status = SUCCESS
|
||||
status_reason = "already arrived at destination"
|
||||
return
|
||||
|
||||
player.walk_along(path)
|
||||
status = SUCCESS
|
||||
status_reason = "walked along path, now at " + str(player.board_position)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
class_name GoToWhileRunningSuccessStop
|
||||
extends Task
|
||||
|
||||
func run(blackboard: Dictionary) -> void:
|
||||
var player: PlayerManager = blackboard["player"]
|
||||
var navigation: TilemapNavigation = blackboard["navigation"]
|
||||
|
||||
if not blackboard.has("path"):
|
||||
status = FAILURE
|
||||
status_reason = "blackboard did not have path"
|
||||
return
|
||||
|
||||
var path: Array[Vector2i] = blackboard["path"]
|
||||
if path.size() == 0:
|
||||
status = FAILURE
|
||||
status_reason = "path was empty"
|
||||
return
|
||||
|
||||
player.walk_along(path)
|
||||
|
||||
if navigation.has_arrived(player.board_position, path):
|
||||
status = SUCCESS
|
||||
status_reason = "already arrived at destination"
|
||||
return
|
||||
|
||||
status = SUCCESS_STOP
|
||||
status_reason = "walked along path, now at " + str(player.board_position)
|
|
@ -4,7 +4,14 @@ extends Task
|
|||
func run(blackboard: Dictionary) -> void:
|
||||
for c in self.get_children():
|
||||
run_child(blackboard, c)
|
||||
if c.status == SUCCESS_STOP:
|
||||
c.status = SUCCESS
|
||||
status = SUCCESS
|
||||
status_reason = "stopping at child " + c.name + ", as it returned SUCCESS_STOP"
|
||||
return
|
||||
if c.status != FAILURE:
|
||||
status = c.status
|
||||
status_reason = "stopped at child " + c.name
|
||||
return
|
||||
status = FAILURE
|
||||
status_reason = "all children failed"
|
||||
|
|
|
@ -4,7 +4,14 @@ extends Task
|
|||
func run(blackboard: Dictionary) -> void:
|
||||
for c in self.get_children():
|
||||
run_child(blackboard, c)
|
||||
if c.status == SUCCESS_STOP:
|
||||
c.status = SUCCESS
|
||||
status = SUCCESS
|
||||
status_reason = "stopping at child " + c.name + ", as it returned SUCCESS_STOP"
|
||||
return
|
||||
if c.status != SUCCESS:
|
||||
status = c.status
|
||||
status_reason = "stopped at child " + c.name
|
||||
return
|
||||
status = SUCCESS
|
||||
status_reason = "all children succeeded"
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
class_name StepVisualization
|
||||
extends Node2D
|
||||
|
||||
static var game_manager: GameManager
|
||||
static var world: World
|
||||
#
|
||||
# Dictionary[Array[Vector2i], bool] ([from, to], string)
|
||||
static var draw_lines: Dictionary = {}
|
||||
|
||||
|
||||
static func add_line(from: Vector2i, to: Vector2i, label: String) -> void:
|
||||
draw_lines[[from, to]] = label
|
||||
|
||||
|
||||
static func add_line_tileset(from: Vector2i, to: Vector2i, label: String) -> void:
|
||||
var add_factor: Vector2i = world.tilemap_ground.tilemap.tile_set.tile_size
|
||||
add_factor.x /= 2
|
||||
add_factor.y /= 2
|
||||
|
||||
var from_tileset: Vector2i = world.tilemap_ground.cell_to_local(from)
|
||||
from_tileset.x += add_factor.x
|
||||
from_tileset.y += add_factor.y
|
||||
|
||||
var to_tileset: Vector2i = world.tilemap_ground.cell_to_local(to)
|
||||
to_tileset.x += add_factor.x
|
||||
to_tileset.y += add_factor.y
|
||||
|
||||
draw_lines[[from_tileset, to_tileset]] = label
|
||||
|
||||
|
||||
func game_tick_start():
|
||||
draw_lines.clear()
|
||||
|
||||
|
||||
func game_tick_end():
|
||||
queue_redraw()
|
||||
|
||||
var label_font = Control.new().get_theme_default_font()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
# draw all draw_lines with their labels
|
||||
for key in draw_lines.keys():
|
||||
var from: Vector2i = key[0]
|
||||
var to: Vector2i = key[1]
|
||||
var label: String = draw_lines[key]
|
||||
draw_line(from, to, Color("red"), 2)
|
||||
var center: Vector2 = (from + to) / 2
|
||||
draw_string(label_font, center, label)
|
|
@ -13,7 +13,7 @@ var chosen_path: Array[Vector2i] = []
|
|||
|
||||
|
||||
func game_tick_start() -> void:
|
||||
found_paths = {}
|
||||
found_paths.clear()
|
||||
failed_positions = []
|
||||
chosen_path = []
|
||||
|
||||
|
@ -37,7 +37,9 @@ func is_within_radius(position: Vector2i, center: Vector2i, radius: int) -> bool
|
|||
|
||||
|
||||
static func manhattan_distance(a: Vector2i, b: Vector2i) -> int:
|
||||
return abs(a.x - b.x) + abs(a.y - b.y)
|
||||
var dist: int = abs(a.x - b.x) + abs(a.y - b.y)
|
||||
# StepVisualization.add_line_tileset(a, b, str(dist))
|
||||
return dist
|
||||
|
||||
|
||||
func manhattan_distance_closest(options: Array[Vector2i], target: Vector2i) -> Vector2i:
|
||||
|
|
|
@ -9,8 +9,10 @@ var tilemap_interactive: TileMapLayerAccess = TileMapLayerAccess.new()
|
|||
var tilemap_player: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||
var tilemap_temperature: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||
var tilemap_nav_vis: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||
# other nodes
|
||||
# managers
|
||||
var camp_manager: CampManager = CampManager.new()
|
||||
# visualization
|
||||
@onready var step_visualizer: StepVisualization = $StepVisualization
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
Loading…
Reference in New Issue