mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2025-12-31 09:49:06 +03:00
Updated 2D pathfinding for version 3.1 (#301)
This commit is contained in:
committed by
Rémi Verschelde
parent
916c9c933c
commit
a6ce6dbf4c
@@ -5,39 +5,18 @@
|
||||
[ext_resource path="res://character.gd" type="Script" id=3]
|
||||
[ext_resource path="res://sprites/character.png" type="Texture" id=4]
|
||||
|
||||
[node name="Game" type="Node" index="0"]
|
||||
[node name="Game" type="Node"]
|
||||
|
||||
[node name="TileMap" type="TileMap" parent="." index="0"]
|
||||
|
||||
mode = 0
|
||||
[node name="TileMap" type="TileMap" parent="."]
|
||||
tile_set = ExtResource( 1 )
|
||||
cell_size = Vector2( 64, 64 )
|
||||
cell_quadrant_size = 16
|
||||
cell_custom_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||
cell_half_offset = 2
|
||||
cell_tile_origin = 0
|
||||
cell_y_sort = false
|
||||
cell_clip_uv = false
|
||||
collision_use_kinematic = false
|
||||
collision_friction = 1.0
|
||||
collision_bounce = 0.0
|
||||
collision_layer = 1
|
||||
collision_mask = 1
|
||||
occluder_light_mask = 1
|
||||
format = 1
|
||||
tile_data = PoolIntArray( 65537, 0, 0, 65541, 0, 0, 65545, 0, 0, 65550, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 196619, 0, 0, 262145, 0, 0, 262146, 0, 0, 262147, 0, 0, 327683, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 458761, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0 )
|
||||
script = ExtResource( 2 )
|
||||
_sections_unfolded = [ "Cell" ]
|
||||
map_size = Vector2( 16, 16 )
|
||||
|
||||
[node name="Character" type="Position2D" parent="." index="1"]
|
||||
|
||||
[node name="Character" type="Position2D" parent="."]
|
||||
script = ExtResource( 3 )
|
||||
SPEED = 200.0
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Character" index="0"]
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Character"]
|
||||
position = Vector2( 7, 0 )
|
||||
texture = ExtResource( 4 )
|
||||
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ var target_position = Vector2()
|
||||
var velocity = Vector2()
|
||||
|
||||
func _ready():
|
||||
_change_state(IDLE)
|
||||
_change_state(STATES.IDLE)
|
||||
|
||||
|
||||
func _change_state(new_state):
|
||||
if new_state == FOLLOW:
|
||||
path = get_parent().get_node('TileMap').get_path(position, target_position)
|
||||
if new_state == STATES.FOLLOW:
|
||||
path = get_parent().get_node('TileMap')._get_path(position, target_position)
|
||||
if not path or len(path) == 1:
|
||||
_change_state(IDLE)
|
||||
_change_state(STATES.IDLE)
|
||||
return
|
||||
# The index 0 is the starting cell
|
||||
# we don't want the character to move back to it in this example
|
||||
@@ -28,13 +28,13 @@ func _change_state(new_state):
|
||||
|
||||
|
||||
func _process(delta):
|
||||
if not _state == FOLLOW:
|
||||
if not _state == STATES.FOLLOW:
|
||||
return
|
||||
var arrived_to_next_point = move_to(target_point_world)
|
||||
if arrived_to_next_point:
|
||||
path.remove(0)
|
||||
if len(path) == 0:
|
||||
_change_state(IDLE)
|
||||
_change_state(STATES.IDLE)
|
||||
return
|
||||
target_point_world = path[0]
|
||||
|
||||
@@ -57,4 +57,4 @@ func _input(event):
|
||||
global_position = get_global_mouse_position()
|
||||
else:
|
||||
target_position = get_global_mouse_position()
|
||||
_change_state(FOLLOW)
|
||||
_change_state(STATES.FOLLOW)
|
||||
|
||||
@@ -2,100 +2,15 @@
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
radiance_size = 4
|
||||
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
|
||||
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
|
||||
sky_curve = 0.25
|
||||
sky_energy = 1.0
|
||||
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
|
||||
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
|
||||
ground_curve = 0.01
|
||||
ground_energy = 1.0
|
||||
sun_color = Color( 1, 1, 1, 1 )
|
||||
sun_latitude = 35.0
|
||||
sun_longitude = 0.0
|
||||
sun_angle_min = 1.0
|
||||
sun_angle_max = 100.0
|
||||
sun_curve = 0.05
|
||||
sun_energy = 16.0
|
||||
texture_size = 2
|
||||
|
||||
[resource]
|
||||
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
background_sky_custom_fov = 0.0
|
||||
background_color = Color( 0, 0, 0, 1 )
|
||||
background_energy = 1.0
|
||||
background_canvas_max_layer = 0
|
||||
ambient_light_color = Color( 0, 0, 0, 1 )
|
||||
ambient_light_energy = 1.0
|
||||
ambient_light_sky_contribution = 1.0
|
||||
fog_enabled = false
|
||||
fog_color = Color( 0.5, 0.6, 0.7, 1 )
|
||||
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
|
||||
fog_sun_amount = 0.0
|
||||
fog_depth_enabled = true
|
||||
fog_depth_begin = 10.0
|
||||
fog_depth_curve = 1.0
|
||||
fog_transmit_enabled = false
|
||||
fog_transmit_curve = 1.0
|
||||
fog_height_enabled = false
|
||||
fog_height_min = 0.0
|
||||
fog_height_max = 100.0
|
||||
fog_height_curve = 1.0
|
||||
tonemap_mode = 0
|
||||
tonemap_exposure = 1.0
|
||||
tonemap_white = 1.0
|
||||
auto_exposure_enabled = false
|
||||
auto_exposure_scale = 0.4
|
||||
auto_exposure_min_luma = 0.05
|
||||
auto_exposure_max_luma = 8.0
|
||||
auto_exposure_speed = 0.5
|
||||
ss_reflections_enabled = false
|
||||
ss_reflections_max_steps = 64
|
||||
ss_reflections_fade_in = 0.15
|
||||
ss_reflections_fade_out = 2.0
|
||||
ss_reflections_depth_tolerance = 0.2
|
||||
ss_reflections_roughness = true
|
||||
ssao_enabled = false
|
||||
ssao_radius = 1.0
|
||||
ssao_intensity = 1.0
|
||||
ssao_radius2 = 0.0
|
||||
ssao_intensity2 = 1.0
|
||||
ssao_bias = 0.01
|
||||
ssao_light_affect = 0.0
|
||||
ssao_color = Color( 0, 0, 0, 1 )
|
||||
ssao_quality = 0
|
||||
ssao_blur = 3
|
||||
ssao_edge_sharpness = 4.0
|
||||
dof_blur_far_enabled = false
|
||||
dof_blur_far_distance = 10.0
|
||||
dof_blur_far_transition = 5.0
|
||||
dof_blur_far_amount = 0.1
|
||||
dof_blur_far_quality = 1
|
||||
dof_blur_near_enabled = false
|
||||
dof_blur_near_distance = 2.0
|
||||
dof_blur_near_transition = 1.0
|
||||
dof_blur_near_amount = 0.1
|
||||
dof_blur_near_quality = 1
|
||||
glow_enabled = false
|
||||
glow_levels/1 = false
|
||||
glow_levels/2 = false
|
||||
glow_levels/3 = true
|
||||
glow_levels/4 = false
|
||||
glow_levels/5 = true
|
||||
glow_levels/6 = false
|
||||
glow_levels/7 = false
|
||||
glow_intensity = 0.8
|
||||
glow_strength = 1.0
|
||||
glow_bloom = 0.0
|
||||
glow_blend_mode = 2
|
||||
glow_hdr_threshold = 1.0
|
||||
glow_hdr_scale = 2.0
|
||||
glow_bicubic_upscale = false
|
||||
adjustment_enabled = false
|
||||
adjustment_brightness = 1.0
|
||||
adjustment_contrast = 1.0
|
||||
adjustment_saturation = 1.0
|
||||
|
||||
|
||||
@@ -7,16 +7,14 @@ path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
source_md5="0b0cb045ce690875fab066adeea76aba"
|
||||
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||
dest_md5="58323f97585db7bd8d6e03320f9ebb33"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
@@ -26,6 +24,7 @@ flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
|
||||
@@ -111,7 +111,7 @@ func calculate_point_index(point):
|
||||
return point.x + map_size.x * point.y
|
||||
|
||||
|
||||
func get_path(world_start, world_end):
|
||||
func _get_path(world_start, world_end):
|
||||
self.path_start_position = world_to_map(world_start)
|
||||
self.path_end_position = world_to_map(world_end)
|
||||
_recalculate_path()
|
||||
|
||||
@@ -6,7 +6,12 @@
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=3
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ ]
|
||||
_global_script_class_icons={
|
||||
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
@@ -16,8 +21,11 @@ config/icon="res://icon.png"
|
||||
|
||||
[input]
|
||||
|
||||
click=[ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
click={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
||||
@@ -7,16 +7,14 @@ path="res://.import/character.png-eb70ac48a5acf508c4b7740ea4ac4fae.stex"
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/character.png"
|
||||
source_md5="8746d76344ac3bad60c33b1bc43e11fd"
|
||||
|
||||
dest_files=[ "res://.import/character.png-eb70ac48a5acf508c4b7740ea4ac4fae.stex" ]
|
||||
dest_md5="e874204705e06ca4dc2c9b0a90db7e8a"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
@@ -26,6 +24,7 @@ flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
|
||||
@@ -7,16 +7,14 @@ path="res://.import/obstacle.png-0258c5f5ce65bfa0dd8610adeb784f54.stex"
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/obstacle.png"
|
||||
source_md5="f741dc1724960a029cba51c962d988be"
|
||||
|
||||
dest_files=[ "res://.import/obstacle.png-0258c5f5ce65bfa0dd8610adeb784f54.stex" ]
|
||||
dest_md5="432d869b849ac70d4f76935622b2e37b"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
@@ -26,6 +24,7 @@ flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
|
||||
@@ -7,16 +7,14 @@ path="res://.import/path_end.png-02b79e25892cd8d863bd44c3c5a1720e.stex"
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/path_end.png"
|
||||
source_md5="be9537ddfec33fdc35a33d88cad94d38"
|
||||
|
||||
dest_files=[ "res://.import/path_end.png-02b79e25892cd8d863bd44c3c5a1720e.stex" ]
|
||||
dest_md5="436b174ce46135e1d4d6b9b238889433"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
@@ -26,6 +24,7 @@ flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
|
||||
@@ -7,16 +7,14 @@ path="res://.import/path_start.png-475bd0b469629aa8779d506c5134e5c2.stex"
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/path_start.png"
|
||||
source_md5="6b4a1211e21f4fab937c7b309d802a44"
|
||||
|
||||
dest_files=[ "res://.import/path_start.png-475bd0b469629aa8779d506c5134e5c2.stex" ]
|
||||
dest_md5="5d90014ca7f70fa5f9494bd25fbe72d0"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
@@ -26,6 +24,7 @@ flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
|
||||
Reference in New Issue
Block a user