debug pathfinding + instance3d

pull/19/head
Valentin Stark 3 years ago
parent c84dc9c682
commit 74a75b6193
  1. 26
      .godot/editor/filesystem_cache8
  2. 4
      .godot/editor/filesystem_update4
  3. 36
      .godot/editor/script_editor_cache.cfg
  4. 5
      scripts/Chunks.gd
  5. 25
      scripts/Entity.gd
  6. 6
      scripts/Instance3D.gd
  7. 11
      scripts/Selection.gd
  8. 2
      scripts/World.gd
  9. 9
      scripts/WorldGeneration.gd

@ -1,12 +1,12 @@
2a60927148abd1d33b818b535e306557
::res://::1678475097
::res://::1678647327
export_presets.cfg::TextFile::-1::1677194603::0::1::::<><>::
icon.png::CompressedTexture2D::4672001524465425285::1676578483::1676582905::1::::<><>::
README.md::TextFile::-1::1676578483::0::1::::<><>::
::res://assets/::1678217906
environment.tres::Environment::8600195688495287911::1678217906::0::1::::<><>::
::res://assets/::1678647181
environment.tres::Environment::8600195688495287911::1678647181::0::1::::<><>::
water.gdshader::Shader::-1::1677174532::0::1::::<><>::
::res://assets/blocs/::1678233640
::res://assets/blocs/::1678647181
0_sides.glb::PackedScene::7036506600244808940::1677174532::1677174532::1::::<><>::
0_sides_grass.png::CompressedTexture2D::4551055068461159203::1677174532::1677174532::1::::<><>::
1_side.glb::PackedScene::5601417408597394875::1677174532::1677617210::1::::<><>::
@ -20,7 +20,7 @@ water.gdshader::Shader::-1::1677174532::0::1::::<><>::
4_sides.glb::PackedScene::139420628202576697::1677174532::1677174532::1::::<><>::
4_sides_grass.png::CompressedTexture2D::7961782411803042998::1677174532::1677174532::1::::<><>::
blocs.meshlib::MeshLibrary::3161916306234183153::1677617602::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u
blocs.tscn::PackedScene::3779811605783367088::1678233640::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u
blocs.tscn::PackedScene::3779811605783367088::1678647181::0::1::::<><>::uid://b53thhe2sa6x0<>uid://cfr1s2lqng8eo<>uid://c0xxcgdm7s2ak<>uid://bffdt5if5pnda<>uid://kc4nqve8lx14<>uid://dlo0nmochxy4u
::res://assets/images/::1677174532
colors.png::CompressedTexture2D::2558953172502239658::1677174532::1677174532::1::::<><>::
grass_top.png::CompressedTexture2D::3263707750932711970::1677174532::1677174532::1::::<><>::
@ -55,19 +55,19 @@ sdqs.meshlib::MeshLibrary::2440886030015449773::1677616939::0::1::::<><>::uid://
blocs.meshlib::MeshLibrary::5001218139483850589::1677702801::0::1::::<><>::uid://ffn1ia7c3x60<>uid://birlu82nfgbsx<>uid://t03cipsdfuim<>uid://68inkwq5fe2v<>uid://blv0o0tit1gob<>uid://dg3l2dsc7n6s<>uid://dpewuerjdlgms<>uid://d3a4ur67k13wa<>uid://d1ioc5uj71iud<>uid://2s6bm46h6kfw<>uid://bttpxki4m82q1<>uid://bh7awq00jlfkn
::res://assets/ui/::1677619095
bloc_select.png::CompressedTexture2D::1141775147858261351::1677618805::1677619095::1::::<><>::
::res://scenes/::1678233640
3DWorld.tscn::PackedScene::3599411568061770725::1678233640::0::1::::<><>::uid://blbwkgls3oafx<>res://scripts/Chunks.gd<>res://scripts/Camera3D.gd<>res://assets/water.gdshader<>uid://dur874iy77jjr<>uid://qjc4ttmkxbch<>res://scripts/Selection.gd
::res://scenes/::1678647319
3DWorld.tscn::PackedScene::3599411568061770725::1678647181::0::1::::<><>::uid://blbwkgls3oafx<>res://scripts/Chunks.gd<>res://scripts/Camera3D.gd<>res://assets/water.gdshader<>uid://dur874iy77jjr<>uid://qjc4ttmkxbch<>res://scripts/Selection.gd
Game.tscn::PackedScene::9075056520838281688::1677174532::0::1::::<><>::uid://brjt1u0dgbmi4<>uid://d1sd7pxywgunu
HUD.tscn::PackedScene::9021570906125339886::1678233640::0::1::::<><>::res://scripts/Map.gd
Instance.tscn::PackedScene::4220804716574195494::1678233640::0::1::::<><>::res://scripts/Instance3D.gd
WorldGeneration.tscn::PackedScene::1108513713840477990::1678233639::0::1::::<><>::res://scripts/WorldGeneration.gd
::res://scripts/::1678233622
HUD.tscn::PackedScene::9021570906125339886::1678647319::0::1::::<><>::res://scripts/Map.gd
Instance.tscn::PackedScene::4220804716574195494::1678647181::0::1::::<><>::res://scripts/Instance3D.gd
WorldGeneration.tscn::PackedScene::1108513713840477990::1678647181::0::1::::<><>::res://scripts/WorldGeneration.gd
::res://scripts/::1678647319
Camera3D.gd::GDScript::-1::1677174532::0::1::::<>Camera3D<>::
Chunks.gd::GDScript::-1::1678219623::0::1::::<>GridMap<>::
Entity.gd::GDScript::-1::1678233622::0::1::::Entity<>Node<>::
Entity.gd::GDScript::-1::1678647319::0::1::::Entity<>Node<>::
Global.gd::GDScript::-1::1677174532::0::1::::<>Node<>::
Instance3D.gd::GDScript::-1::1677873181::0::1::::<>CharacterBody3D<>::
Map.gd::GDScript::-1::1678219623::0::1::::<>TextureRect<>::
Selection.gd::GDScript::-1::1678222510::0::1::::<>Node3D<>::
World.gd::GDScript::-1::1678232290::0::1::::World<>Node<>::
World.gd::GDScript::-1::1678476426::0::1::::World<>Node<>::
WorldGeneration.gd::GDScript::-1::1678232290::0::1::::<>Control<>::

@ -5,4 +5,8 @@ res://scenes/Instance.tscn
res://assets/blocs/blocs.tscn
res://scenes/HUD.tscn
res://scripts/Entity.gd
res://scripts/Instance3D.gd
res://scripts/Selection.gd
res://scripts/World.gd
res://scripts/Chunks.gd
res://scripts/WorldGeneration.gd

@ -3,11 +3,11 @@
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 21,
"column": 96,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 15,
"scroll_position": 32.0,
"row": 9,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
@ -20,7 +20,7 @@ state={
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 90,
"row": 79,
"scroll_position": 65.0,
"selection": false,
"syntax_highlighter": "GDScript"
@ -31,12 +31,16 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 28,
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 78,
"scroll_position": 54.0,
"selection": false,
"row": 2,
"scroll_position": 0.0,
"selection": true,
"selection_from_column": 0,
"selection_from_line": 2,
"selection_to_column": 54,
"selection_to_line": 2,
"syntax_highlighter": "GDScript"
}
@ -45,11 +49,11 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 2,
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 82,
"scroll_position": 63.0,
"row": 27,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
@ -101,10 +105,10 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 17,
"column": 57,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 3,
"row": 11,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"
@ -115,11 +119,11 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 3,
"column": 55,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 22,
"scroll_position": 0.0,
"row": 28,
"scroll_position": 12.0,
"selection": false,
"syntax_highlighter": "GDScript"
}

@ -1,7 +1,5 @@
extends GridMap
@onready var entities = []
const Entity3D = preload("res://scenes/Instance.tscn")
func _ready():
@ -72,8 +70,7 @@ func setFloor():
func setEntities():
for entity in Global.world.entities:
var entity_instance = Entity3D.instantiate()
entity_instance.id = entities.size()
entity_instance.id = entity.id
entity_instance.position = map_to_local(Vector3(entity.position.x, entity.position.y, entity.position.z))
entity_instance.connect_to_world(entity_instance.id)
entities.append(entity_instance)
add_child(entity_instance)

@ -4,10 +4,11 @@ class_name Entity
var position: Vector3
var position2D: Vector2i
var movement: int = -1
var movement_step: float = 0.0
var speed = 3.0 # blocs per second
var id = -1
var moving_counter = 0
signal moving
func _init(id: int, position: Vector2i):
@ -26,28 +27,30 @@ func get_data():
return data
func move(new_position: Vector2i):
var new_position_3d = Vector3(new_position.x, Global.world.get_height(Vector2i(new_position.x, new_position.y)), new_position.y)
emit_signal("moving", new_position_3d, speed)
Global.world.blocs[position.x][position.y].entity = -1
self.position.x = new_position.x
self.position.y = Global.world.get_height(Vector2i(new_position.x, new_position.y))
self.position.z = new_position.y
self.position = new_position_3d
position2D = new_position
Global.world.blocs[new_position.x][new_position.y].entity = id
emit_signal("moving", self.position)
### Mettre un speed
func follow_path(path: Array):
moving_counter += 1
var current_moving_counter = moving_counter
for next in path:
if moving_counter != current_moving_counter:
return
move(next)
var t = Timer.new()
t.wait_time = 0.3
t.wait_time = 1.0 / speed
t.set_one_shot(true)
t.autostart = true
Engine.get_main_loop().get_root().add_child(t)
await t.timeout
move(next)
t.queue_free()
func heuristic(a: Vector2i, b: Vector2i) -> float:
return abs(a.x - b.x) + abs(a.y - b.y)

@ -1,7 +1,5 @@
extends CharacterBody3D
const SPEED = 3.0
var id = -1
func connect_to_world(id):
@ -9,7 +7,7 @@ func connect_to_world(id):
world_entity.moving.connect(_on_entity_moving)
pass
func _on_entity_moving(new_position):
func _on_entity_moving(new_position, speed):
var tween = get_tree().create_tween()
tween.tween_property(self, "position", new_position, 1/SPEED)
tween.tween_property(self, "position", new_position, 1.0/speed)
pass

@ -1,5 +1,10 @@
extends Node3D
const Entity3D = preload("res://scenes/Instance.tscn")
@onready var grid = $Grid
@onready var camera =$Camera3D
@onready var highlighter = $Highlighter
@ -17,6 +22,12 @@ func _process(delta):
selection = highlight
else:
selection = reset_highlight()
var entity = Global.world.add_entity(Vector2i(highlight.data.position.x, highlight.data.position.z))
var entity_instance = Entity3D.instantiate()
entity_instance.id = entity.id
entity_instance.position = highlight.data.position
entity_instance.connect_to_world(entity_instance.id)
add_child(entity_instance)
if Input.is_action_just_pressed("main_command"):
if selection.type == 1:
var path = Global.world.entities[selection.data.id].pathfinding(Vector2i(highlight.data.position.x, highlight.data.position.z))

@ -76,7 +76,7 @@ func get_height(point: Vector2i):
func add_entity(position: Vector2i):
entities.append(Entity.new(entities.size(), position))
blocs[position.x][position.y]["entity"] = entities.size() - 1
pass
return entities[entities.size() - 1]
func cost(point1: Vector2i, point2: Vector2i):
var cost = 1

@ -7,14 +7,7 @@ func _ready():
Global.world.width = world_width
Global.world.height = world_height
Global.world.heightMap = generate_heightmap(Global.world.width, Global.world.height)
Global.world.blocs = set_blocs(Global.world.width, Global.world.height, Global.world.heightMap)
# TEST À ENLEVER
for x in range(0, 8):
for y in range(0, 8):
Global.world.add_entity(Vector2i(x, y))
# FIN TEST À ENLEVER
Global.world.blocs = set_blocs(Global.world.width, Global.world.height, Global.world.heightMap)
get_tree().change_scene_to_file("scenes/Game.tscn")

Loading…
Cancel
Save