Update flower entity to spawn snails based on game state.

- Added Snail entity with states for eating and sleeping.
- Modified Flowers script to handle snail spawning logic.
This commit is contained in:
Dan 2024-05-14 14:51:01 +01:00
parent 9988ee23de
commit 908f834181
8 changed files with 143 additions and 2 deletions

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=8 format=3 uid="uid://bme541qdw7nai"]
[gd_scene load_steps=9 format=3 uid="uid://bme541qdw7nai"]
[ext_resource type="Script" path="res://entities/scripts/flowers.gd" id="1_72iub"]
[ext_resource type="PackedScene" uid="uid://rnykx61eqxyk" path="res://scenes/decor/flower_1.tscn" id="1_biusc"]
[ext_resource type="PackedScene" uid="uid://b7quc1hxenh5p" path="res://scenes/decor/flower_2.tscn" id="2_k5hnf"]
[ext_resource type="Texture2D" uid="uid://dhf4dessaw5p5" path="res://resources/particles/twirl_01.png" id="3_xruiv"]
[ext_resource type="PackedScene" uid="uid://bnwvtlsvxjmel" path="res://entities/Snail.tscn" id="5_5uu7l"]
[sub_resource type="CircleShape2D" id="CircleShape2D_1tovu"]
radius = 142.316
@ -123,3 +124,5 @@ libraries = {
"": SubResource("AnimationLibrary_qs4pr")
}
autoplay = "Highlight"
[node name="Snail" parent="." instance=ExtResource("5_5uu7l")]

24
entities/Snail.tscn Normal file
View file

@ -0,0 +1,24 @@
[gd_scene load_steps=5 format=3 uid="uid://bnwvtlsvxjmel"]
[ext_resource type="Script" path="res://entities/scripts/snail.gd" id="1_lkvd1"]
[ext_resource type="Script" path="res://entities/scripts/finite_state_machine.gd" id="1_tejvt"]
[ext_resource type="Script" path="res://entities/snail/states/snail_sleeping.gd" id="3_wnrnl"]
[ext_resource type="Script" path="res://entities/snail/states/snail_eating.gd" id="4_1abwi"]
[node name="Snail" type="Sprite2D"]
script = ExtResource("1_lkvd1")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
[node name="Polygon2D" type="Polygon2D" parent="."]
polygon = PackedVector2Array(-8, -8, 4, -11, 10, 5, -7, 9, -25, 8, -22, 0, -11, 0)
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("initial_state")]
script = ExtResource("1_tejvt")
initial_state = NodePath("Sleeping")
[node name="Sleeping" type="Node" parent="StateMachine"]
script = ExtResource("3_wnrnl")
[node name="Eating" type="Node" parent="StateMachine"]
script = ExtResource("4_1abwi")

View file

@ -3,8 +3,40 @@ class_name Flowers
@onready var outline = $AreaHighlight
@export var health : int = 100
var spawn_snails : bool = false
@onready var spawn_area = $FlowerCollectionArea/CollisionShape2D
@onready var snail = $Snail
func _ready():
hide_outline()
## Check if this level is spawning snails or not
if GameState.spawn_snails:
Log.pr("Going to be spawning snails!")
spawn_snails = true
Log.pr(get_random_snail_spawn())
snail.global_position = get_random_snail_spawn()
func show_outline():
outline.visible = true
func hide_outline():
outline.visible = false
func get_random_snail_spawn():
var circle_radius = spawn_area.shape.radius
var random_angle = randf_range(0, TAU)
var x = circle_radius * cos(random_angle)
var y = circle_radius * sin(random_angle)
var circle_center = spawn_area.global_position
var random_point = circle_center + Vector2(x, y)
return random_point

View file

@ -0,0 +1,4 @@
extends Sprite2D
class_name Snail
var eating : bool = false

View file

@ -0,0 +1,18 @@
extends State
class_name SnailEating
@onready var snail = get_parent().get_parent() as Snail # I think this is bad but I dont care it works
func enter(_msg := {}):
Log.pr("I am a snail...")
snail.eating = true
func exit():
snail.eating = false
func update(_delta : float):
pass
func physics_update(_delta : float) -> void:
pass

View file

@ -0,0 +1,17 @@
extends State
class_name SnailSleeping
@onready var snail = get_parent().get_parent() as Snail # I think this is bad but I dont care it works
func enter(_msg := {}):
Log.pr("I am a snail asleep...")
func exit():
pass
func update(_delta : float):
pass
func physics_update(_delta : float) -> void:
pass

View file

@ -98,3 +98,43 @@ Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorActi
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
Remove-Item -Recurse -Force '{temp_dir}'"
[preset.2]
name="Linux/X11"
platform="Linux/X11"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="build/linux/PollenNotIncluded.x86_64"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
[preset.2.options]
custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/bptc=true
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false
binary_format/architecture="x86_64"
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="#!/usr/bin/env bash
export DISPLAY=:0
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
\"{temp_dir}/{exe_name}\" {cmd_args}"
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
rm -rf \"{temp_dir}\""

View file

@ -13,6 +13,9 @@ var level_started : bool = false
var level_complete : bool = false
var game_over : bool = false
## Game Rules
var spawn_snails : bool = false
var gathered_nectar : int = 0 :
get:
return gathered_nectar