Set up a Terraman2D based world.

This commit is contained in:
Relintai 2022-02-26 01:22:34 +01:00
parent f6c505242b
commit fa1fbd62db
8 changed files with 153 additions and 5 deletions

View File

@ -46,6 +46,7 @@ texture = ExtResource( 6 )
slots = [ null, SubResource( 1 ), null, null, null, null, null, null, null, null, null, null, null, null, SubResource( 2 ), null ] slots = [ null, SubResource( 1 ), null, null, null, null, null, null, null, null, null, null, null, null, SubResource( 2 ), null ]
[node name="Character" type="CharacterSkeleton2D"] [node name="Character" type="CharacterSkeleton2D"]
modulate = Color( 0.745098, 0.745098, 0.745098, 1 )
entity_type = 1 entity_type = 1
attach_point_paths/0_left_hand = NodePath("") attach_point_paths/0_left_hand = NodePath("")
attach_point_paths/1_right_hand = NodePath("") attach_point_paths/1_right_hand = NodePath("")

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://scenes/MainScene.gd" type="Script" id=1] [ext_resource path="res://scenes/MainScene.gd" type="Script" id=1]
[ext_resource path="res://scenes/World.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/terra_2d_world/Terrain2DWorldBlocky.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/menu/Menu.tscn" type="PackedScene" id=3] [ext_resource path="res://scenes/menu/Menu.tscn" type="PackedScene" id=3]
[ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=4] [ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=4]
[ext_resource path="res://ui/debug/DebugInfo.tscn" type="PackedScene" id=5] [ext_resource path="res://ui/debug/DebugInfo.tscn" type="PackedScene" id=5]

View File

@ -1,12 +1,9 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://scenes/World.gd" type="Script" id=1] [ext_resource path="res://scenes/World.gd" type="Script" id=1]
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2] [ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://modules/planets/TileMap64x32.tscn" type="PackedScene" id=3]
[node name="World" type="Node2D" groups=["save"]] [node name="World" type="Node2D" groups=["save"]]
scale = Vector2( 1, 0.706 ) scale = Vector2( 1, 0.706 )
script = ExtResource( 1 ) script = ExtResource( 1 )
world_layer = ExtResource( 2 ) world_layer = ExtResource( 2 )
[node name="TileMap" parent="." instance=ExtResource( 3 )]

View File

@ -0,0 +1,14 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://scenes/terra_2d_world/Terrain2DWorldBlockyGD.gd" type="Script" id=1]
[ext_resource path="res://scenes/terra_2d_world/new_terrain2dlibrarymergerpcm.tres" type="Terrain2DLibraryMergerPCM" id=2]
[ext_resource path="res://scenes/terra_2d_world/new_terrain2dlevelgenerator.tres" type="Terrain2DLevelGenerator" id=3]
[node name="Terrain2DWorldBlocky" type="Terrain2DWorldBlocky" groups=["save"]]
library = ExtResource( 2 )
level_generator = ExtResource( 3 )
cell_size_x = 64
cell_size_y = 64
get_custom_transform = Transform2D( 1, 0.5, -1, 0.5, 0, 0 )
build_flags = 127
script = ExtResource( 1 )

View File

@ -0,0 +1,97 @@
tool
extends Terrain2DWorldBlocky
# Copyright (c) 2019 Péter Magyar
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
export(int) var spawn_range : int = 2
export(bool) var spawn_mobs : bool = true
export(bool) var show_loading_screen : bool = true
export(bool) var generate_on_ready : bool = false
export(bool) var generate setget set_generate, get_generate
export(bool) var clear setget set_clear, get_clear
var initial_generation : bool = false
var _player_file_name : String
var _player : Entity
func _enter_tree():
if !Engine.editor_hint && generate_on_ready:
spawn(0, 0)
func spawn(x, y):
chunks_clear()
for xx in range(x - spawn_range, x + spawn_range):
for yy in range(y - spawn_range, y + spawn_range):
chunk_create(xx, yy)
func set_clear(val):
if (val):
chunks_clear()
func get_clear():
return false
func load_character(file_name: String) -> void:
_player_file_name = file_name
_player = ESS.entity_spawner.load_player(file_name, Vector3(5, 5, 0), 1) as Entity
#TODO hack, do this properly
# _player.set_physics_process(false)
Server.sset_seed(_player.sseed)
spawn(0, 0)
if spawn_mobs:
generate()
func generate() -> void:
for x in range(-2, 2):
for y in range(-2, 2):
ESS.entity_spawner.spawn_mob(1, 50, Vector3(x * 200, y * 200, 0))
func save() -> void:
if _player == null or _player_file_name == "":
return
ESS.entity_spawner.save_player(_player, _player_file_name)
func _generation_finished():
if show_loading_screen and not Engine.editor_hint:
get_node("..").hide_loading_screen()
# if _player:
# _player.set_physics_process(true)
func set_generate(val):
if (val):
library.refresh_rects()
#level_generator.setup(self, current_seed, false, library)
spawn(0, 0)
func get_generate():
return false

View File

@ -0,0 +1,8 @@
tool
extends Terrain2DLevelGenerator
func _generate_chunk(chunk : Terrain2DChunk):
chunk.channel_ensure_allocated(Terrain2DChunkDefault.DEFAULT_CHANNEL_TYPE, 1)
#chunk.set_voxel(2, 1, 1, Terrain2DChunkDefault.DEFAULT_CHANNEL_TYPE)

View File

@ -0,0 +1,6 @@
[gd_resource type="Terrain2DLevelGenerator" load_steps=2 format=2]
[ext_resource path="res://scenes/terra_2d_world/levelgen.gd" type="Script" id=1]
[resource]
script = ExtResource( 1 )

View File

@ -0,0 +1,25 @@
[gd_resource type="Terrain2DLibraryMergerPCM" load_steps=11 format=2]
[ext_resource path="res://modules/planets/textures/dirt_albedo.png" type="Texture" id=1]
[ext_resource path="res://modules/planets/textures/stone_1_albedo.png" type="Texture" id=2]
[ext_resource path="res://modules/planets/textures/test_brick_albedo.png" type="Texture" id=3]
[ext_resource path="res://modules/planets/textures/stone_dungeon_1_albedo.png" type="Texture" id=4]
[ext_resource path="res://modules/planets/textures/grass_albedo.png" type="Texture" id=5]
[sub_resource type="Terrain2DSurfaceMerger" id=1]
texture = ExtResource( 5 )
[sub_resource type="Terrain2DSurfaceMerger" id=2]
texture = ExtResource( 1 )
[sub_resource type="Terrain2DSurfaceMerger" id=3]
texture = ExtResource( 2 )
[sub_resource type="Terrain2DSurfaceMerger" id=4]
texture = ExtResource( 4 )
[sub_resource type="Terrain2DSurfaceMerger" id=5]
texture = ExtResource( 3 )
[resource]
terra_surfaces = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ]