Godot Version
4.3
Question
Hi there, this is my first time posting in the Godot forum. I’m trying to create a sort of idle game where you take care of a pet. However, I’m running into an issue where I’m not sure how to design and implement an mechanic in Godot.
The mechanic I’m trying to create is a mood changing system. Every x amount of time, the pet’s mood will randomly change between a few moods: happy, hungry, dirty, bored, or sad. The player can also preemptively do actions (Feed, Clean, or Play) to keep the pet happy for longer.
Here’s what I want to happen:
- If the pet’s mood is “happy” and the player decides to Feed, Clean, or Play with the pet, the timer to randomly change the pet’s mood (
mood_timer
) increases by 1 minute if it is already running. - If the pet’s mood changes from “happy”, it must stay in that new mood (hungry, dirty, or bored) until the player takes a respective action to clear the mood.
- If the pet’s happiness meets a criteria (0 out of 3 happiness points), then the pet’s mood is sad until the player makes actions to increase the pet’s happiness until it is no longer sad (maybe Play, in this instance?).
So far, the pet entity only includes the happiness
stat, but I’m wondering if I also need to implement hunger
and cleanliness
stats too to make this mechanic work.
Anyway, the pet entity has a simple state machine (it’s implemented by nodes and GDScript) to make it randomly idle on screen and then wander around. I created a new state, Mood, to keep track of its mood, but I’m not sure if this is the right way to implement the system I have in mind. Here’s a screenshot of the Nodes used for the pet entity:
Do I create a new state machine for moods? How would that look like? Could I reuse my initial state machine node to do this?
Just in case this is needed, here is the code for the state machine I have so far (I followed Bitlytic’s fantastic walkthrough on state machines):
extends Node
class_name StateMachine
@export var initial_state: State
var current_state: State
var states: Dictionary = {}
func _ready():
for state: State in get_children():
states[state.name.to_lower()] = state
state.change_to.connect(on_state_change)
if initial_state:
current_state = initial_state
current_state.enter()
func _process(delta):
if current_state:
current_state.process_state(delta)
func _physics_process(delta):
if current_state:
current_state.physics_process_state(delta)
func on_state_change(state: State, new_state_name: String):
if state != current_state:
return
var new_state = states.get(new_state_name.to_lower())
if !new_state:
return
if current_state:
current_state.exit()
new_state.enter()
current_state = new_state