From 9e3deaf3b064ba7ea3d1d0263ce4ea7f5bc51a13 Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Sun, 21 Jan 2024 16:39:13 +0100 Subject: [PATCH] Mag gen & work towards AI --- assets/tiles.tres | 16 +++- nodes/v2/creatures/enemies/basic_enemy.tscn | 21 ++++ .../worldgen/entity_markers/enemy_marker.tscn | 11 +++ .../worldgen/entity_markers/exit_marker.tscn | 12 +++ .../entity_markers/player_marker.tscn | 11 +++ scenes/v2/world.tscn | 2 + .../roomsets/standard/medium_room_up.tscn | 2 +- .../standard/medium_room_up_down.tscn | 2 +- .../roomsets/standard/small_fork.tscn | 2 +- .../standard/small_room_down_right.tscn | 2 +- .../roomsets/standard/spawn_room.tscn | 2 +- scripts/baddie.gd | 6 -- scripts/basic_enemy.gd | 4 +- scripts/player.gd | 2 +- scripts/v2/creature.gd | 56 +++++++++++ scripts/v2/enemy.gd | 42 ++++++++ scripts/v2/world.gd | 5 - scripts/v2/worldgen/standard/entity_marker.gd | 65 +++++++++++++ scripts/v2/worldgen/standard/room.gd | 4 +- scripts/v2/worldgen/standard_generator.gd | 95 +++++++++++++++++++ 20 files changed, 341 insertions(+), 21 deletions(-) create mode 100644 nodes/v2/creatures/enemies/basic_enemy.tscn create mode 100644 nodes/v2/worldgen/entity_markers/enemy_marker.tscn create mode 100644 nodes/v2/worldgen/entity_markers/exit_marker.tscn create mode 100644 nodes/v2/worldgen/entity_markers/player_marker.tscn create mode 100644 scripts/v2/creature.gd create mode 100644 scripts/v2/enemy.gd create mode 100644 scripts/v2/worldgen/standard/entity_marker.gd diff --git a/assets/tiles.tres b/assets/tiles.tres index 0e99012..f51cb4d 100644 --- a/assets/tiles.tres +++ b/assets/tiles.tres @@ -1,8 +1,11 @@ -[gd_resource type="TileSet" load_steps=7 format=3 uid="uid://cluemfplimly4"] +[gd_resource type="TileSet" load_steps=11 format=3 uid="uid://cluemfplimly4"] [ext_resource type="Texture2D" uid="uid://db56d1182ln4b" path="res://assets/art/Tiles/computer_tile1.png" id="1_5muy3"] [ext_resource type="Texture2D" uid="uid://klj2jswq3s4w" path="res://assets/art/Tiles/platform_tile.png" id="2_owfas"] [ext_resource type="Texture2D" uid="uid://dw5bnymac2wha" path="res://assets/art/Tiles/computer_tile_safe.png" id="3_ca38s"] +[ext_resource type="PackedScene" uid="uid://bo2usnpwbmtph" path="res://nodes/v2/worldgen/entity_markers/exit_marker.tscn" id="4_skp8u"] +[ext_resource type="PackedScene" uid="uid://b3yvofe5j167l" path="res://nodes/v2/worldgen/entity_markers/player_marker.tscn" id="5_5hygb"] +[ext_resource type="PackedScene" uid="uid://b4oxvram27p0u" path="res://nodes/v2/worldgen/entity_markers/enemy_marker.tscn" id="6_m5a4l"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_hu2b2"] texture = ExtResource("1_5muy3") @@ -18,6 +21,7 @@ texture = ExtResource("2_owfas") 0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 0:0/0/physics_layer_0/angular_velocity = 0.0 0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, -4, -8, -4) +0:0/0/physics_layer_0/polygon_0/one_way = true 0:0/1 = 1 0:0/1/flip_h = true 0:0/1/physics_layer_0/linear_velocity = Vector2(0, 0) @@ -65,8 +69,18 @@ texture = ExtResource("3_ca38s") 0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 0:0/0/physics_layer_0/angular_velocity = 0.0 +[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_mxjkl"] +resource_name = "Entity Markers" +scenes/1/scene = ExtResource("4_skp8u") +scenes/1/display_placeholder = ExtResource("4_skp8u") +scenes/2/scene = ExtResource("5_5hygb") +scenes/2/display_placeholder = ExtResource("5_5hygb") +scenes/3/scene = ExtResource("6_m5a4l") +scenes/3/display_placeholder = ExtResource("6_m5a4l") + [resource] physics_layer_0/collision_layer = 1 sources/0 = SubResource("TileSetAtlasSource_hu2b2") sources/1 = SubResource("TileSetAtlasSource_1rql8") sources/2 = SubResource("TileSetAtlasSource_57o2x") +sources/3 = SubResource("TileSetScenesCollectionSource_mxjkl") diff --git a/nodes/v2/creatures/enemies/basic_enemy.tscn b/nodes/v2/creatures/enemies/basic_enemy.tscn new file mode 100644 index 0000000..c5f4be0 --- /dev/null +++ b/nodes/v2/creatures/enemies/basic_enemy.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=5 format=3 uid="uid://bgdkduh2uevft"] + +[ext_resource type="Script" path="res://scripts/v2/enemy.gd" id="1_jfeur"] +[ext_resource type="Texture2D" uid="uid://iewpb4eaydo1" path="res://assets/art/Enemies/basic_enemy1.png" id="2_g0kyc"] +[ext_resource type="AudioStream" uid="uid://btf1rlmxtf4bg" path="res://assets/sound/Bomb_Explosion.wav" id="2_pspk3"] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_htsfi"] +radius = 3.0 +height = 16.0 + +[node name="BasicEnemy" type="CharacterBody2D"] +script = ExtResource("1_jfeur") +max_hp = 3 +death_sound = ExtResource("2_pspk3") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture_filter = 1 +texture = ExtResource("2_g0kyc") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CapsuleShape2D_htsfi") diff --git a/nodes/v2/worldgen/entity_markers/enemy_marker.tscn b/nodes/v2/worldgen/entity_markers/enemy_marker.tscn new file mode 100644 index 0000000..740c274 --- /dev/null +++ b/nodes/v2/worldgen/entity_markers/enemy_marker.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="uid://b4oxvram27p0u"] + +[ext_resource type="Script" path="res://scripts/v2/worldgen/standard/entity_marker.gd" id="1_vuvjk"] +[ext_resource type="PackedScene" uid="uid://bgdkduh2uevft" path="res://nodes/v2/creatures/enemies/basic_enemy.tscn" id="2_qxhxm"] + +[node name="EnemyMarker" type="Node2D"] +script = ExtResource("1_vuvjk") +marker_id = "enemy" +entities = Array[PackedScene]([ExtResource("2_qxhxm")]) +spawn_chance = 0.8 +debug_color = Color(0.686275, 0, 0.0156863, 1) diff --git a/nodes/v2/worldgen/entity_markers/exit_marker.tscn b/nodes/v2/worldgen/entity_markers/exit_marker.tscn new file mode 100644 index 0000000..02feda5 --- /dev/null +++ b/nodes/v2/worldgen/entity_markers/exit_marker.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=3 uid="uid://bo2usnpwbmtph"] + +[ext_resource type="Script" path="res://scripts/v2/worldgen/standard/entity_marker.gd" id="1_5qujy"] +[ext_resource type="PackedScene" path="res://nodes/exit.tscn" id="2_gvvu0"] + +[node name="ExitMarker" type="Node2D"] +script = ExtResource("1_5qujy") +marker_id = "exit" +entities = Array[PackedScene]([ExtResource("2_gvvu0")]) +spawn_method = 1 +entity_selection_method = 1 +debug_color = Color(0.129412, 1, 1, 1) diff --git a/nodes/v2/worldgen/entity_markers/player_marker.tscn b/nodes/v2/worldgen/entity_markers/player_marker.tscn new file mode 100644 index 0000000..cbd0cae --- /dev/null +++ b/nodes/v2/worldgen/entity_markers/player_marker.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="uid://b3yvofe5j167l"] + +[ext_resource type="Script" path="res://scripts/v2/worldgen/standard/entity_marker.gd" id="1_f63ew"] +[ext_resource type="PackedScene" uid="uid://de3exlu8jniam" path="res://nodes/player.tscn" id="2_ka5cd"] + +[node name="PlayerMarker" type="Node2D"] +script = ExtResource("1_f63ew") +marker_id = "player_spawn" +entities = Array[PackedScene]([ExtResource("2_ka5cd")]) +spawn_method = 2 +debug_color = Color(0, 0.160784, 0.886275, 1) diff --git a/scenes/v2/world.tscn b/scenes/v2/world.tscn index 92a90fb..7d17d1a 100644 --- a/scenes/v2/world.tscn +++ b/scenes/v2/world.tscn @@ -10,7 +10,9 @@ generator = ExtResource("2_ag01j") map = NodePath("TileMap") [node name="TileMap" type="TileMap" parent="."] +texture_filter = 1 tile_set = ExtResource("3_5mj08") format = 2 [node name="Camera2D" type="Camera2D" parent="."] +enabled = false diff --git a/scenes/v2/worldgen/roomsets/standard/medium_room_up.tscn b/scenes/v2/worldgen/roomsets/standard/medium_room_up.tscn index 271f419..c8ea214 100644 --- a/scenes/v2/worldgen/roomsets/standard/medium_room_up.tscn +++ b/scenes/v2/worldgen/roomsets/standard/medium_room_up.tscn @@ -6,6 +6,6 @@ [node name="MediumRoomUp" type="TileMap"] tile_set = ExtResource("1_ucjv8") format = 2 -layer_0/tile_data = PackedInt32Array(0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 65536, 0, 0, 131072, 0, 0, 196608, 0, 0, 262144, 0, 0, 65552, 0, 0, 131088, 0, 0, 196624, 0, 0, 327680, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 589824, 0, 0, 655360, 0, 0, 720896, 0, 0, 720897, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720909, 0, 0, 720910, 0, 0, 589840, 0, 0, 524304, 0, 0, 458768, 0, 0, 393232, 0, 0, 327696, 0, 0, 262160, 0, 0, 720912, 0, 0, 655376, 0, 0, 720911, 0, 0, 720907, 0, 0, 720906, 0, 0, 720905, 0, 0, 720904, 0, 0, 720903, 0, 0, 720908, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 8, 1, 0, 65543, 1, 0, 65545, 1, 0, 196612, 0, 0, 196613, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 196619, 0, 0, 196620, 0, 0, 262156, 0, 0, 327692, 0, 0, 393228, 0, 0, 458764, 0, 0, 589837, 1, 0, 589839, 1, 0, 524302, 1, 0, 458765, 1, 0, 458767, 1, 0, 393230, 1, 0, 327693, 1, 0, 327695, 1, 0, 262158, 1, 0, 196621, 1, 0, 196623, 1, 0, 458760, 0, 0, 458759, 0, 0, 458758, 0, 0, 458757, 0, 0, 458756, 0, 0, 458755, 0, 0, 458754, 0, 0, 458753, 0, 0) +layer_0/tile_data = PackedInt32Array(0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 65536, 0, 0, 131072, 0, 0, 196608, 0, 0, 262144, 0, 0, 65552, 0, 0, 131088, 0, 0, 196624, 0, 0, 327680, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 589824, 0, 0, 655360, 0, 0, 720896, 0, 0, 720897, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720909, 0, 0, 720910, 0, 0, 589840, 0, 0, 524304, 0, 0, 458768, 0, 0, 393232, 0, 0, 327696, 0, 0, 262160, 0, 0, 720912, 0, 0, 655376, 0, 0, 720911, 0, 0, 720907, 0, 0, 720906, 0, 0, 720905, 0, 0, 720904, 0, 0, 720903, 0, 0, 720908, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 8, 1, 0, 65543, 1, 0, 65545, 1, 0, 196612, 0, 0, 196613, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 196619, 0, 0, 196620, 0, 0, 262156, 0, 0, 327692, 0, 0, 393228, 0, 0, 458764, 0, 0, 589837, 1, 0, 589839, 1, 0, 524302, 1, 0, 458765, 1, 0, 458767, 1, 0, 393230, 1, 0, 327693, 1, 0, 327695, 1, 0, 262158, 1, 0, 196621, 1, 0, 196623, 1, 0, 458760, 0, 0, 458759, 0, 0, 458758, 0, 0, 458757, 0, 0, 458756, 0, 0, 458755, 0, 0, 458754, 0, 0, 458753, 0, 0, 655362, 3, 65536, 131080, 3, 65536, 655365, 3, 196608, 655369, 3, 196608, 655374, 3, 196608, 327686, 3, 196608, 327683, 3, 196608, 131083, 3, 196608) script = ExtResource("2_nekba") top = true diff --git a/scenes/v2/worldgen/roomsets/standard/medium_room_up_down.tscn b/scenes/v2/worldgen/roomsets/standard/medium_room_up_down.tscn index 6b13ea5..cf73d4b 100644 --- a/scenes/v2/worldgen/roomsets/standard/medium_room_up_down.tscn +++ b/scenes/v2/worldgen/roomsets/standard/medium_room_up_down.tscn @@ -6,7 +6,7 @@ [node name="MediumRoomUpDown" type="TileMap"] tile_set = ExtResource("1_0bmf2") format = 2 -layer_0/tile_data = PackedInt32Array(0, 0, 0, 65536, 0, 0, 131072, 0, 0, 196608, 0, 0, 262144, 0, 0, 327680, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 589824, 0, 0, 655360, 0, 0, 720896, 0, 0, 1, 0, 0, 720897, 0, 0, 2, 0, 0, 720898, 0, 0, 3, 0, 0, 720899, 0, 0, 4, 0, 0, 720900, 0, 0, 5, 0, 0, 720901, 0, 0, 6, 0, 0, 720902, 0, 0, 10, 0, 0, 720906, 0, 0, 11, 0, 0, 720907, 0, 0, 720908, 0, 0, 720909, 0, 0, 720910, 0, 0, 720911, 0, 0, 196624, 0, 0, 262160, 0, 0, 327696, 0, 0, 393232, 0, 0, 458768, 0, 0, 524304, 0, 0, 589840, 0, 0, 655376, 0, 0, 720912, 0, 0, 720903, 1, 0, 720905, 1, 0, 8, 1, 0, 65543, 1, 0, 65545, 1, 0, 458759, 0, 0, 458758, 0, 0, 458760, 0, 0, 458761, 0, 0, 458757, 0, 0, 458756, 0, 0, 458762, 0, 0, 458763, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 196619, 0, 0, 65546, 0, 0, 131082, 0, 0, 131083, 0, 0, 65547, 0, 0, 196620, 0, 0, 196621, 0, 0, 196622, 0, 0, 196623, 0, 0, 458764, 0, 0, 589837, 1, 0, 589839, 1, 0, 524302, 1, 0, 458765, 1, 0, 458767, 1, 0, 458755, 1, 0, 458753, 1, 0, 524290, 1, 0, 589825, 1, 0, 589827, 1, 0, 393218, 1, 0, 327681, 1, 0, 327683, 1, 0, 262146, 1, 0, 196609, 1, 0, 196611, 1, 0, 262156, 0, 0, 262157, 0, 0, 262158, 0, 0, 262159, 0, 0, 262148, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 65552, 0, 0, 131088, 0, 0, 131087, 0, 0, 131086, 0, 0, 131085, 0, 0, 131084, 0, 0, 65548, 0, 0, 65549, 0, 0, 65550, 0, 0, 65551, 0, 0) +layer_0/tile_data = PackedInt32Array(0, 0, 0, 65536, 0, 0, 131072, 0, 0, 196608, 0, 0, 262144, 0, 0, 327680, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 589824, 0, 0, 655360, 0, 0, 720896, 0, 0, 1, 0, 0, 720897, 0, 0, 2, 0, 0, 720898, 0, 0, 3, 0, 0, 720899, 0, 0, 4, 0, 0, 720900, 0, 0, 5, 0, 0, 720901, 0, 0, 6, 0, 0, 720902, 0, 0, 10, 0, 0, 720906, 0, 0, 11, 0, 0, 720907, 0, 0, 720908, 0, 0, 720909, 0, 0, 720910, 0, 0, 720911, 0, 0, 196624, 0, 0, 262160, 0, 0, 327696, 0, 0, 393232, 0, 0, 458768, 0, 0, 524304, 0, 0, 589840, 0, 0, 655376, 0, 0, 720912, 0, 0, 720903, 1, 0, 720905, 1, 0, 8, 1, 0, 65543, 1, 0, 65545, 1, 0, 458759, 0, 0, 458758, 0, 0, 458760, 0, 0, 458761, 0, 0, 458757, 0, 0, 458756, 0, 0, 458762, 0, 0, 458763, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 196615, 0, 0, 196616, 0, 0, 196617, 0, 0, 196618, 0, 0, 196619, 0, 0, 65546, 0, 0, 131082, 0, 0, 131083, 0, 0, 65547, 0, 0, 196620, 0, 0, 196621, 0, 0, 196622, 0, 0, 196623, 0, 0, 458764, 0, 0, 589837, 1, 0, 589839, 1, 0, 524302, 1, 0, 458765, 1, 0, 458767, 1, 0, 458755, 1, 0, 458753, 1, 0, 524290, 1, 0, 589825, 1, 0, 589827, 1, 0, 393218, 1, 0, 327681, 1, 0, 327683, 1, 0, 262146, 1, 0, 196609, 1, 0, 196611, 1, 0, 262156, 0, 0, 262157, 0, 0, 262158, 0, 0, 262159, 0, 0, 262148, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 65552, 0, 0, 131088, 0, 0, 131087, 0, 0, 131086, 0, 0, 131085, 0, 0, 131084, 0, 0, 65548, 0, 0, 65549, 0, 0, 65550, 0, 0, 65551, 0, 0, 393224, 3, 65536, 393222, 3, 196608, 393226, 3, 196608, 655365, 3, 196608, 655362, 3, 196608, 655374, 3, 196608, 655371, 3, 196608, 131077, 3, 196608) script = ExtResource("2_n0xwr") top = true bottom = true diff --git a/scenes/v2/worldgen/roomsets/standard/small_fork.tscn b/scenes/v2/worldgen/roomsets/standard/small_fork.tscn index f3b4a1c..1af1452 100644 --- a/scenes/v2/worldgen/roomsets/standard/small_fork.tscn +++ b/scenes/v2/worldgen/roomsets/standard/small_fork.tscn @@ -6,7 +6,7 @@ [node name="SmallFork" type="TileMap"] tile_set = ExtResource("1_eu7wp") format = 2 -layer_0/tile_data = PackedInt32Array(65536, 0, 0, 131072, 0, 0, 458752, 0, 0, 524288, 0, 0, 131073, 0, 0, 524289, 0, 0, 65538, 0, 0, 131074, 0, 0, 458754, 0, 0, 524290, 0, 0, 65542, 0, 0, 131078, 0, 0, 458758, 0, 0, 524294, 0, 0, 131079, 0, 0, 524295, 0, 0, 65544, 0, 0, 131080, 0, 0, 458760, 0, 0, 524296, 0, 0, 0, 0, 0, 393216, 0, 0, 1, 0, 0, 393217, 0, 0, 2, 0, 0, 393218, 0, 0, 393219, 1, 0, 524291, 1, 0, 458756, 1, 0, 393221, 1, 0, 524293, 1, 0, 6, 0, 0, 393222, 0, 0, 7, 0, 0, 393223, 0, 0, 8, 0, 0, 393224, 0, 0, 4, 1, 0, 65539, 1, 0, 65541, 1, 0, 131076, 1, 0, 196611, 1, 0, 196613, 1, 0, 262148, 1, 0) +layer_0/tile_data = PackedInt32Array(65536, 0, 0, 131072, 0, 0, 458752, 0, 0, 524288, 0, 0, 131073, 0, 0, 524289, 0, 0, 65538, 0, 0, 131074, 0, 0, 458754, 0, 0, 524290, 0, 0, 65542, 0, 0, 131078, 0, 0, 458758, 0, 0, 524294, 0, 0, 131079, 0, 0, 524295, 0, 0, 65544, 0, 0, 131080, 0, 0, 458760, 0, 0, 524296, 0, 0, 0, 0, 0, 393216, 0, 0, 1, 0, 0, 393217, 0, 0, 2, 0, 0, 393218, 0, 0, 393219, 1, 0, 524291, 1, 0, 458756, 1, 0, 393221, 1, 0, 524293, 1, 0, 6, 0, 0, 393222, 0, 0, 7, 0, 0, 393223, 0, 0, 8, 0, 0, 393224, 0, 0, 4, 1, 0, 65539, 1, 0, 65541, 1, 0, 131076, 1, 0, 196611, 1, 0, 196613, 1, 0, 262148, 1, 0, 458753, 0, 0, 458759, 0, 0, 65537, 0, 0, 65543, 0, 0, 327687, 3, 65536, 327681, 3, 65536) script = ExtResource("2_lsa1k") left = true right = true diff --git a/scenes/v2/worldgen/roomsets/standard/small_room_down_right.tscn b/scenes/v2/worldgen/roomsets/standard/small_room_down_right.tscn index 199f153..ded72c3 100644 --- a/scenes/v2/worldgen/roomsets/standard/small_room_down_right.tscn +++ b/scenes/v2/worldgen/roomsets/standard/small_room_down_right.tscn @@ -6,7 +6,7 @@ [node name="SmallRoom1" type="TileMap"] tile_set = ExtResource("1_mja1s") format = 2 -layer_0/tile_data = PackedInt32Array(65536, 0, 0, 0, 0, 0, 131072, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 524291, 0, 0, 524298, 0, 0, 458762, 0, 0, 393226, 0, 0, 327690, 0, 0, 262154, 0, 0, 196618, 0, 0, 131082, 0, 0, 65546, 0, 0, 10, 0, 0, 524292, 1, 0, 524294, 1, 0, 458755, 0, 0, 458754, 0, 0, 458753, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 458759, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 458761, 0, 0, 458760, 0, 0, 393222, 1, 0) +layer_0/tile_data = PackedInt32Array(65536, 0, 0, 0, 0, 0, 131072, 0, 0, 393216, 0, 0, 458752, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 524291, 0, 0, 524298, 0, 0, 458762, 0, 0, 393226, 0, 0, 327690, 0, 0, 262154, 0, 0, 196618, 0, 0, 131082, 0, 0, 65546, 0, 0, 10, 0, 0, 524292, 1, 0, 524294, 1, 0, 458755, 0, 0, 458754, 0, 0, 458753, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 458759, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 458761, 0, 0, 458760, 0, 0, 393222, 1, 0, 327688, 3, 65536) script = ExtResource("2_0e88q") left = true bottom = true diff --git a/scenes/v2/worldgen/roomsets/standard/spawn_room.tscn b/scenes/v2/worldgen/roomsets/standard/spawn_room.tscn index 9d59b96..d67cef2 100644 --- a/scenes/v2/worldgen/roomsets/standard/spawn_room.tscn +++ b/scenes/v2/worldgen/roomsets/standard/spawn_room.tscn @@ -6,7 +6,7 @@ [node name="SpawnRoom" type="TileMap"] tile_set = ExtResource("1_bu30l") format = 2 -layer_0/tile_data = PackedInt32Array(65536, 0, 0, 0, 0, 0, 327680, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 327684, 0, 0, 327685, 0, 0, 5, 0, 0, 6, 0, 0, 65542, 0, 0, 327686, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 393216, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0) +layer_0/tile_data = PackedInt32Array(65536, 0, 0, 0, 0, 0, 327680, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 327684, 0, 0, 327685, 0, 0, 5, 0, 0, 6, 0, 0, 65542, 0, 0, 327686, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 393216, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 196611, 3, 131072) script = ExtResource("2_n3iuk") left = true right = true diff --git a/scripts/baddie.gd b/scripts/baddie.gd index 1c62c9e..0f41887 100644 --- a/scripts/baddie.gd +++ b/scripts/baddie.gd @@ -6,12 +6,6 @@ var HP: int = 8 @export var color_str: String = "ffff00" -func _ready(): - var tile_map: TileMap = get_node("%tile_map") - var tile_pos = tile_map.local_to_map(Vector2i(int(position.x), int(position.y))) - if(tile_map.get_cell_source_id(0, tile_pos) != -1): - push_error("Enemy placed at tile in use, freeing!") - queue_free() func take_damage(dmg): playAudio("Bomb_Drop.wav") diff --git a/scripts/basic_enemy.gd b/scripts/basic_enemy.gd index 9bda5ff..ae3d7d2 100644 --- a/scripts/basic_enemy.gd +++ b/scripts/basic_enemy.gd @@ -50,7 +50,7 @@ func take_damage(dmg): func update_angry(): if angry && global_position.distance_to(player.global_position) > angry_distance: angry = false - elif global_position.distance_to(player.global_position) < active_distance: + elif player and global_position.distance_to(player.global_position) < active_distance: angry = true if(TIMER.wait_time <= 0): TIMER.start(UPDATE_ANGRY_TIME) @@ -65,7 +65,7 @@ func _physics_process(_delta: float) -> void: if knockback > 0: motion.y -= knockback/2 - if(player.global_position.x > global_position.x): + if(player and player.global_position.x > global_position.x): motion.x -= knockback else: motion.x += knockback diff --git a/scripts/player.gd b/scripts/player.gd index b83a58a..805290a 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -155,7 +155,7 @@ func _movement_process(delta: float) -> void: if self.is_on_floor(): if Input.is_action_pressed("move_down"): - pass # lmanley: todo reimplement platforms + self.position.y += 1 else: self.jump() self.current_jumps = self.extra_jumps diff --git a/scripts/v2/creature.gd b/scripts/v2/creature.gd new file mode 100644 index 0000000..11cb23f --- /dev/null +++ b/scripts/v2/creature.gd @@ -0,0 +1,56 @@ +class_name Creature +extends Node + +signal damaged(amount) +signal healed(amount) +signal death() + +@export +var max_hp: int = 1 + +@export +var death_sound: AudioStream = null + +@export +var free_on_death: bool = true + +var hp: int : + get: + return hp + set(value): + var old_hp = hp + + hp = clampi(value, 0, max_hp) + + if hp < old_hp: + self.damaged.emit(old_hp - hp) + elif hp > old_hp: + self.healed.emit(hp - old_hp) + + if hp == 0: + self.death.emit() + +func _ready() -> void: + self.hp = self.max_hp + self.death.connect(self._creature_on_death) + +func take_damage(damage: int) -> void: + self.hp -= damage + +func heal(amount: int) -> void: + self.hp += amount + +func _creature_on_death() -> void: + + # Play a sound on creature death + if self.death_sound: + var audio_player = AudioStreamPlayer2D.new() + self.get_parent().add_child(audio_player) + audio_player.stream = self.death_sound + audio_player.bus = "Sound Effects" + audio_player.finished.connect(audio_player.queue_free) + audio_player.play() + + # Destroy on death + if self.free_on_death: + self.queue_free() diff --git a/scripts/v2/enemy.gd b/scripts/v2/enemy.gd new file mode 100644 index 0000000..45129c3 --- /dev/null +++ b/scripts/v2/enemy.gd @@ -0,0 +1,42 @@ +class_name Enemy +extends Creature + +enum State { + IDLE, + CHASE, + ATTACK +} + +@export +var state: State = State.IDLE + +@export_category("Parts") +@export +var animation_player: AnimationPlayer + +var _chase_target: Node2D +var _target_is_left: bool = false + +func _play_animation(animation: String) -> void: + if not animation_player: + return + + if not animation_player.has_animation(animation): + return + + if animation_player.is_playing() and animation_player.current_animation == animation: + return + + animation_player.play(animation) + +func _process(delta: float) -> void: + var animation_name = str(State.keys()[self.state]).to_lower() + self._play_animation(animation_name) + +func _physics_process(delta: float) -> void: + match self.state: + State.CHASE: + if not self._chase_target: + self.state = State.IDLE + + pass diff --git a/scripts/v2/world.gd b/scripts/v2/world.gd index f8c7478..ae51c30 100644 --- a/scripts/v2/world.gd +++ b/scripts/v2/world.gd @@ -8,8 +8,3 @@ var map: TileMap func _ready() -> void: self.generator.generate(map) - -func _process(_delta: float) -> void: - if Input.is_action_just_pressed("jump"): - map.clear() - self.generator.generate(map) diff --git a/scripts/v2/worldgen/standard/entity_marker.gd b/scripts/v2/worldgen/standard/entity_marker.gd new file mode 100644 index 0000000..33324ac --- /dev/null +++ b/scripts/v2/worldgen/standard/entity_marker.gd @@ -0,0 +1,65 @@ +class_name StandardEntityMarker +extends Node2D + +enum SPAWN_METHOD { + ALL, + FURTHEST, + ONCE, + NONE +} + +enum ENTITY_SELECTION_METHOD { + RANDOM, + POP +} + +@export_category("Entity Spawning") +@export +var marker_id: String + +@export +var entities: Array[PackedScene] = [] + +@export +var spawn_method: SPAWN_METHOD + +@export_range(0, 1.0) +var spawn_chance: float = 1.0 + +@export +var entity_selection_method: ENTITY_SELECTION_METHOD + +@export_category("Marker Debug") +@export +var debug_color: Color = Color.WHITE + +@export +var marker_size: int = 16 + +func _ready() -> void: + self.add_to_group("genv2:entity_marker") + + var sprite: Sprite2D = self.get_node_or_null("Sprite2D") + if not sprite: + sprite = Sprite2D.new() + sprite.texture = _get_debug_texture() + self.add_child(sprite) + +func _register(gen: StandardWorldGenerator) -> void: + if self.marker_id == "": + push_error("Marker ID is empty, this marker will not be used for spawning entities.") + return + gen._register_marker("genv2:entity_marker:%s" % self.marker_id, self) + +func _get_debug_texture() -> Texture2D: + var texture = GradientTexture2D.new() + + var gradient = Gradient.new() + gradient.colors = [self.debug_color] + + texture.gradient = gradient + + texture.width = self.marker_size + texture.height = self.marker_size + + return texture diff --git a/scripts/v2/worldgen/standard/room.gd b/scripts/v2/worldgen/standard/room.gd index a840df0..daf451d 100644 --- a/scripts/v2/worldgen/standard/room.gd +++ b/scripts/v2/worldgen/standard/room.gd @@ -62,8 +62,10 @@ func copy_to_map(map: TileMap) -> void: for x in range(0, self.room_size.x): for y in range(0, self.room_size.y): var tile = self.get_cell_source_id(TILEMAP_LAYER, Vector2i(x, y)) + var alt = self.get_cell_alternative_tile(TILEMAP_LAYER, Vector2i(x, y)) + if tile != -1: - map.set_cell(TILEMAP_LAYER, Vector2i(position.x + x, position.y + y), tile, Vector2i(0, 0)) + map.set_cell(TILEMAP_LAYER, Vector2i(position.x + x, position.y + y), tile, Vector2i(0, 0), alt) else: map.set_cell(TILEMAP_LAYER, Vector2i(position.x + x, position.y + y), -1, Vector2i(0, 0)) diff --git a/scripts/v2/worldgen/standard_generator.gd b/scripts/v2/worldgen/standard_generator.gd index 17bb222..937f0fd 100644 --- a/scripts/v2/worldgen/standard_generator.gd +++ b/scripts/v2/worldgen/standard_generator.gd @@ -20,6 +20,8 @@ var _rooms_blocking: Array[PackedScene] = [] var _progress_tracker: ProgressTracker +var _markers: Dictionary = {} + func _generate(map: TileMap) -> void: self._progress_tracker = ProgressTracker.new(1) @@ -32,6 +34,9 @@ func _generate(map: TileMap) -> void: # Create rooms self._create_rooms(map, init_room, self.max_room_path_length, _progress_tracker.next_step("Creating Rooms")) map.update_internals() + + self._spawn_entities(map, _progress_tracker.next_step("Spawning Entities")) + map.update_internals() func _sort_rooms(step_tracker: ProgressStepTracker) -> void: step_tracker.complete.call_deferred() @@ -163,5 +168,95 @@ func _get_rooms(exit: Vector2i) -> Array[PackedScene]: push_error("Invalid exit: " + str(exit)) return [] +func _register_marker(group: String, marker: Node2D) -> void: + if not group in self._markers: + self._markers[group] = [marker] + else: + self._markers[group].append(marker) + +func _spawn_entities(map: TileMap, step_tracker: ProgressStepTracker) -> void: + var tree = map.get_tree() + + # Register entity markers + for entity_marker in tree.get_nodes_in_group("genv2:entity_marker"): + if entity_marker is StandardEntityMarker: + entity_marker._register(self) + + for marker_id in self._markers: + var sample_marker: StandardEntityMarker = self._markers[marker_id][0] + + match sample_marker.spawn_method: + StandardEntityMarker.SPAWN_METHOD.ALL: + for marker in self._markers[marker_id]: + map.erase_cell.call_deferred(0, map.local_to_map(marker.position)) + + var packed_entity: PackedScene = _select_entity(marker.entity_selection_method, marker.entities) + if packed_entity == null: + continue + + var entity: Node2D = packed_entity.instantiate() + entity.position = marker.position + map.add_child(entity) + StandardEntityMarker.SPAWN_METHOD.FURTHEST: + var furthest_marker: StandardEntityMarker = self._markers[marker_id].pop_back() + var furthest_distance: float = furthest_marker.position.distance_to(Vector2.ZERO) + + # Calculate furthest marker and destroy others + for marker in self._markers[marker_id]: + var calc_distance: float = marker.position.distance_to(Vector2.ZERO) + if calc_distance > furthest_distance: + map.erase_cell(0, map.local_to_map(furthest_marker.position)) + furthest_marker = marker + furthest_distance = calc_distance + else: + map.erase_cell(0, map.local_to_map(marker.position)) + + # Erase furthest marker + map.erase_cell.call_deferred(0, map.local_to_map(furthest_marker.position)) + + # Get entity + var packed_entity: PackedScene = _select_entity(furthest_marker.entity_selection_method, furthest_marker.entities) + if packed_entity == null: + continue + + var entity: Node2D = packed_entity.instantiate() + entity.position = furthest_marker.position + map.add_child(entity) + + + StandardEntityMarker.SPAWN_METHOD.ONCE: + var i = randi() % len(self._markers[marker_id]) + var marker = self._markers[marker_id][i] + + var packed_entity: PackedScene = _select_entity(marker.entity_selection_method, marker.entities) + if packed_entity != null: + var entity: Node2D = packed_entity.instantiate() + entity.position = marker.position + map.add_child(entity) + + for _marker in self._markers[marker_id]: + map.erase_cell(0, map.local_to_map(_marker.position)) + + StandardEntityMarker.SPAWN_METHOD.NONE: + for marker in self._markers[marker_id]: + map.erase_cell(0, map.local_to_map(marker.position)) + _: + push_error("Invalid spawning method!") + continue + +func _select_entity(mode: StandardEntityMarker.ENTITY_SELECTION_METHOD, entities: Array) -> PackedScene: + if len(entities) == 0: + return null + + match mode: + StandardEntityMarker.ENTITY_SELECTION_METHOD.RANDOM: + var i = randi() % len(entities) + return entities[i] + StandardEntityMarker.ENTITY_SELECTION_METHOD.POP: + var i = randi() % len(entities) + return entities.pop_at(i) + + return null + func _get_progress_tracker() -> ProgressTracker: return self._progress_tracker