parent
378c5accfa
commit
a429c3590d
@ -0,0 +1,40 @@ |
||||
[gd_scene load_steps=5 format=2] |
||||
|
||||
[ext_resource path="res://ProceduralGenerator.gd" type="Script" id=1] |
||||
[ext_resource path="res://meshes.meshlib" type="MeshLibrary" id=2] |
||||
[ext_resource path="res://Player.gd" type="Script" id=3] |
||||
|
||||
[sub_resource type="CapsuleMesh" id=1] |
||||
|
||||
[node name="Spatial" type="Spatial"] |
||||
|
||||
[node name="GridMap" type="GridMap" parent="."] |
||||
mesh_library = ExtResource( 2 ) |
||||
cell_size = Vector3( 1, 1, 1 ) |
||||
cell_octant_size = 512 |
||||
cell_center_x = false |
||||
cell_center_y = false |
||||
cell_center_z = false |
||||
script = ExtResource( 1 ) |
||||
__meta__ = { |
||||
"_editor_clip_": 0 |
||||
} |
||||
ChunkWidth = 64 |
||||
ChunkHeight = 64 |
||||
|
||||
[node name="Player" type="Spatial" parent="GridMap"] |
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 20, 0 ) |
||||
script = ExtResource( 3 ) |
||||
|
||||
[node name="MeshInstance" type="MeshInstance" parent="GridMap/Player"] |
||||
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) |
||||
mesh = SubResource( 1 ) |
||||
|
||||
[node name="Camera" type="Camera" parent="GridMap/Player"] |
||||
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 10, 0 ) |
||||
|
||||
[node name="MapUpdateTimer" type="Timer" parent="GridMap"] |
||||
wait_time = 0.1 |
||||
autostart = true |
||||
|
||||
[connection signal="timeout" from="GridMap/MapUpdateTimer" to="GridMap" method="_on_MapUpdateTimer_timeout"] |
||||
@ -0,0 +1,46 @@ |
||||
[gd_scene load_steps=8 format=2] |
||||
|
||||
[sub_resource type="CubeMesh" id=1] |
||||
|
||||
[sub_resource type="SpatialMaterial" id=2] |
||||
albedo_color = Color( 0.266667, 0.211765, 0.74902, 1 ) |
||||
|
||||
[sub_resource type="SpatialMaterial" id=3] |
||||
albedo_color = Color( 0.054902, 0.588235, 0.843137, 1 ) |
||||
|
||||
[sub_resource type="SpatialMaterial" id=4] |
||||
albedo_color = Color( 0.882353, 0.811765, 0.0588235, 1 ) |
||||
|
||||
[sub_resource type="SpatialMaterial" id=5] |
||||
albedo_color = Color( 0.121569, 0.756863, 0.32549, 1 ) |
||||
|
||||
[sub_resource type="SpatialMaterial" id=6] |
||||
albedo_color = Color( 0.611765, 0.611765, 0.611765, 1 ) |
||||
|
||||
[sub_resource type="SpatialMaterial" id=7] |
||||
|
||||
[node name="MeshLib" type="Spatial"] |
||||
|
||||
[node name="Tile_DeepWaterBlock" type="MeshInstance" parent="."] |
||||
mesh = SubResource( 1 ) |
||||
material/0 = SubResource( 2 ) |
||||
|
||||
[node name="Tile_WaterBlock" type="MeshInstance" parent="."] |
||||
mesh = SubResource( 1 ) |
||||
material/0 = SubResource( 3 ) |
||||
|
||||
[node name="Tile_SandBlock" type="MeshInstance" parent="."] |
||||
mesh = SubResource( 1 ) |
||||
material/0 = SubResource( 4 ) |
||||
|
||||
[node name="Tile_GrassBlock" type="MeshInstance" parent="."] |
||||
mesh = SubResource( 1 ) |
||||
material/0 = SubResource( 5 ) |
||||
|
||||
[node name="Tile_StoneBlock" type="MeshInstance" parent="."] |
||||
mesh = SubResource( 1 ) |
||||
material/0 = SubResource( 6 ) |
||||
|
||||
[node name="Tile_SnowBlock" type="MeshInstance" parent="."] |
||||
mesh = SubResource( 1 ) |
||||
material/0 = SubResource( 7 ) |
||||
@ -0,0 +1,20 @@ |
||||
extends Spatial |
||||
|
||||
|
||||
const SPEED = 0.25 |
||||
|
||||
|
||||
func _physics_process(delta): |
||||
# Movement |
||||
var motion = Vector3() |
||||
|
||||
if Input.is_action_pressed("ui_up"): |
||||
motion.z += -1.0 |
||||
if Input.is_action_pressed("ui_down"): |
||||
motion.z += 1.0 |
||||
if Input.is_action_pressed("ui_left"): |
||||
motion.x += -1.0 |
||||
if Input.is_action_pressed("ui_right"): |
||||
motion.x += 1.0 |
||||
|
||||
global_transform.origin += motion * SPEED |
||||
@ -0,0 +1,52 @@ |
||||
extends GridMap |
||||
|
||||
export(int) var ChunkWidth: int = 0 |
||||
export(int) var ChunkHeight: int = 0 |
||||
|
||||
var heightMapTexture = NoiseTexture.new() |
||||
|
||||
onready var player = $Player |
||||
|
||||
func _ready(): |
||||
randomize() |
||||
heightMapTexture.width = 512 |
||||
heightMapTexture.height = 512 |
||||
heightMapTexture.noise = OpenSimplexNoise.new() |
||||
heightMapTexture.noise.seed = randi() |
||||
|
||||
print("Seed: " + str(heightMapTexture.noise.seed)) |
||||
|
||||
setGridChunk(0, ChunkWidth, 0, ChunkHeight) |
||||
|
||||
func generateGridChunk(playerPos: Vector3) -> void: |
||||
clear() |
||||
var chunkCenter = world_to_map(playerPos) |
||||
var rowStart: float = chunkCenter.z - (ChunkHeight / 2) |
||||
var rowEnd: float = chunkCenter.z + (ChunkHeight / 2) |
||||
var columnStart: float = chunkCenter.x - (ChunkWidth / 2) |
||||
var columnEnd: float = chunkCenter.x + (ChunkWidth / 2) |
||||
setGridChunk(columnStart, columnEnd, rowStart, rowEnd) |
||||
|
||||
func setGridChunk(columnStart: float, columnEnd: float, rowStart: float, rowEnd: float) -> void: |
||||
if columnStart < 0 : |
||||
columnStart = 0 |
||||
if rowStart < 0 : |
||||
rowStart = 0 |
||||
if columnEnd > heightMapTexture.width : |
||||
columnEnd = heightMapTexture.width - 1 |
||||
if rowEnd > heightMapTexture.height : |
||||
rowEnd = heightMapTexture.height - 1 |
||||
|
||||
for mz in range(rowStart, rowEnd): |
||||
for mx in range(columnStart, columnEnd): |
||||
var noiseValue: float = heightMapTexture.noise.get_noise_2d(mx, mz) |
||||
var weight: float = (noiseValue + 1) / 2 |
||||
var height: float = floor(lerp(0, 8, weight)) * 2 |
||||
for my in range(0, height): |
||||
var meshID = floor(my / 2) |
||||
set_cell_item(mx, my * 2, mz, meshID, 0) |
||||
|
||||
|
||||
|
||||
func _on_MapUpdateTimer_timeout(): |
||||
generateGridChunk(player.global_transform.origin) |
||||
@ -0,0 +1,7 @@ |
||||
[gd_resource type="Environment" load_steps=2 format=2] |
||||
|
||||
[sub_resource type="ProceduralSky" id=1] |
||||
|
||||
[resource] |
||||
background_mode = 2 |
||||
background_sky = SubResource( 1 ) |
||||
@ -0,0 +1,35 @@ |
||||
[remap] |
||||
|
||||
importer="texture" |
||||
type="StreamTexture" |
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" |
||||
metadata={ |
||||
"vram_texture": false |
||||
} |
||||
|
||||
[deps] |
||||
|
||||
source_file="res://icon.png" |
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] |
||||
|
||||
[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 |
||||
flags/mipmaps=false |
||||
flags/anisotropic=false |
||||
flags/srgb=2 |
||||
process/fix_alpha_border=true |
||||
process/premult_alpha=false |
||||
process/HDR_as_SRGB=false |
||||
process/invert_color=false |
||||
process/normal_map_invert_y=false |
||||
stream=false |
||||
size_limit=0 |
||||
detect_3d=true |
||||
svg/scale=1.0 |
||||
Binary file not shown.
@ -0,0 +1,26 @@ |
||||
; Engine configuration file. |
||||
; It's best edited using the editor UI and not directly, |
||||
; since the parameters that go here are not all obvious. |
||||
; |
||||
; Format: |
||||
; [section] ; section goes between [] |
||||
; param=value ; assign values to parameters |
||||
|
||||
config_version=4 |
||||
|
||||
[application] |
||||
|
||||
config/name="gridmap" |
||||
config/icon="res://icon.png" |
||||
|
||||
[gui] |
||||
|
||||
common/drop_mouse_on_gui_input_disabled=true |
||||
|
||||
[physics] |
||||
|
||||
common/enable_pause_aware_picking=true |
||||
|
||||
[rendering] |
||||
|
||||
environment/default_environment="res://default_env.tres" |
||||
Loading…
Reference in new issue