Implemented a teleporter, it has a test cube mesh with the brick texture for now, and made the dungeon spawn it. Also work on setting up the dungeon generation.

This commit is contained in:
Relintai 2020-07-18 22:42:50 +02:00
parent 4084debdad
commit f96a66300b
7 changed files with 124 additions and 23 deletions

View File

@ -43,6 +43,9 @@ func _generate_chunk(chunk: VoxelChunk, spawn_mobs: bool) -> void:
# generate_terrarin(chunk, spawn_mobs)
for i in range(get_dungeon_count()):
get_dungeon(i).generate_chunk(chunk, spawn_mobs)
generate_simple_terrarin(chunk, spawn_mobs)
if not Engine.editor_hint and chunk.position_y == 0 and spawn_mobs and randi() % 4 == 0:

View File

@ -0,0 +1,40 @@
extends StaticBody
export(Color) var default_albedo : Color = Color(0.494118, 0.494118, 0.494118)
export(Color) var hover_albedo : Color = Color(0.65098, 0.65098, 0.65098)
var teleport_to : Vector3 = Vector3()
func _ready():
connect("mouse_entered", self, "on_mouse_entered")
connect("mouse_exited", self, "on_mouse_exited")
var mat = $MeshInstance.get_surface_material(0)
mat.albedo_color = default_albedo
func on_mouse_entered():
var mat = $MeshInstance.get_surface_material(0)
mat.albedo_color = hover_albedo
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
func on_mouse_exited():
var mat = $MeshInstance.get_surface_material(0)
mat.albedo_color = default_albedo
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
func _input_event(camera: Object, event: InputEvent, click_position: Vector3, click_normal: Vector3, shape_idx: int):
if event is InputEventMouseButton && !event.pressed:
teleport()
if event is InputEventScreenTouch && !event.pressed:
teleport()
func teleport():
var world = get_node("..")
if world && world._player:
var p : Entity = world._player
p.get_body().transform.origin = teleport_to

View File

@ -0,0 +1,27 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://modules/planets/test_planet/dungeons/dung_teleporter.gd" type="Script" id=1]
[ext_resource path="res://modules/planets/test_planet/voxel_library/textures/test_brick_albedo.png" type="Texture" id=2]
[sub_resource type="CubeMesh" id=1]
size = Vector3( 1, 1, 1 )
[sub_resource type="SpatialMaterial" id=3]
flags_vertex_lighting = true
albedo_color = Color( 0.494118, 0.494118, 0.494118, 1 )
albedo_texture = ExtResource( 2 )
[sub_resource type="BoxShape" id=2]
extents = Vector3( 0.5, 0.5, 0.5 )
[node name="DungeonTeleporter" type="StaticBody"]
script = ExtResource( 1 )
default_albedo = Color( 0.521569, 0.521569, 0.521569, 1 )
hover_albedo = Color( 0.65098, 0.65098, 0.65098, 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
material/0 = SubResource( 3 )
[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 2 )

View File

@ -26,11 +26,15 @@ export(int) var min_room_dimension : int = 5
export(int) var max_room_dimension : int = 8
export(int) var enemy_count : int = 14
export(MeshDataResource) var dung_entrance_mdr : MeshDataResource = null
export(PackedScene) var dung_entrance_scene : PackedScene = null
var map : Array = []
var rooms : Array = []
var enemies : Array = []
#var nav_graph : AStar2D
var entrance_position : Transform = Transform()
var inner_entrance_position : Vector3 = Vector3()
enum Tile { None, Floor, Wall, Door }
@ -39,6 +43,9 @@ func _setup():
print("Dungeon size is 0!")
return
entrance_position.origin = Vector3(7, 5, 7)
inner_entrance_position = Vector3(10,10,10)
# if data.get_dungeon_start_room_data_count() == 0:
# return
#
@ -54,18 +61,37 @@ func _setup():
# dung.setup()
#
# add_dungeon_start_room(dung)
# build()
pass
func _setup_library(library):
._setup_library(library)
for i in range(get_dungeon_start_room_count()):
get_dungeon_start_room(i).setup_library(library)
build()
#
#func _setup_library(library):
# ._setup_library(library)
#
# for i in range(get_dungeon_start_room_count()):
# get_dungeon_start_room(i).setup_library(library)
func _generate_chunk(chunk, spawn_mobs):
for i in range(get_dungeon_start_room_count()):
get_dungeon_start_room(i).generate_chunk(chunk, spawn_mobs)
var aabb : AABB = AABB(Vector3(posx, posy, posz) * chunk.get_voxel_scale(), Vector3(sizex, sizey, sizez) * chunk.get_voxel_scale())
var chunk_aabb : AABB = AABB(chunk.get_position() * Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * chunk.get_voxel_scale(), Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * chunk.get_voxel_scale())
# if dung_entrance_mdr && chunk_aabb.has_point(entrance_position.origin):
#todo chunk needs an add func that takes global coords
# chunk.add_mesh_data_resource(entrance_position, dung_entrance_mdr)
if dung_entrance_scene && chunk_aabb.has_point(entrance_position.origin):
call_deferred("spawn_teleporter_scene", dung_entrance_scene, entrance_position, chunk, inner_entrance_position)
if !aabb.intersects(chunk_aabb):
return
# for i in range(get_dungeon_start_room_count()):
# get_dungeon_start_room(i).generate_chunk(chunk, spawn_mobs)
func spawn_teleporter_scene(scene : PackedScene, transform : Transform, chunk : VoxelChunk, teleports_to : Vector3):
var s = scene.instance()
chunk.get_voxel_world().add_child(s)
s.transform = transform
s.teleport_to = teleports_to
func build():
# randomize()
@ -76,6 +102,7 @@ func build():
# var player_x = start_room.position.x + 1 + randi() % int(start_room.size.x - 2)
# var player_y = start_room.position.y + 1 + randi() % int(start_room.size.y - 2)
#inner_entrance_position!
# entrance_position.origin = Vector2(player_x * tile_size + tile_size / 2, player_y * tile_size + tile_size / 2)
# _player = ESS.entity_spawner.load_player(_player_file_name, pos, 1) as Entity
#Server.sset_seed(_player.sseed)

View File

@ -1,6 +1,8 @@
[gd_resource type="Dungeon" load_steps=2 format=2]
[gd_resource type="Dungeon" load_steps=4 format=2]
[ext_resource path="res://modules/planets/test_planet/dungeons/dungeon.gd" type="Script" id=1]
[ext_resource path="res://modules/species/Human/Female/character_models/huf_calf_left.gltf" type="MeshDataResource" id=2]
[ext_resource path="res://modules/planets/test_planet/dungeons/dung_teleporter.tscn" type="PackedScene" id=3]
[resource]
sizex = 40
@ -11,3 +13,5 @@ level_room_count = 9
min_room_dimension = 5
max_room_dimension = 8
enemy_count = 14
dung_entrance_mdr = ExtResource( 2 )
dung_entrance_scene = ExtResource( 3 )

View File

@ -49,7 +49,7 @@ var rc : int = 0
func _enter_tree():
if generate_on_ready and not Engine.is_editor_hint():
# This crases pretty reliably, when duplicatiog BiomeBase, not yet sure why exactly
# This crashes pretty reliably, when duplicatiog BiomeBase, not yet sure why exactly
# call_deferred("generate")
generate()