Little work on the vman dungeon.

This commit is contained in:
Relintai 2020-09-01 23:37:36 +02:00
parent f0ff24b2a7
commit 2d15234eb8

View File

@ -28,6 +28,10 @@ export(int) var enemy_count : int = 14
export(bool) var spawn_mobs : bool = false export(bool) var spawn_mobs : bool = false
export(Texture) var wall_texture : Texture
export(Texture) var floor_texture : Texture
export(Texture) var ceiling_texture : Texture
export(MeshDataResource) var dung_entrance_mdr : MeshDataResource = null export(MeshDataResource) var dung_entrance_mdr : MeshDataResource = null
export(PackedScene) var dung_entrance_scene : PackedScene = null export(PackedScene) var dung_entrance_scene : PackedScene = null
@ -45,8 +49,6 @@ var next_level_teleporter_position_data_space : Vector3 = Vector3()
var enemy_data : Array = [] var enemy_data : Array = []
# in binary: WallXP = 00001, WallXN = 0010, WallZP = 0100, WallZN = 1000
enum NeighbourCaseCodeFlags { WallXP = 1, WallXN = 2, WallZP = 4, WallZN = 8 }
enum Tile { Wall, Floor, Door, Empty } enum Tile { Wall, Floor, Door, Empty }
func _instance(p_seed, p_instance): func _instance(p_seed, p_instance):
@ -89,10 +91,6 @@ func _setup():
build() build()
func _setup_library(library):
._setup_library(library)
func _generate_chunk(chunk, spawn_mobs): func _generate_chunk(chunk, spawn_mobs):
var aabb : AABB = AABB(Vector3(posx - 1, posy - 1, posz - 1) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale), Vector3(sizex + 2, sizey + 2, sizez + 2) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale)) var aabb : AABB = AABB(Vector3(posx - 1, posy - 1, posz - 1) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale), Vector3(sizex + 2, sizey + 2, sizez + 2) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale))
var chunk_aabb : AABB = AABB(chunk.get_position() * Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale), Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale)) var chunk_aabb : AABB = AABB(chunk.get_position() * Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale), Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale))
@ -136,6 +134,25 @@ func _generate_chunk(chunk, spawn_mobs):
ceiling_pos = chunk.size_y ceiling_pos = chunk.size_y
draw_ceiling = false draw_ceiling = false
var xx : int = 0
var zz : int = 0
for x in range(px, tox):
for z in range(pz, toz):
var tile : int = map[x][z]
#we can safely check like this
if tile > Tile.Wall:
add_wall(chunk, xx, zz, floor_pos, ceiling_pos, null, wall_texture)
# if draw_floor:
# chunk.add_mesh_data_resourcev(Vector3(xx, floor_pos, zz), dung_floor, floor_texture)
#
# if draw_ceiling:
# chunk.add_mesh_data_resourcev(Vector3(xx, ceiling_pos, zz), dung_ceiling, ceiling_texture)
zz += 1
xx += 1
zz = 0
if spawn_mobs: if spawn_mobs:
for enemy in enemy_data: for enemy in enemy_data:
var bp = enemy[0] var bp = enemy[0]
@ -222,34 +239,6 @@ func build_level():
connect_rooms() connect_rooms()
#post process walls, so they have the correct type
var neighbours : int = 0
for x in range(sizex):
for z in range(sizez):
if map[x][z] == Tile.Floor:
if x != 0:
if map[x - 1][z] <= Tile.Wall:
neighbours |= NeighbourCaseCodeFlags.WallXP
if x != sizex - 1:
if map[x + 1][z] <= Tile.Wall:
neighbours |= NeighbourCaseCodeFlags.WallXN
if z != 0:
if map[x][z - 1] <= Tile.Wall:
neighbours |= NeighbourCaseCodeFlags.WallZP
if z != sizez - 1:
if map[x][z + 1] <= Tile.Wall:
neighbours |= NeighbourCaseCodeFlags.WallZN
#left shift all bits by 4 -> (binary) 0000XXXX -> XXXX0000
neighbours = neighbours << 4
#bitwise or them together -> (Tile.Floor = 1 = 00000001) -> (binary) 000000001 | XXXX0000 -> XXXX0001
map[x][z] = Tile.Floor | neighbours
neighbours = 0
func connect_rooms(): func connect_rooms():
var stone_graph : AStar2D = AStar2D.new() var stone_graph : AStar2D = AStar2D.new()
var point_id : int = 0 var point_id : int = 0