parent
f2648f6c3c
commit
90500c2ee1
@ -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 |
||||||
|
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("..") |
||||||
Loading…
Reference in new issue