Basic terrain creation

This commit is contained in:
leca 2024-05-30 06:55:13 +03:00
parent 460f561062
commit c632bfe7e0
10 changed files with 225 additions and 13 deletions

View File

@ -15,6 +15,10 @@ run/main_scene="res://scenes/world.tscn"
config/features=PackedStringArray("4.2", "Forward Plus") config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
Definitions="*res://scripts/definitions.gd"
[input] [input]
MWU={ MWU={
@ -62,3 +66,8 @@ run={
"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":4194325,"key_label":0,"unicode":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":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
] ]
} }
LMC={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}

View File

@ -4,8 +4,13 @@
[ext_resource type="PackedScene" uid="uid://bs7ctvbx7xov5" path="res://scenes/ui.tscn" id="2_06brk"] [ext_resource type="PackedScene" uid="uid://bs7ctvbx7xov5" path="res://scenes/ui.tscn" id="2_06brk"]
[node name="God" type="Node3D"] [node name="God" type="Node3D"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0)
script = ExtResource("1_hfa56") script = ExtResource("1_hfa56")
[node name="Camera" type="Camera3D" parent="."] [node name="Camera" type="Camera3D" parent="."]
[node name="eye" type="RayCast3D" parent="Camera"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
target_position = Vector3(50, 0, 0)
[node name="UI" parent="." instance=ExtResource("2_06brk")] [node name="UI" parent="." instance=ExtResource("2_06brk")]

View File

@ -1,19 +1,69 @@
[gd_scene load_steps=4 format=3 uid="uid://dj0odn77jplje"] [gd_scene load_steps=9 format=3 uid="uid://dj0odn77jplje"]
[ext_resource type="Script" path="res://scripts/Tile.gd" id="1_s01tx"] [ext_resource type="Script" path="res://scripts/Tile.gd" id="1_s01tx"]
[ext_resource type="Texture2D" uid="uid://d1k366i5jjtrk" path="res://textures/plus.svg" id="2_cddgt"]
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_qnc60"]
data = PackedVector3Array(-5, 2.5, 5, 5, 2.5, 5, -5, -2.5, 5, 5, 2.5, 5, 5, -2.5, 5, -5, -2.5, 5, 5, 2.5, -5, -5, 2.5, -5, 5, -2.5, -5, -5, 2.5, -5, -5, -2.5, -5, 5, -2.5, -5, 5, 2.5, 5, 5, 2.5, -5, 5, -2.5, 5, 5, 2.5, -5, 5, -2.5, -5, 5, -2.5, 5, -5, 2.5, -5, -5, 2.5, 5, -5, -2.5, -5, -5, 2.5, 5, -5, -2.5, 5, -5, -2.5, -5, 5, 2.5, 5, -5, 2.5, 5, 5, 2.5, -5, -5, 2.5, 5, -5, 2.5, -5, 5, 2.5, -5, -5, -2.5, 5, 5, -2.5, 5, -5, -2.5, -5, 5, -2.5, 5, 5, -2.5, -5, -5, -2.5, -5)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_f1ys8"]
transparency = 1
albedo_color = Color(1, 1, 1, 0)
[sub_resource type="BoxMesh" id="BoxMesh_3vjuu"] [sub_resource type="BoxMesh" id="BoxMesh_3vjuu"]
material = SubResource("StandardMaterial3D_f1ys8")
size = Vector3(10, 5, 10) size = Vector3(10, 5, 10)
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_scykg"] [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_scykg"]
data = PackedVector3Array(-5, 2.5, 5, 5, 2.5, 5, -5, -2.5, 5, 5, 2.5, 5, 5, -2.5, 5, -5, -2.5, 5, 5, 2.5, -5, -5, 2.5, -5, 5, -2.5, -5, -5, 2.5, -5, -5, -2.5, -5, 5, -2.5, -5, 5, 2.5, 5, 5, 2.5, -5, 5, -2.5, 5, 5, 2.5, -5, 5, -2.5, -5, 5, -2.5, 5, -5, 2.5, -5, -5, 2.5, 5, -5, -2.5, -5, -5, 2.5, 5, -5, -2.5, 5, -5, -2.5, -5, 5, 2.5, 5, -5, 2.5, 5, 5, 2.5, -5, -5, 2.5, 5, -5, 2.5, -5, 5, 2.5, -5, -5, -2.5, 5, 5, -2.5, 5, -5, -2.5, -5, 5, -2.5, 5, 5, -2.5, -5, -5, -2.5, -5) data = PackedVector3Array(-5, 2.5, 5, 5, 2.5, 5, -5, -2.5, 5, 5, 2.5, 5, 5, -2.5, 5, -5, -2.5, 5, 5, 2.5, -5, -5, 2.5, -5, 5, -2.5, -5, -5, 2.5, -5, -5, -2.5, -5, 5, -2.5, -5, 5, 2.5, 5, 5, 2.5, -5, 5, -2.5, 5, 5, 2.5, -5, 5, -2.5, -5, 5, -2.5, 5, -5, 2.5, -5, -5, 2.5, 5, -5, -2.5, -5, -5, 2.5, 5, -5, -2.5, 5, -5, -2.5, -5, 5, 2.5, 5, -5, 2.5, 5, 5, 2.5, -5, -5, 2.5, 5, -5, 2.5, -5, 5, 2.5, -5, -5, -2.5, 5, 5, -2.5, 5, -5, -2.5, -5, 5, -2.5, 5, 5, -2.5, -5, -5, -2.5, -5)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0knec"]
albedo_color = Color(0.203922, 0.458824, 0.113725, 1)
[sub_resource type="BoxMesh" id="BoxMesh_doul4"]
material = SubResource("StandardMaterial3D_0knec")
size = Vector3(10, 5, 10)
[node name="Tile" type="StaticBody3D"] [node name="Tile" type="StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0)
script = ExtResource("1_s01tx") script = ExtResource("1_s01tx")
[node name="VisibleMesh" type="MeshInstance3D" parent="."] [node name="Empty_tile" type="CollisionShape3D" parent="."]
mesh = SubResource("BoxMesh_3vjuu") shape = SubResource("ConcavePolygonShape3D_qnc60")
[node name="CollisionMesh" type="CollisionShape3D" parent="."] [node name="VisibleMesh" type="MeshInstance3D" parent="Empty_tile"]
mesh = SubResource("BoxMesh_3vjuu")
skeleton = NodePath("../..")
[node name="plus_sprite" type="Sprite3D" parent="Empty_tile"]
transform = Transform3D(2, 0, 0, 0, -8.74228e-08, -2, 0, 2, -8.74228e-08, 0, 2.501, 0)
texture = ExtResource("2_cddgt")
[node name="Plain_tile" type="CollisionShape3D" parent="."]
visible = false
shape = SubResource("ConcavePolygonShape3D_scykg") shape = SubResource("ConcavePolygonShape3D_scykg")
[node name="VisibleMesh" type="MeshInstance3D" parent="Plain_tile"]
mesh = SubResource("BoxMesh_doul4")
skeleton = NodePath("../..")
[node name="Forest_tile" type="CollisionShape3D" parent="."]
visible = false
shape = SubResource("ConcavePolygonShape3D_scykg")
[node name="VisibleMesh" type="MeshInstance3D" parent="Forest_tile"]
mesh = SubResource("BoxMesh_doul4")
skeleton = NodePath("../..")
[node name="ray_north" type="RayCast3D" parent="."]
target_position = Vector3(10, 0, 0)
[node name="ray_south" type="RayCast3D" parent="."]
target_position = Vector3(-10, 0, 0)
[node name="ray_west" type="RayCast3D" parent="."]
target_position = Vector3(0, 0, -10)
[node name="ray_east" type="RayCast3D" parent="."]
target_position = Vector3(0, 0, 10)
collide_with_areas = true

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://dh52xle0rfx5r"] [gd_scene load_steps=6 format=3 uid="uid://dh52xle0rfx5r"]
[ext_resource type="PackedScene" uid="uid://b6er1dx11vq1a" path="res://scenes/models/god.tscn" id="1_vj3b2"] [ext_resource type="PackedScene" uid="uid://b6er1dx11vq1a" path="res://scenes/models/god.tscn" id="1_vj3b2"]
[ext_resource type="PackedScene" uid="uid://dj0odn77jplje" path="res://scenes/models/tile.tscn" id="2_1y5so"] [ext_resource type="Script" path="res://scripts/Earth.gd" id="2_oiur1"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_xk8d1"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_xk8d1"]
@ -26,7 +26,4 @@ transform = Transform3D(-0.0647024, -0.76, 0.646694, -0.0118927, 0.648593, 0.761
shadow_enabled = true shadow_enabled = true
[node name="Earth" type="Node3D" parent="."] [node name="Earth" type="Node3D" parent="."]
script = ExtResource("2_oiur1")
[node name="Tile" parent="Earth" instance=ExtResource("2_1y5so")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 11.3537, -2.5, 0)
constant_linear_velocity = Vector3(10, 0, 0)

38
scripts/Earth.gd Normal file
View File

@ -0,0 +1,38 @@
extends Node3D
enum TileType {
Empty,
Plain,
Forest
}
var tile_exemplar = preload("res://scenes/models/tile.tscn");
func _ready():
var start_tile = tile_exemplar.instantiate()
add_child(start_tile);
func _physics_process(delta):
pass
func mark_free_tiles():
var tiles = get_children()
for tile in tiles:
if tile.tile_type == TileType.Empty: continue
var free_dirs = tile.get_free_dirs_around();
for dir in free_dirs:
var free_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty
add_child(free_tile)
var pos: Vector3 = tile.position
match dir:
"north":
pos.x += 10
"south":
pos.x -= 10
"west":
pos.z -= 10
"east":
pos.z += 10
free_tile.position = pos;
free_tile.update_tile()

View File

@ -6,6 +6,8 @@ var walk = 0.25
@onready var camera = $"./Camera" @onready var camera = $"./Camera"
@onready var ui = $"./UI" @onready var ui = $"./UI"
@onready var velocity_label: Label = ui.find_child("velocity_label") @onready var velocity_label: Label = ui.find_child("velocity_label")
@onready var eye_raycast: RayCast3D = $"./Camera/eye"
@onready var earth = $"../Earth"
func _ready(): func _ready():
camera.make_current() camera.make_current()
@ -34,6 +36,13 @@ func _physics_process(delta):
var velocity = Vector3.ZERO var velocity = Vector3.ZERO
var speed var speed
if Input.is_action_just_pressed("LMC") and eye_raycast.is_colliding():
var target = eye_raycast.get_collider()
if "TileType" in target and target.tile_type == 0:
target.tile_type = 2
target.update_tile()
earth.mark_free_tiles()
if Input.is_action_pressed("run"): if Input.is_action_pressed("run"):
speed = walk * 2 speed = walk * 2
else: else:

View File

@ -1,11 +1,34 @@
extends StaticBody3D extends StaticBody3D
enum TileType {
Empty,
Plain,
Forest
}
@export var tile_type: TileType = TileType.Empty;
func update_tile():
var children = find_children("*tile");
for child in children:
if TileType.keys()[tile_type] == child.name.split("_")[0]:
child.visible = true;
else:
child.visible = false;
# Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. update_tile()
func get_free_dirs_around():
# Called every frame. 'delta' is the elapsed time since the previous frame. var free_tiles_around = []
if tile_type == TileType.Empty: return free_tiles_around
var raycasts = find_children("ray*");
for raycast: RayCast3D in raycasts:
raycast.force_raycast_update()
if !raycast.is_colliding():
free_tiles_around.append(raycast.name.split("_")[1])
return free_tiles_around
func _process(delta): func _process(delta):
pass pass

7
scripts/definitions.gd Normal file
View File

@ -0,0 +1,7 @@
extends Node
class_name defs
enum TileType {
Empty,
Plain,
Forest
}

36
textures/plus.svg Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="130.58292mm"
height="130.58162mm"
viewBox="0 0 130.58292 130.58162"
version="1.1"
id="svg1"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-45.075196,-68.909269)">
<path
d="m 97.926916,68.909267 c -4.08902,0 -7.38191,5.421994 -7.38191,12.156633 v 33.31318 H 57.231834 c -6.734662,0 -12.156638,3.2916 -12.156638,7.38062 v 24.88073 c 0,4.08905 5.421976,7.38065 12.156638,7.38065 h 33.313172 v 33.31316 c 0,6.73468 3.292865,12.15665 7.38191,12.15665 h 24.879444 c 4.08904,0 7.38191,-5.42197 7.38191,-12.15665 v -33.31316 h 33.31318 c 6.73469,0 12.15666,-3.2916 12.15666,-7.38065 V 121.7597 c 0,-4.08904 -5.42197,-7.38062 -12.15666,-7.38062 H 130.18827 V 81.0659 c 0,-6.734639 -3.29287,-12.156633 -7.38191,-12.156633 z"
style="fill:#898989;stroke-width:3.01397;stroke-linecap:round"
id="path2" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

38
textures/plus.svg.import Normal file
View File

@ -0,0 +1,38 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d1k366i5jjtrk"
path.s3tc="res://.godot/imported/plus.svg-fa9840203ca82cc4696e02bad07ef61f.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://textures/plus.svg"
dest_files=["res://.godot/imported/plus.svg-fa9840203ca82cc4696e02bad07ef61f.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false