Compare commits

...

3 Commits

Author SHA1 Message Date
Ervan Lefevre 90500c2ee1 Adds a minimalist AI for NPCs 2 years ago
Ervan Lefevre f2648f6c3c Adds a state_duration to FSM.gd 2 years ago
Ervan Lefevre a673356992 🐛 Fixes missing gravity on death state 2 years ago
  1. 35
      nodes/npc/npc.gd
  2. BIN
      nodes/npc/npc.png
  3. 34
      nodes/npc/npc.png.import
  4. 24
      nodes/npc/npc.tscn
  5. 5
      nodes/player/player.gd
  6. 2
      nodes/player/player.tscn
  7. 2
      project.godot
  8. 25
      scenes/poc.tscn
  9. 10
      scripts/ia/fsm.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -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

@ -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("..")

@ -16,7 +16,7 @@ const STATES= [
var use_gravity = {
"climb": false,
"die": false,
"die": true,
"idle": true,
"jump": true,
"spawn": true,
@ -30,7 +30,7 @@ func _ready():
$fsm.set_states(STATES)
add_to_group("player")
func _enter_spawn():
func on_enter_spawn_state():
$fsm.set_next_state("idle")
func on_enter_idle_state():
@ -59,7 +59,6 @@ func walk_state(_delta):
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
$fsm.set_next_state("jump")
# detect collision with wall or ceiling to enter climb state
if is_on_wall() or (Input.is_action_pressed('ui_up') && is_on_ceiling()):
velocity.y = 0
$fsm.set_next_state("climb")

@ -24,4 +24,4 @@ shape = SubResource("CapsuleShape2D_w17ly")
metadata/_edit_group_ = true
[node name="camera" type="Camera2D" parent="."]
zoom = Vector2(4, 4)
zoom = Vector2(5, 5)

@ -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"

@ -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)

@ -8,17 +8,20 @@ var states = ['idle']
var current_state = null
var previous_state = null
var next_state = null
var state_duration = 0
func set_states(new_states):
self.states = new_states
func _ready():
pass
func _physics_process(delta):
if current_state == null:
next_state = states[0]
_transition()
return
_transition()
func _physics_process(delta):
if "before_state" in root:
root.call("before_state", delta)
@ -43,6 +46,7 @@ func _transition():
if on_exit_state_method in root:
root.call(on_exit_state_method)
state_duration = 0
var on_enter_state_method = "on_enter_" + current_state + "_state"
if on_enter_state_method in root:
root.call(on_enter_state_method)

Loading…
Cancel
Save