Magnet Agent’s gameplay is a 2D puzzle game based on Physics and Magnetic interaction.
The player controls Magnet Boy who interacts with other magnets in the environment using his magnetic powers. For example, when he touches a magnet with the same polarity, he is repelled and bounces into the air; when he touches one with the opposite polarity, he is attracted toward it.
Players do not control the magnet man directly. Instead, they must strategically place magnets in the scene to guide him safely to the destination.
https://drive.google.com/file/d/1s0VR2wAQBo5k56xSiJCQIrIO9LBYQ8iS/view?usp=sharing
There are four modules included in the core gameplay system:
Utilizes FSM (Finite State Machine) to manage character states.
using Audio_Zenject;
using FSM;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour{
private string currentStateName;
protected IStateMachine _stateMachine;
protected bool isPlaying=false;
protected bool isPlanning = false;
protected bool isWinning=false;
protected bool instantDeath=false;
protected virtual void InitializeStates()
{
List<IState> states = new List<IState>();
states.Add(InitState_Spawned());
states.Add(InitState_InTheAir_Planning());
states.Add(InitState_Idle());
states.Add(InitState_Moving());
states.Add(InitState_InTheAir());
states.Add(InitState_Die());
states.Add(InitState_UnderControl());
states.Add(InitState_Attached());
states.Add(InitState_Win());
var stateMachine= new StateMachine(states, key_spawned);
_stateMachine = stateMachine;
stateMachine.OnStateChanged.AddListener((state) =>
{
currentStateName = state.GetName();
});
_stateMachine.Initialize();
}
}
Manages the animator, movement, and magnetic interactions.
Provides condition checks — e.g., whether the player is airborne, in contact with traps, or interacting with items.
protected bool CheckIsGrounded()
{
if (_movement.IsGrounded())
{
return true;
}
return false;
}
private bool CheckTrap()
{
return Physics2D.OverlapCircle(_center.position, 0.5f, _settings.trapLayer);
}
private bool CheckInteractable(out IInteractable obj)
{
var hit = Physics2D.OverlapCircle(_center.position, 0.3f, _interactableLayer);
if (hit)
{
obj = hit.GetComponent<IInteractable>();
if (obj != null)
{
return true;
}
}
obj = null;
return false;
}
IItem provides an interface to link to ItemDatabase.IInteractable defines the interactive behaviors of interactable objects.IPolarizable is an interface that defines magnetic objects and exposes their polarity through an external accessor.IMagnetic inherits from IPolarizable and specifies how magnetic objects interact with other IMagnetic entities.UnityEvent<string> OnStateChanged to synchronize level states across characters, items, and UI elements.