diff --git a/evolve-die-repeat/addons/godot_vim/godot_vim.gd b/evolve-die-repeat/addons/godot_vim/godot_vim.gd new file mode 100644 index 0000000..03deda8 --- /dev/null +++ b/evolve-die-repeat/addons/godot_vim/godot_vim.gd @@ -0,0 +1,8 @@ +@tool +extends GodotVimPlugin + +func _enter_tree(): + pass + +func _exit_tree(): + pass diff --git a/evolve-die-repeat/addons/godot_vim/godot_vim.gd.uid b/evolve-die-repeat/addons/godot_vim/godot_vim.gd.uid new file mode 100644 index 0000000..19e6468 --- /dev/null +++ b/evolve-die-repeat/addons/godot_vim/godot_vim.gd.uid @@ -0,0 +1 @@ +uid://c0i5fl58y2apo diff --git a/evolve-die-repeat/addons/godot_vim/godot_vim.gdextension b/evolve-die-repeat/addons/godot_vim/godot_vim.gdextension new file mode 100644 index 0000000..7c0f67b --- /dev/null +++ b/evolve-die-repeat/addons/godot_vim/godot_vim.gdextension @@ -0,0 +1,12 @@ +[configuration] +entry_symbol = "gdext_rust_init" +compatibility_minimum = "4.5" +reloadable = true + +[libraries] +linux.debug.x86_64 = "res://addons/godot_vim/bin/libgodot_vim.so" +linux.release.x86_64 = "res://addons/godot_vim/bin/libgodot_vim.so" +windows.debug.x86_64 = "res://addons/godot_vim/bin/godot_vim.dll" +windows.release.x86_64 = "res://addons/godot_vim/bin/godot_vim.dll" +macos.debug.universal = "res://addons/godot_vim/bin/libgodot_vim.dylib" +macos.release.universal = "res://addons/godot_vim/bin/libgodot_vim.dylib" diff --git a/evolve-die-repeat/addons/godot_vim/godot_vim.gdextension.uid b/evolve-die-repeat/addons/godot_vim/godot_vim.gdextension.uid new file mode 100644 index 0000000..a25656b --- /dev/null +++ b/evolve-die-repeat/addons/godot_vim/godot_vim.gdextension.uid @@ -0,0 +1 @@ +uid://cgm1ycwc1a0ll diff --git a/evolve-die-repeat/addons/godot_vim/plugin.cfg b/evolve-die-repeat/addons/godot_vim/plugin.cfg new file mode 100644 index 0000000..715349c --- /dev/null +++ b/evolve-die-repeat/addons/godot_vim/plugin.cfg @@ -0,0 +1,6 @@ +[plugin] +name="GodotVim" +description="Vim emulation for Godot's script editor" +author="hmdfrds" +version="0.1.4" +script="godot_vim.gd" diff --git a/evolve-die-repeat/game_manager.gd b/evolve-die-repeat/game_manager.gd index 2366d1f..51c239f 100644 --- a/evolve-die-repeat/game_manager.gd +++ b/evolve-die-repeat/game_manager.gd @@ -2,6 +2,7 @@ extends Node var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason) var viewport_size +@onready var extent: Rect2 = get_viewport().get_visible_rect() func _ready() -> void: viewport_size = get_viewport().get_visible_rect().size diff --git a/evolve-die-repeat/molecular/assets/background/dirt-specs.png b/evolve-die-repeat/molecular/assets/background/dirt-specs.png deleted file mode 100644 index 28a28dd..0000000 Binary files a/evolve-die-repeat/molecular/assets/background/dirt-specs.png and /dev/null differ diff --git a/evolve-die-repeat/molecular/assets/background/dirt-specs.png.import b/evolve-die-repeat/molecular/assets/background/dirt-specs.png.import deleted file mode 100644 index 830b775..0000000 --- a/evolve-die-repeat/molecular/assets/background/dirt-specs.png.import +++ /dev/null @@ -1,40 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://bfjf6dxvbq5cj" -path="res://.godot/imported/dirt-specs.png-ef6f8fd578fedf9d185ca3625a87c7c3.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://molecular/assets/background/dirt-specs.png" -dest_files=["res://.godot/imported/dirt-specs.png-ef6f8fd578fedf9d185ca3625a87c7c3.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/uastc_level=0 -compress/rdo_quality_loss=0.0 -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/channel_remap/red=0 -process/channel_remap/green=1 -process/channel_remap/blue=2 -process/channel_remap/alpha=3 -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/evolve-die-repeat/molecular/molecular_player.gd b/evolve-die-repeat/molecular/molecular_player.gd index e1e6461..534f636 100644 --- a/evolve-die-repeat/molecular/molecular_player.gd +++ b/evolve-die-repeat/molecular/molecular_player.gd @@ -19,8 +19,6 @@ func _ready() -> void: attack_area.monitoring = false # no collision until attacking attack_timer.wait_time = attack_duration attack_cooldown_timer.wait_time = attack_cooldown_duration - - func _process(delta): velocity = Vector2.ZERO diff --git a/evolve-die-repeat/molecular/molecular_stage.tscn b/evolve-die-repeat/molecular/molecular_stage.tscn index 3ae908b..15636f5 100644 --- a/evolve-die-repeat/molecular/molecular_stage.tscn +++ b/evolve-die-repeat/molecular/molecular_stage.tscn @@ -14,7 +14,7 @@ tile_data = PackedInt32Array(0, 65536, 2, 65536, 65536, 3, 1, 131072, 2, 65537, tile_data = PackedInt32Array(0, 196608, 2, 65536, 196608, 3, 1, 262144, 2, 65537, 262144, 3) [sub_resource type="TileMapPattern" id="TileMapPattern_mys4o"] -tile_data = PackedInt32Array(0, 196608, 0, 65536, 196608, 1, 1, 262144, 0, 65537, 262144, 1) +tile_data = PackedInt32Array(0, 196608, 0, 65536, 196608, 1) [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_b1jr0"] resource_name = "Background tileset" @@ -76,6 +76,7 @@ tile_map_data = PackedByteArray("AAAAAAAAAAAAAAIAAAAAAAEAAAAAAAIAAAAAAAIAAAAAAAI tile_set = SubResource("TileSet_mys4o") [node name="ParallaxNear" type="Parallax2D" parent="Background"] +z_index = 5 scroll_scale = Vector2(0.9, 0.9) repeat_times = 7 diff --git a/evolve-die-repeat/molecular/nucleotide_prey.gd b/evolve-die-repeat/molecular/nucleotide_prey.gd index 732c738..f1ca09c 100644 --- a/evolve-die-repeat/molecular/nucleotide_prey.gd +++ b/evolve-die-repeat/molecular/nucleotide_prey.gd @@ -11,8 +11,7 @@ var mirrorSprite3: Node2D # Called when the node enters the scene tree for the first time. func _ready() -> void: health = maxHealth - sprite.animation = "Healthy" - sprite.play() + sprite.play("Healthy") mirrorSprite1 = sprite.duplicate() mirrorSprite2 = sprite.duplicate() diff --git a/evolve-die-repeat/molecular/nucleotide_prey.tscn b/evolve-die-repeat/molecular/nucleotide_prey.tscn index c3bbedc..e40fea2 100644 --- a/evolve-die-repeat/molecular/nucleotide_prey.tscn +++ b/evolve-die-repeat/molecular/nucleotide_prey.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://c3iw2v3x6ngrb"] +[gd_scene load_steps=12 format=3 uid="uid://c3iw2v3x6ngrb"] [ext_resource type="PackedScene" uid="uid://bvsdg1v3ksixy" path="res://shared/npc/prey2D.tscn" id="1_qvulj"] [ext_resource type="Script" uid="uid://bgossk6xo31gi" path="res://molecular/nucleotide_prey.gd" id="2_0227s"] @@ -8,11 +8,13 @@ [ext_resource type="Texture2D" uid="uid://uy28y3mkk6nt" path="res://molecular/assets/prey/prey-healthy-frame1.png" id="5_ae5nf"] [ext_resource type="Texture2D" uid="uid://btnyajci8ptb2" path="res://molecular/assets/prey/prey-injured-frame0.png" id="6_0f87h"] [ext_resource type="Texture2D" uid="uid://bqll8ge4cr2uf" path="res://molecular/assets/prey/prey-injured-frame1.png" id="7_w7inl"] +[ext_resource type="Script" uid="uid://c7o7sp02u0wkv" path="res://molecular/nucleotide_prey_state.gd" id="9_guu3v"] +[ext_resource type="Script" uid="uid://ubcu8fdfxxj1" path="res://molecular/nucleotide_prey_foraging.gd" id="10_rgguv"] [sub_resource type="SpriteFrames" id="SpriteFrames_66x8p"] animations = [{ "frames": [{ -"duration": 20.0, +"duration": 1.0, "texture": ExtResource("2_lkj7f") }, { "duration": 20.0, @@ -23,7 +25,7 @@ animations = [{ "speed": 1.0 }, { "frames": [{ -"duration": 20.0, +"duration": 1.0, "texture": ExtResource("4_ee1gb") }, { "duration": 20.0, @@ -34,7 +36,7 @@ animations = [{ "speed": 1.0 }, { "frames": [{ -"duration": 20.0, +"duration": 1.0, "texture": ExtResource("6_0f87h") }, { "duration": 20.0, @@ -54,4 +56,17 @@ maxHealth = 20 [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="0"] scale = Vector2(0.1, 0.1) sprite_frames = SubResource("SpriteFrames_66x8p") -animation = &"Dying" +animation = &"Injured" + +[node name="State" type="Node" parent="." index="2"] +script = ExtResource("9_guu3v") +metadata/_custom_type_script = "uid://co2xp7gauamql" + +[node name="Foraging" type="Node" parent="State" index="0"] +script = ExtResource("10_rgguv") +metadata/_custom_type_script = "uid://c7o7sp02u0wkv" + +[node name="Timer" type="Timer" parent="State/Foraging" index="0"] +one_shot = true + +[connection signal="timeout" from="State/Foraging/Timer" to="State/Foraging" method="_on_timer_timeout"] diff --git a/evolve-die-repeat/molecular/nucleotide_prey_foraging.gd b/evolve-die-repeat/molecular/nucleotide_prey_foraging.gd new file mode 100644 index 0000000..11f1757 --- /dev/null +++ b/evolve-die-repeat/molecular/nucleotide_prey_foraging.gd @@ -0,0 +1,17 @@ +extends NucleotidePreyState + +@onready var timer = $Timer +var dir: float = 0.0 + +func enter(previous_state_path: String, data := {}) -> void: + timer.start(randi() % 5) + dir = randi() % 360 + +func physics_update(_delta: float) -> void: + # TODO: move in direction of dir + pass + + +func _on_timer_timeout() -> void: + dir = randi() % 360 + timer.start(randi() % 5) diff --git a/evolve-die-repeat/molecular/nucleotide_prey_foraging.gd.uid b/evolve-die-repeat/molecular/nucleotide_prey_foraging.gd.uid new file mode 100644 index 0000000..a7e2045 --- /dev/null +++ b/evolve-die-repeat/molecular/nucleotide_prey_foraging.gd.uid @@ -0,0 +1 @@ +uid://ubcu8fdfxxj1 diff --git a/evolve-die-repeat/molecular/nucleotide_prey_state.gd b/evolve-die-repeat/molecular/nucleotide_prey_state.gd new file mode 100644 index 0000000..f3140c5 --- /dev/null +++ b/evolve-die-repeat/molecular/nucleotide_prey_state.gd @@ -0,0 +1,6 @@ +class_name NucleotidePreyState extends State + +enum State {IDLE, FORAGING, FEEDING, FLEEING} + +func _ready() -> void: + await owner.ready diff --git a/evolve-die-repeat/molecular/nucleotide_prey_state.gd.uid b/evolve-die-repeat/molecular/nucleotide_prey_state.gd.uid new file mode 100644 index 0000000..55b2c6a --- /dev/null +++ b/evolve-die-repeat/molecular/nucleotide_prey_state.gd.uid @@ -0,0 +1 @@ +uid://c7o7sp02u0wkv diff --git a/evolve-die-repeat/molecular/prey_manager.gd b/evolve-die-repeat/molecular/prey_manager.gd index 8e6b926..14fe0a4 100644 --- a/evolve-die-repeat/molecular/prey_manager.gd +++ b/evolve-die-repeat/molecular/prey_manager.gd @@ -1,10 +1,11 @@ extends SpawnManager2D -@export var cam: Camera2D +#@export var cam: Camera2D # Called when the node enters the scene tree for the first time. func _ready() -> void: - spawnRange = cam.get_viewport_rect() + spawnRange = GameManager.extent + #spawnRange = cam.get_viewport_rect() _spawn_minimum() diff --git a/evolve-die-repeat/project.godot b/evolve-die-repeat/project.godot index 4cbd70a..b4ca26f 100644 --- a/evolve-die-repeat/project.godot +++ b/evolve-die-repeat/project.godot @@ -19,6 +19,10 @@ config/icon="res://icon.svg" GameManager="*res://game_manager.gd" +[editor_plugins] + +enabled=PackedStringArray("res://addons/godot_vim/plugin.cfg") + [global_group] player="All scenes that constitute players should be added here." diff --git a/evolve-die-repeat/shared/npc/prey2D.gd b/evolve-die-repeat/shared/npc/prey2D.gd index 84a8394..1013af6 100644 --- a/evolve-die-repeat/shared/npc/prey2D.gd +++ b/evolve-die-repeat/shared/npc/prey2D.gd @@ -1,6 +1,10 @@ extends NPC2D class_name AbstractPrey2D +enum States {IDLE, FORAGING, FLEEING} +var state = States.IDLE + + # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. diff --git a/evolve-die-repeat/shared/npc/spawn_manager_2d.gd b/evolve-die-repeat/shared/npc/spawn_manager_2d.gd index 4bf6f5b..2ad5269 100644 --- a/evolve-die-repeat/shared/npc/spawn_manager_2d.gd +++ b/evolve-die-repeat/shared/npc/spawn_manager_2d.gd @@ -1,11 +1,10 @@ extends Node class_name SpawnManager2D -#var scene = preload("res://molecular/nucleotide_prey.tscn") @export var scene: PackedScene @export var minCount = 1 @export var maxCount = 2 -@export var spawnRange: Rect2 +@export var spawnRange: Rect2 = Rect2(0, 0, 0, 0) var _currentCount = 0 diff --git a/evolve-die-repeat/shared/state.gd b/evolve-die-repeat/shared/state.gd new file mode 100644 index 0000000..067ff24 --- /dev/null +++ b/evolve-die-repeat/shared/state.gd @@ -0,0 +1,24 @@ +class_name State extends Node + +# Emits on state completion +signal finished(next_state_path: String, data: Dictionary) + +# Called by StateMachine on unhandled input +func handle_input(_event: InputEvent) -> void: + pass + +# Main update loop +func update(_delta: float) -> void: + pass + +# Physics update loop +func physics_update(_delta: float) -> void: + pass + +# Called by StateMachine on state change. Data contains arbitrary data to initialize state. +func enter(previous_state_path: String, data := {}) -> void: + pass + +# Called by StateMachine before state change. Should be used for cleanup. +func exit() -> void: + pass diff --git a/evolve-die-repeat/shared/state.gd.uid b/evolve-die-repeat/shared/state.gd.uid new file mode 100644 index 0000000..5986cde --- /dev/null +++ b/evolve-die-repeat/shared/state.gd.uid @@ -0,0 +1 @@ +uid://co2xp7gauamql diff --git a/evolve-die-repeat/shared/state_machine.gd b/evolve-die-repeat/shared/state_machine.gd new file mode 100644 index 0000000..33fd0f2 --- /dev/null +++ b/evolve-die-repeat/shared/state_machine.gd @@ -0,0 +1,39 @@ +class_name StateMachine extends Node + +@export var initial_state: State = null + +# use first child as 'active' state +@onready var state: State = (func get_initial_state() -> State: + return initial_state if initial_state != null else get_child(0) +).call() + +# Connect states on ready, then wait. +func _ready() -> void: + for node: State in find_children("*", "State"): + node.finished.connect(_transition_to_next_state) + + await owner.ready + state.enter("") + +# pass unhandled input to state. +func _unhandled_input(event: InputEvent) -> void: + state.handle_input(event) + +# Pass process tick to state. +func _process(delta: float) -> void: + state.update(delta) + +# Pass physics tick to state. +func _physics_process(delta: float) -> void: + state.physics_update(delta) + +# Transition to next state +func _transition_to_next_state(target_path: String, data: Dictionary = {}) -> void: + if not has_node(target_path): + printerr(owner.name + ": Trying to transition to state " + target_path + ", which does not exist.") + return + + var previous_state_path := state.name + state.exit() + state = get_node(target_path) + state.enter(previous_state_path, data) diff --git a/evolve-die-repeat/shared/state_machine.gd.uid b/evolve-die-repeat/shared/state_machine.gd.uid new file mode 100644 index 0000000..a5d7b40 --- /dev/null +++ b/evolve-die-repeat/shared/state_machine.gd.uid @@ -0,0 +1 @@ +uid://ck7k8ht54snsy