diff --git a/nodes/npc/npc.gd b/nodes/npc/npc.gd new file mode 100644 index 0000000..7c0a64a --- /dev/null +++ b/nodes/npc/npc.gd @@ -0,0 +1,35 @@ +extends CharacterBody2D + +class_name Npc + +const SPEED = 100 +const MINIMUM_STATE_DURATION = 3 + +const STATES = ['panic'] + +var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") +var direction = 0 + +func _ready(): + pick_new_direction() + $fsm.set_states(STATES) + +func panic_state(delta): + if is_on_wall(): + direction *= -1 + + var should_update = ( + $fsm.state_duration >= MINIMUM_STATE_DURATION + && ceil($fsm.state_duration) % 2 == (randi() %2) + ) + + if should_update: + pick_new_direction() + $fsm.state_duration = 0 + + velocity.x = direction + velocity.y += gravity * delta + move_and_slide() + +func pick_new_direction(): + direction = [1,-1][randi_range(0,1)] * SPEED diff --git a/nodes/npc/npc.png b/nodes/npc/npc.png new file mode 100644 index 0000000..8b30563 Binary files /dev/null and b/nodes/npc/npc.png differ diff --git a/nodes/npc/npc.png.import b/nodes/npc/npc.png.import new file mode 100644 index 0000000..6937127 --- /dev/null +++ b/nodes/npc/npc.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bm258xfujps7e" +path="res://.godot/imported/npc.png-6ab5db0d3e525d0fae0b471428195d99.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://nodes/npc/npc.png" +dest_files=["res://.godot/imported/npc.png-6ab5db0d3e525d0fae0b471428195d99.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/nodes/npc/npc.tscn b/nodes/npc/npc.tscn new file mode 100644 index 0000000..093a1de --- /dev/null +++ b/nodes/npc/npc.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=5 format=3 uid="uid://dvx48q5ecyxjs"] + +[ext_resource type="Script" path="res://nodes/npc/npc.gd" id="1_38jh5"] +[ext_resource type="Texture2D" uid="uid://bm258xfujps7e" path="res://nodes/npc/npc.png" id="1_hgsqd"] +[ext_resource type="Script" path="res://scripts/ia/fsm.gd" id="3_vhp64"] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_f223n"] +radius = 4.0 +height = 14.0 + +[node name="npc" type="CharacterBody2D"] +script = ExtResource("1_38jh5") + +[node name="shape" type="CollisionShape2D" parent="."] +rotation = 1.5708 +shape = SubResource("CapsuleShape2D_f223n") + +[node name="sprite" type="Sprite2D" parent="."] +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_hgsqd") + +[node name="fsm" type="Node2D" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("3_vhp64") +root = NodePath("..") diff --git a/project.godot b/project.godot index 076b15d..91baaf6 100644 --- a/project.godot +++ b/project.godot @@ -10,7 +10,7 @@ config_version=5 [application] -config/name="LD54" +config/name="Ant Underwater Odyssey" run/main_scene="res://scenes/main_menu.tscn" config/features=PackedStringArray("4.1", "GL Compatibility") config/icon="res://icon.svg" diff --git a/scenes/poc.tscn b/scenes/poc.tscn index 8ef95af..9e1cbd5 100644 --- a/scenes/poc.tscn +++ b/scenes/poc.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=16 format=3 uid="uid://ce8ov6npvl27w"] +[gd_scene load_steps=17 format=3 uid="uid://ce8ov6npvl27w"] [ext_resource type="Texture2D" uid="uid://cfq8pma4bpgq" path="res://assets/tilesets/cave_tileset.png" id="1_vofrt"] [ext_resource type="PackedScene" uid="uid://c5rmt3jeffjx7" path="res://nodes/player/player.tscn" id="2_gxv3v"] [ext_resource type="Texture2D" uid="uid://ccqiabs4p3ryl" path="res://assets/placeholders/map.png" id="3_aeud1"] [ext_resource type="Script" path="res://scripts/gameplay/rising_level.gd" id="4_ts3u4"] +[ext_resource type="PackedScene" uid="uid://dvx48q5ecyxjs" path="res://nodes/npc/npc.tscn" id="5_0u2ly"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_3t6yd"] vertices = PackedVector2Array(0, -16, 16, -16, 16, 16, 0, 16) @@ -240,8 +241,28 @@ position = Vector2(1136, 1968) position = Vector2(1736, 3056) monitorable = false script = ExtResource("4_ts3u4") -RISING_SPEED = 0 +RISING_SPEED = 5 [node name="shape" type="CollisionShape2D" parent="water_level"] position = Vector2(2.08165e-12, 2.08165e-12) shape = SubResource("RectangleShape2D_qoxeb") + +[node name="npcs" type="Node2D" parent="."] + +[node name="npc" parent="npcs" instance=ExtResource("5_0u2ly")] +position = Vector2(1320, 1976) + +[node name="npc2" parent="npcs" instance=ExtResource("5_0u2ly")] +position = Vector2(1360, 1976) + +[node name="npc3" parent="npcs" instance=ExtResource("5_0u2ly")] +position = Vector2(1432, 1992) + +[node name="npc4" parent="npcs" instance=ExtResource("5_0u2ly")] +position = Vector2(1496, 1992) + +[node name="npc5" parent="npcs" instance=ExtResource("5_0u2ly")] +position = Vector2(1552, 1992) + +[node name="npc6" parent="npcs" instance=ExtResource("5_0u2ly")] +position = Vector2(1256, 1968)