diff --git a/.godot/editor/3DWorld.tscn-editstate-5ee7dca069a2497be3bb28c4d56856bf.cfg b/.godot/editor/3DWorld.tscn-editstate-5ee7dca069a2497be3bb28c4d56856bf.cfg index 96d555a..1893fbc 100644 --- a/.godot/editor/3DWorld.tscn-editstate-5ee7dca069a2497be3bb28c4d56856bf.cfg +++ b/.godot/editor/3DWorld.tscn-editstate-5ee7dca069a2497be3bb28c4d56856bf.cfg @@ -97,7 +97,7 @@ Anim={ "auto_orthogonal_enabled": true, "cinematic_preview": false, "display_mode": 20, -"distance": 291.893, +"distance": 99.3776, "doppler": false, "frame_time": false, "gizmos": true, @@ -108,8 +108,8 @@ Anim={ "use_environment": false, "use_orthogonal": false, "view_type": 0, -"x_rotation": 0.566436, -"y_rotation": -10.7757 +"x_rotation": 1.00277, +"y_rotation": -10.5881 }, { "auto_orthogonal": false, "auto_orthogonal_enabled": true, diff --git a/.godot/editor/Instance.gd-folding-36fd78999554015d6181a024e5221f48.cfg b/.godot/editor/Instance.gd-folding-36fd78999554015d6181a024e5221f48.cfg new file mode 100644 index 0000000..e860dd4 --- /dev/null +++ b/.godot/editor/Instance.gd-folding-36fd78999554015d6181a024e5221f48.cfg @@ -0,0 +1,3 @@ +[folding] + +sections_unfolded=PackedStringArray() diff --git a/.godot/editor/Instance.tscn-editstate-9d991e3bcaa18250a5137d16090bc9f4.cfg b/.godot/editor/Instance.tscn-editstate-9d991e3bcaa18250a5137d16090bc9f4.cfg new file mode 100644 index 0000000..f631e28 --- /dev/null +++ b/.godot/editor/Instance.tscn-editstate-9d991e3bcaa18250a5137d16090bc9f4.cfg @@ -0,0 +1,170 @@ +[editor_states] + +Anim={ +"visible": false +} +2D={ +"grid_offset": Vector2(0, 0), +"grid_snap_active": false, +"grid_step": Vector2(8, 8), +"grid_visibility": 1, +"ofs": Vector2(-114.654, -46.1878), +"primary_grid_steps": 8, +"show_edit_locks": true, +"show_guides": true, +"show_helpers": false, +"show_origin": true, +"show_rulers": true, +"show_transformation_gizmos": true, +"show_viewport": true, +"show_zoom_control": true, +"smart_snap_active": false, +"snap_guides": true, +"snap_node_anchors": true, +"snap_node_center": true, +"snap_node_parent": true, +"snap_node_sides": true, +"snap_other_nodes": true, +"snap_pixel": true, +"snap_relative": false, +"snap_rotation": false, +"snap_rotation_offset": 0.0, +"snap_rotation_step": 0.261799, +"snap_scale": false, +"snap_scale_step": 0.1, +"zoom": 5.65685 +} +3D={ +"fov": 70.01, +"gizmos_status": { +"AudioListener3D": 0, +"AudioStreamPlayer3D": 0, +"CPUParticles3D": 0, +"CSGShape3D": 0, +"Camera3D": 0, +"CollisionObject3D": 0, +"CollisionPolygon3D": 0, +"CollisionShape3D": 0, +"Decal": 0, +"FogVolume": 0, +"GPUParticles3D": 0, +"GPUParticlesCollision3D": 0, +"Joint3D": 0, +"Light3D": 0, +"LightmapGI": 0, +"LightmapProbe": 0, +"Marker3D": 0, +"NavigationLink3D": 0, +"NavigationRegion3D": 0, +"OccluderInstance3D": 0, +"Path3D": 0, +"PhysicalBone3D": 0, +"RayCast3D": 0, +"ReflectionProbe": 0, +"ShapeCast3D": 0, +"Skeleton3D": 0, +"SoftBody3D": 0, +"SpringArm3D": 0, +"VehicleWheel3D": 0, +"VisibleOnScreenNotifier3D": 0, +"VoxelGI": 0 +}, +"local_coords": false, +"preview_sun_env": { +"environ_ao_enabled": false, +"environ_enabled": true, +"environ_energy": 1.0, +"environ_gi_enabled": false, +"environ_glow_enabled": true, +"environ_ground_color": Color(0.2, 0.169, 0.133, 1), +"environ_sky_color": Color(0.385, 0.454, 0.55, 1), +"environ_tonemap_enabled": true, +"sun_color": Color(1, 1, 1, 1), +"sun_enabled": true, +"sun_energy": 1.0, +"sun_max_distance": 100.0, +"sun_rotation": Vector2(-1.0472, 2.61799) +}, +"rotate_snap": 0.555556, +"scale_snap": 1.25, +"show_grid": true, +"show_origin": true, +"snap_enabled": false, +"translate_snap": 0.001, +"viewport_mode": 1, +"viewports": [{ +"auto_orthogonal": false, +"auto_orthogonal_enabled": true, +"cinematic_preview": false, +"display_mode": 20, +"distance": 4.0, +"doppler": false, +"frame_time": false, +"gizmos": true, +"half_res": false, +"information": false, +"listener": true, +"position": Vector3(0, 0, 0), +"use_environment": false, +"use_orthogonal": false, +"view_type": 0, +"x_rotation": 0.5, +"y_rotation": -0.5 +}, { +"auto_orthogonal": false, +"auto_orthogonal_enabled": true, +"cinematic_preview": false, +"display_mode": 20, +"distance": 4.0, +"doppler": false, +"frame_time": false, +"gizmos": true, +"half_res": false, +"information": false, +"listener": false, +"position": Vector3(0, 0, 0), +"use_environment": false, +"use_orthogonal": false, +"view_type": 0, +"x_rotation": 0.5, +"y_rotation": -0.5 +}, { +"auto_orthogonal": false, +"auto_orthogonal_enabled": true, +"cinematic_preview": false, +"display_mode": 20, +"distance": 4.0, +"doppler": false, +"frame_time": false, +"gizmos": true, +"half_res": false, +"information": false, +"listener": false, +"position": Vector3(0, 0, 0), +"use_environment": false, +"use_orthogonal": false, +"view_type": 0, +"x_rotation": 0.5, +"y_rotation": -0.5 +}, { +"auto_orthogonal": false, +"auto_orthogonal_enabled": true, +"cinematic_preview": false, +"display_mode": 20, +"distance": 4.0, +"doppler": false, +"frame_time": false, +"gizmos": true, +"half_res": false, +"information": false, +"listener": false, +"position": Vector3(0, 0, 0), +"use_environment": false, +"use_orthogonal": false, +"view_type": 0, +"x_rotation": 0.5, +"y_rotation": -0.5 +}], +"zfar": 4000.01, +"znear": 0.05 +} diff --git a/.godot/editor/Instance.tscn-folding-9d991e3bcaa18250a5137d16090bc9f4.cfg b/.godot/editor/Instance.tscn-folding-9d991e3bcaa18250a5137d16090bc9f4.cfg new file mode 100644 index 0000000..4cd0379 --- /dev/null +++ b/.godot/editor/Instance.tscn-folding-9d991e3bcaa18250a5137d16090bc9f4.cfg @@ -0,0 +1,5 @@ +[folding] + +node_unfolds=[NodePath("Pivot/MeshInstance3D"), PackedStringArray("Skeleton")] +resource_unfolds=["res://scenes/Instance.tscn::CapsuleMesh_qsbqh", PackedStringArray(), "res://scenes/Instance.tscn::CapsuleShape3D_ed37x", PackedStringArray()] +nodes_folded=[] diff --git a/.godot/editor/Instance3D.gd-folding-3eb269b94f06a762c7befac12d728193.cfg b/.godot/editor/Instance3D.gd-folding-3eb269b94f06a762c7befac12d728193.cfg new file mode 100644 index 0000000..e860dd4 --- /dev/null +++ b/.godot/editor/Instance3D.gd-folding-3eb269b94f06a762c7befac12d728193.cfg @@ -0,0 +1,3 @@ +[folding] + +sections_unfolded=PackedStringArray() diff --git a/.godot/editor/create_recent.Node b/.godot/editor/create_recent.Node index 8ec6d78..9a923f4 100644 --- a/.godot/editor/create_recent.Node +++ b/.godot/editor/create_recent.Node @@ -1,5 +1,6 @@ -MeshInstance3D CollisionShape3D +MeshInstance3D +Node3D CharacterBody3D TextureRect TileMap diff --git a/.godot/editor/editor_layout.cfg b/.godot/editor/editor_layout.cfg index d62e1ca..34dc132 100644 --- a/.godot/editor/editor_layout.cfg +++ b/.godot/editor/editor_layout.cfg @@ -16,11 +16,21 @@ dock_5="Inspector,Node,History" [EditorNode] -open_scenes=["res://scenes/WorldGeneration.tscn", "res://scenes/3DWorld.tscn"] +open_scenes=["res://scenes/WorldGeneration.tscn", "res://scenes/3DWorld.tscn", "res://scenes/Instance.tscn"] [ScriptEditor] -open_scripts=["res://scripts/Camera3D.gd", "res://scripts/Chunks.gd", "res://scripts/Entity.gd", "res://scripts/Map.gd", "res://scripts/World.gd", "res://scripts/WorldGeneration.gd"] +open_scripts=["res://scripts/Camera3D.gd", "res://scripts/Chunks.gd", "res://scripts/Entity.gd", "res://scripts/Global.gd", "res://scripts/Instance3D.gd", "res://scripts/Instance.gd", "res://scripts/Map.gd", "res://scripts/World.gd", "res://scripts/WorldGeneration.gd"] open_help=["Callable", "Object"] script_split_offset=70 list_split_offset=0 + +[editor_log] + +log_filter_0=true +log_filter_2=true +log_filter_1=true +log_filter_3=true +log_filter_4=true +collapse=false +show_search=true diff --git a/.godot/editor/filesystem_cache8 b/.godot/editor/filesystem_cache8 index f7c2f9a..8ae9fdf 100644 --- a/.godot/editor/filesystem_cache8 +++ b/.godot/editor/filesystem_cache8 @@ -1,10 +1,10 @@ 2a60927148abd1d33b818b535e306557 -::res://::1677510301 +::res://::1677532539 export_presets.cfg::TextFile::-1::1677194603::0::1::::<><>:: icon.png::CompressedTexture2D::4672001524465425285::1676578483::1676582905::1::::<><>:: README.md::TextFile::-1::1676578483::0::1::::<><>:: -::res://assets/::1677501393 -environment.tres::Environment::8600195688495287911::1677501393::0::1::::<><>:: +::res://assets/::1677530709 +environment.tres::Environment::8600195688495287911::1677530709::0::1::::<><>:: water.gdshader::Shader::-1::1677174532::0::1::::<><>:: ::res://assets/blocs/::1677174532 0_sides.glb::PackedScene::7036506600244808940::1677174532::1677174532::1::::<><>:: @@ -28,16 +28,19 @@ bloc_complet.glb::PackedScene::1436864023732800907::1677175567::1677177205::1::: bloc_complet_albedo.png::CompressedTexture2D::5276576783821208744::1677177183::1677177210::1::::<><>:: bloc_complet_normal.png::CompressedTexture2D::5644009833993754604::1677177183::1677177214::1::::<><>:: cube.meshlib::MeshLibrary::1045877065266806205::1677177509::0::1::::<><>::uid://chgapiyga3x6o<>uid://cmoaaucso40hs -::res://scenes/::1677501747 -3DWorld.tscn::PackedScene::3599411568061770725::1677501747::0::1::::<><>::uid://becm6iybpdly2<>res://scripts/Chunks.gd<>res://scripts/Camera3D.gd<>res://assets/water.gdshader<>uid://dur874iy77jjr +::res://scenes/::1677532532 +3DWorld.tscn::PackedScene::3599411568061770725::1677532532::0::1::::<><>::uid://becm6iybpdly2<>res://scripts/Chunks.gd<>uid://b1eubi13cfb4a<>res://scripts/Camera3D.gd<>res://assets/water.gdshader<>uid://dur874iy77jjr Game.tscn::PackedScene::9075056520838281688::1677174532::0::1::::<><>::uid://brjt1u0dgbmi4<>uid://d1sd7pxywgunu HUD.tscn::PackedScene::9021570906125339886::1677174532::0::1::::<><>::res://scripts/Map.gd -WorldGeneration.tscn::PackedScene::1108513713840477990::1677501747::0::1::::<><>::res://scripts/WorldGeneration.gd -::res://scripts/::1677501746 +Instance.tscn::PackedScene::4220804716574195494::1677532508::0::1::::<><>::res://scripts/Instance3D.gd +WorldGeneration.tscn::PackedScene::1108513713840477990::1677532508::0::1::::<><>::res://scripts/WorldGeneration.gd +::res://scripts/::1677532532 Camera3D.gd::GDScript::-1::1677174532::0::1::::<>Camera3D<>:: -Chunks.gd::GDScript::-1::1677501746::0::1::::<>GridMap<>:: -Entity.gd::GDScript::-1::1677501239::0::1::::Entity<>Node<>:: +Chunks.gd::GDScript::-1::1677530699::0::1::::<>GridMap<>:: +Entity.gd::GDScript::-1::1677530928::0::1::::Entity<>Node<>:: Global.gd::GDScript::-1::1677174532::0::1::::<>Node<>:: +Instance3D.gd::GDScript::-1::1677532532::0::1::::<>CharacterBody3D<>:: +Instance.gd::GDScript::-1::1677531382::0::1::::<>CharacterBody3D<>:: Map.gd::GDScript::-1::1677190875::0::1::::<>TextureRect<>:: -World.gd::GDScript::-1::1677501239::0::1::::World<>Node<>:: -WorldGeneration.gd::GDScript::-1::1677501614::0::1::::<>Control<>:: +World.gd::GDScript::-1::1677530828::0::1::::World<>Node<>:: +WorldGeneration.gd::GDScript::-1::1677530810::0::1::::<>Control<>:: diff --git a/.godot/editor/filesystem_update4 b/.godot/editor/filesystem_update4 index 6bdb391..8071074 100644 --- a/.godot/editor/filesystem_update4 +++ b/.godot/editor/filesystem_update4 @@ -1,5 +1,8 @@ -res://scenes/3DWorld.tscn +res://scenes/WorldGeneration.tscn res://assets/environment.tres +res://scenes/3DWorld.tscn +res://scenes/Instance.tscn +res://scripts/Instance3D.gd res://scripts/Chunks.gd -res://scenes/WorldGeneration.tscn +res://scripts/Entity.gd res://scripts/WorldGeneration.gd diff --git a/.godot/editor/project_metadata.cfg b/.godot/editor/project_metadata.cfg index 4f8c87d..dd94154 100644 --- a/.godot/editor/project_metadata.cfg +++ b/.godot/editor/project_metadata.cfg @@ -11,8 +11,8 @@ run_reload_scripts=true [recent_files] -scenes=["res://scenes/3DWorld.tscn", "res://scenes/WorldGeneration.tscn", "res://assets/test/bloc_complet.glb", "res://scenes/Character.tscn", "res://scenes/Map.tscn", "res://scenes/HUD.tscn", "res://scenes/Game.tscn", "res://scenes/world_generation.tscn", "res://MeshLib.tscn", "res://scenes/GridMap.tscn"] -scripts=["Object", "Callable", "res://scripts/Camera3D.gd", "res://scripts/Map.gd", "res://scripts/Entity.gd", "res://scripts/Bloc.gd", "res://scripts/Chunks.gd", "res://scripts/World.gd", "res://scripts/Character.gd", "res://scripts/WorldGeneration.gd"] +scenes=["res://scenes/Instance.tscn", "res://scenes/3DWorld.tscn", "res://scenes/WorldGeneration.tscn", "res://assets/test/bloc_complet.glb", "res://scenes/Character.tscn", "res://scenes/Map.tscn", "res://scenes/HUD.tscn", "res://scenes/Game.tscn", "res://scenes/world_generation.tscn", "res://MeshLib.tscn"] +scripts=["Object", "Callable", "res://scripts/Instance3D.gd", "res://scripts/Instance.gd", "res://scripts/Global.gd", "res://scripts/Camera3D.gd", "res://scripts/Map.gd", "res://scripts/Entity.gd", "res://scripts/Bloc.gd", "res://scripts/Chunks.gd"] [color_picker] @@ -20,7 +20,7 @@ recent_presets=PackedColorArray(1, 1, 1, 1, 0.72549, 0.74902, 0.0156863, 1, 0.74 [dialog_bounds] -project_settings=Rect2(830, 1124, 1531, 700) +project_settings=Rect2(599, 409, 1531, 671) search_help=Rect2(684, 912, 1368, 912) export=Rect2(468, 69, 1800, 1011) diff --git a/.godot/editor/recent_dirs b/.godot/editor/recent_dirs index b333705..31f6083 100644 --- a/.godot/editor/recent_dirs +++ b/.godot/editor/recent_dirs @@ -1,7 +1,7 @@ -/home/valentin/Documents/Gridmap/scripts res://scripts -res://assets/test res://scenes +/home/valentin/Documents/Gridmap/scripts +res://assets/test res:// res://assets /home/valentin/Documents/Gridmap diff --git a/.godot/editor/script_editor_cache.cfg b/.godot/editor/script_editor_cache.cfg index 07527f9..af28835 100644 --- a/.godot/editor/script_editor_cache.cfg +++ b/.godot/editor/script_editor_cache.cfg @@ -3,12 +3,16 @@ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 18, +"column": 1, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 12, +"row": 11, "scroll_position": 0.0, -"selection": false, +"selection": true, +"selection_from_column": 1, +"selection_from_line": 11, +"selection_to_column": 17, +"selection_to_line": 11, "syntax_highlighter": "GDScript" } @@ -17,16 +21,12 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 14, +"column": 1, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 62, -"scroll_position": 41.0, -"selection": true, -"selection_from_column": 14, -"selection_from_line": 62, -"selection_to_column": 38, -"selection_to_line": 62, +"row": 56, +"scroll_position": 38.0, +"selection": false, "syntax_highlighter": "GDScript" } @@ -35,11 +35,11 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 5, +"column": 0, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 123, -"scroll_position": 100.0, +"row": 80, +"scroll_position": 67.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -49,11 +49,11 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 0, +"column": 26, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 15, -"scroll_position": 0.0, +"row": 23, +"scroll_position": 3.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -63,10 +63,10 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 26, +"column": 13, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 12, +"row": 8, "scroll_position": 0.0, "selection": false, "syntax_highlighter": "GDScript" @@ -85,3 +85,53 @@ state={ "selection": false, "syntax_highlighter": "GDScript" } + +[res://scripts/Global.gd] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 17, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 2, +"scroll_position": 0.0, +"selection": true, +"selection_from_column": 5, +"selection_from_line": 2, +"selection_to_column": 17, +"selection_to_line": 2, +"syntax_highlighter": "GDScript" +} + +[res://scripts/Instance.gd] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 0, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 0, +"scroll_position": 0.0, +"selection": false, +"syntax_highlighter": "GDScript" +} + +[res://scripts/Instance3D.gd] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 0, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 6, +"scroll_position": 0.0, +"selection": true, +"selection_from_column": 0, +"selection_from_line": 6, +"selection_to_column": 27, +"selection_to_line": 9, +"syntax_highlighter": "GDScript" +} diff --git a/.godot/uid_cache.bin b/.godot/uid_cache.bin index 94e08f1..a5aa1a1 100644 Binary files a/.godot/uid_cache.bin and b/.godot/uid_cache.bin differ diff --git a/scenes/3DWorld.tscn b/scenes/3DWorld.tscn index ae6bdcd..7352f74 100644 --- a/scenes/3DWorld.tscn +++ b/scenes/3DWorld.tscn @@ -46,6 +46,9 @@ transform = Transform3D(0.999999, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0) mesh_library = ExtResource("1_cg1yu") cell_size = Vector3(1, 1, 1) cell_octant_size = 512 +cell_center_x = false +cell_center_y = false +cell_center_z = false data = { "cells": PackedInt32Array(1619, 64841, 0, 130877, 765, 0, 65483, 19, 0, 590646, 65155, 0) } @@ -62,6 +65,7 @@ environment = ExtResource("4_dycnn") [node name="Ocean" type="MeshInstance3D" parent="."] transform = Transform3D(0.999999, 0, 0, 0, 1, 0, 0, 0, 1, 256, 1, 256) +visible = false mesh = SubResource("PlaneMesh_7x62x") skeleton = NodePath("../Chunks") diff --git a/scenes/Instance.tscn b/scenes/Instance.tscn new file mode 100644 index 0000000..c2f62f3 --- /dev/null +++ b/scenes/Instance.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=3 uid="uid://b1eubi13cfb4a"] + +[ext_resource type="Script" path="res://scripts/Instance3D.gd" id="1_64ypb"] + +[sub_resource type="CapsuleMesh" id="CapsuleMesh_qsbqh"] + +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ed37x"] + +[node name="Instance3D" type="CharacterBody3D"] +script = ExtResource("1_64ypb") + +[node name="Pivot" type="Node3D" parent="."] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Pivot"] +mesh = SubResource("CapsuleMesh_qsbqh") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +shape = SubResource("CapsuleShape3D_ed37x") diff --git a/scripts/Chunks.gd b/scripts/Chunks.gd index 37f20c8..2e1d3e4 100644 --- a/scripts/Chunks.gd +++ b/scripts/Chunks.gd @@ -4,9 +4,11 @@ extends GridMap @onready var entities = [] +const Entity3D = preload("res://scenes/Instance.tscn") + func _ready(): setFloor() -# setGridChunk(0, ChunkWidth, 0, ChunkHeight) + setEntities() func setFloor(): for mz in range(0, Global.world.width - 1): @@ -67,59 +69,27 @@ func setFloor(): mesh_rotation = Global.GRID_ROTATION[0] set_cell_item( Vector3(mx, my, mz) , meshID, mesh_rotation) - if bloc.entity != -1: - var entity = Global.world.entities[bloc.entity] - var mesh_instance = MeshInstance3D.new() - mesh_instance.mesh = CapsuleMesh.new() - mesh_instance.translate(map_to_local(Vector3(bloc.x, bloc.y, bloc.z))) - entity.moving.connect(_on_entity_moving) - entities.append(mesh_instance) - add_child(entities[entities.size()-1]) - Global.world.entities[bloc.entity].move(0) - - - -# -#func setEntities(columnStart: float, columnEnd: float, rowStart: float, rowEnd: float) -> void: -# if columnStart < 0 : -# columnStart = 0 -# if rowStart < 0 : -# rowStart = 0 -# if columnEnd > Global.world.width - 1 : -# columnEnd =Global.world.width - 2 -# if rowEnd > Global.world.height - 1 : -# rowEnd = Global.world.height - 2 -# -## var multimesh = MultiMesh.new() -# -## multimesh.transform_format = MultiMesh.TRANSFORM_3D -# var instances = [] -# for mz in range(rowStart, rowEnd): -# for mx in range(columnStart, columnEnd): -# var bloc = Global.world.get_bloc(Vector2(mx, mz)) -# if bloc.entity != -1: -# instances.append(map_to_local(Vector3(bloc.x, bloc.y, bloc.z))) -# -# -# multimesh.instance_count = instances.size() -# for instance_index in multimesh.instance_count: -# var transform := Transform3D() -# transform.origin = instances[instance_index] -# -# multimesh.set_instance_transform(instance_index, transform) -# -# if instances.size(): -# var multimesh_instance = MultiMeshInstance3D.new() -# multimesh_instance.multimesh = multimesh -# multimeshInstances.append(multimesh_instance) -# add_child(multimeshInstances[multimeshInstances.size()-1]) -# -#func _on_map_update_timer_timeout(): -# pass -## generateGridChunk(camera.global_transform.origin) - +func setEntities(): + for entity in Global.world.entities: + var entity_instance = Entity3D.instantiate() + entity_instance.id = entities.size() + 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) -func _on_entity_moving(): - pass -# print("bonsoir") +# TEST À ENLEVER +var inputs = {"ui_right": Vector2.RIGHT, + "ui_left": Vector2.LEFT, + "ui_up": Vector2.UP, + "ui_down": Vector2.DOWN} + +func _unhandled_input(event): + for dir in inputs.keys(): + if event.is_action_pressed(dir): + var new_position = Global.world.entities[23].position2D + inputs[dir] +# var new_position3d = map_to_local(Vector3(new_position.x, 0, new_position.y)) +# var new_position2d = Vector2(new_position3d.x, new_position3d.z) + Global.world.entities[23].move(new_position) +# FIN TEST À ENLEVER diff --git a/scripts/Entity.gd b/scripts/Entity.gd index 3b73452..dc9b92f 100644 --- a/scripts/Entity.gd +++ b/scripts/Entity.gd @@ -2,14 +2,27 @@ extends Node class_name Entity -var position: Vector2 +var position: Vector3 +var position2D: Vector2 var movement: int = -1 var movement_step: float = 0.0 +var id = -1 signal moving -func _init(position: Vector2): - self.position = position +func _init(id: int, position: Vector2): + self.id = id + self.position.x = position.x + self.position.y = Global.world.get_height(Vector2(position.x, position.y)) + self.position.z = position.y + position2D = position -func move(direction: int): - emit_signal("moving") +func move(new_position: Vector2): + self.position.x = new_position.x + self.position.y = Global.world.get_height(Vector2(new_position.x, new_position.y)) + self.position.z = new_position.y + position2D = new_position + Global.world.blocs[position.x][position.y].entity = -1 + Global.world.blocs[new_position.x][new_position.y].entity = id + emit_signal("moving", self.position) + diff --git a/scripts/Instance.gd b/scripts/Instance.gd new file mode 100644 index 0000000..06a4c08 --- /dev/null +++ b/scripts/Instance.gd @@ -0,0 +1,31 @@ +extends CharacterBody3D + + +const SPEED = 5.0 +const JUMP_VELOCITY = 4.5 + +# Get the gravity from the project settings to be synced with RigidBody nodes. +var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") + + +func _physics_process(delta): + # Add the gravity. + if not is_on_floor(): + velocity.y -= gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") + var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + if direction: + velocity.x = direction.x * SPEED + velocity.z = direction.z * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + velocity.z = move_toward(velocity.z, 0, SPEED) + + move_and_slide() diff --git a/scripts/Instance3D.gd b/scripts/Instance3D.gd new file mode 100644 index 0000000..b91a1c3 --- /dev/null +++ b/scripts/Instance3D.gd @@ -0,0 +1,30 @@ +extends CharacterBody3D + + +const SPEED = 10.0 +var id = -1 + +var inputs = {"ui_right": Vector3.RIGHT, + "ui_left": Vector3.LEFT, + "ui_up": Vector3.FORWARD, + "ui_down": Vector3.BACK} + +func connect_to_world(id): + var world_entity = Global.world.entities[id] + world_entity.moving.connect(_on_entity_moving) + pass +# +#func _unhandled_input(event): +# for dir in inputs.keys(): +# if event.is_action_pressed(dir): +# var new_position = position + inputs[dir] +# move(new_position) +# +#func move(new_position): +# var tween = get_tree().create_tween() +# tween.tween_property(self, "position", new_position, 1/SPEED).set_trans(Tween.TRANS_SINE) + +func _on_entity_moving(new_position): + var tween = get_tree().create_tween() + tween.tween_property(self, "position", new_position, 1/SPEED).set_trans(Tween.TRANS_SINE) + pass diff --git a/scripts/World.gd b/scripts/World.gd index 73569a4..47fae43 100644 --- a/scripts/World.gd +++ b/scripts/World.gd @@ -59,7 +59,10 @@ func get_bloc(point: Vector2): return bloc +func get_height(point: Vector2): + return heightMap[point.x][point.y] + func add_entity(position: Vector2): - entities.append(Entity.new(position)) + entities.append(Entity.new(entities.size(), position)) blocs[position.x][position.y]["entity"] = entities.size() - 1 pass diff --git a/scripts/WorldGeneration.gd b/scripts/WorldGeneration.gd index 0baef5a..fdd9779 100644 --- a/scripts/WorldGeneration.gd +++ b/scripts/WorldGeneration.gd @@ -9,9 +9,12 @@ func _ready(): 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(Vector2(x, y)) + # FIN TEST À ENLEVER + get_tree().change_scene_to_file("scenes/Game.tscn")