From 7770879003e100e600f8646c315460905795a762 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 21 Jul 2020 00:30:06 +0200 Subject: [PATCH] Implemented mob spawning (turned it off for now). Also now the menu now won't spawn in the dungeon. --- game/menu/Menu.tscn | 2 +- .../planets/test_planet/SimplePlanetData.tres | 2 +- .../planets/test_planet/dungeons/dungeon.gd | 50 +++++++++++-------- .../planets/test_planet/dungeons/dungeon.tres | 1 + .../world_generators/MainPlanetGenerator.gd | 1 + 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/game/menu/Menu.tscn b/game/menu/Menu.tscn index 174a5c56..d811656c 100644 --- a/game/menu/Menu.tscn +++ b/game/menu/Menu.tscn @@ -20,7 +20,7 @@ [ext_resource path="res://scripts/world_generators/MainPlanetGenerator.gd" type="Script" id=18] [ext_resource path="res://scripts/settings/DirectionalLightSettings.gd" type="Script" id=19] [ext_resource path="res://ui/about/About.tscn" type="PackedScene" id=20] -[ext_resource path="res://modules/planets/test_planet/DungeonPlanetData.tres" type="PlanetData" id=21] +[ext_resource path="res://modules/planets/test_planet/SimplePlanetData.tres" type="PlanetData" id=21] [sub_resource type="VoxelmanLevelGenerator" id=1] script = ExtResource( 18 ) diff --git a/game/modules/planets/test_planet/SimplePlanetData.tres b/game/modules/planets/test_planet/SimplePlanetData.tres index 247cc090..aee3118f 100644 --- a/game/modules/planets/test_planet/SimplePlanetData.tres +++ b/game/modules/planets/test_planet/SimplePlanetData.tres @@ -1,7 +1,7 @@ [gd_resource type="PlanetData" load_steps=3 format=2] [ext_resource path="res://modules/planets/test_planet/planets/simple_planet.tres" type="Planet" id=1] -[ext_resource path="res://modules/planets/test_planet/biomes/2_tdungb.tres" type="BiomeData" id=2] +[ext_resource path="res://modules/planets/test_planet/biomes/1_test.tres" type="BiomeData" id=2] [resource] id = 1 diff --git a/game/modules/planets/test_planet/dungeons/dungeon.gd b/game/modules/planets/test_planet/dungeons/dungeon.gd index 691248d7..ffe4db17 100644 --- a/game/modules/planets/test_planet/dungeons/dungeon.gd +++ b/game/modules/planets/test_planet/dungeons/dungeon.gd @@ -26,6 +26,8 @@ export(int) var min_room_dimension : int = 5 export(int) var max_room_dimension : int = 8 export(int) var enemy_count : int = 14 +export(bool) var spawn_mobs : bool = false + export(MeshDataResource) var dung_floor : MeshDataResource = null export(MeshDataResource) var dung_ceiling : MeshDataResource = null export(MeshDataResource) var dung_wall_xp : MeshDataResource = null @@ -49,6 +51,8 @@ var inner_entrance_position : Vector3 = Vector3() var player_inner_entrance_position_x : int = 0 var player_inner_entrance_position_z : int = 0 +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 } @@ -162,6 +166,14 @@ func _generate_chunk(chunk, spawn_mobs): zz += 1 xx += 1 zz = 0 + + if spawn_mobs: + for enemy in enemy_data: + var bp = enemy[0] + var pos : Vector3 = Vector3(bp.x * chunk.voxel_scale, floor_pos, bp.y * chunk.voxel_scale) + + ESS.entity_spawner.spawn_mob(enemy[1], enemy[2], pos) + # entities.app # for i in range(get_dungeon_start_room_count()): # get_dungeon_start_room(i).generate_chunk(chunk, spawn_mobs) @@ -192,28 +204,22 @@ func build(): #Server.sset_seed(_player.sseed) #Place enemies -# for i in range(enemy_count): -# var room = rooms[1 + randi() % (rooms.size() - 1)] -# var x = room.position.x + 1 + randi() % int (room.size.x - 2) -# var y = room.position.y + 1 + randi() % int (room.size.y - 2) -# -# var blocked = false -# for enemy in enemies: -# var body = enemy.get_body() -# var bp = body.get_tile_position() -# if bp.x == x && bp.y == y: -# blocked = true -# break -# -# if !blocked: -# var t = tile_to_pixel_center(x, y) -# var enemy = ESS.entity_spawner.spawn_mob(1, 1, Vector3(t.x, t.y, 0), get_path()) -# -# enemies.append(enemy) -# -# tile_map.update_dirty_quadrants() -# -# generated = true + if spawn_mobs: + for i in range(enemy_count): + var room = rooms[1 + randi() % (rooms.size() - 1)] + var x = room.position.x + 1 + randi() % int (room.size.x - 2) + var y = room.position.y + 1 + randi() % int (room.size.y - 2) + + var blocked = false + for enemy in enemy_data: + var bp = enemy[0] + if bp.x == x && bp.y == y: + blocked = true + break + + if !blocked: + enemy_data.append([Vector2(x, y), 1, 1]) + # var enemy = ESS.entity_spawner.spawn_mob(1, 1, Vector3(t.x, t.y, 0), get_path()) func build_level(): rooms.clear() diff --git a/game/modules/planets/test_planet/dungeons/dungeon.tres b/game/modules/planets/test_planet/dungeons/dungeon.tres index 04cfffdd..3e4c36df 100644 --- a/game/modules/planets/test_planet/dungeons/dungeon.tres +++ b/game/modules/planets/test_planet/dungeons/dungeon.tres @@ -21,6 +21,7 @@ level_room_count = 9 min_room_dimension = 5 max_room_dimension = 8 enemy_count = 14 +spawn_mobs = false dung_floor = ExtResource( 7 ) dung_ceiling = ExtResource( 4 ) dung_wall_xp = ExtResource( 5 ) diff --git a/game/scripts/world_generators/MainPlanetGenerator.gd b/game/scripts/world_generators/MainPlanetGenerator.gd index 0e5640a3..351c0de4 100644 --- a/game/scripts/world_generators/MainPlanetGenerator.gd +++ b/game/scripts/world_generators/MainPlanetGenerator.gd @@ -44,6 +44,7 @@ func setup(world : VoxelWorld, level_seed : int, spawn_mobs : bool, library: Vox _planet.current_seed = _level_seed _planet.setup() _planet.setup_library(_library) + _library.refresh_rects() # create_planet()