- Home /
How to create a turn based battle system?
I'm creating a turn based battle system for a first person roguelike-esque game. Basically I'm wanting to create a turn based battle system similar to the one found in this video https://www.youtube.com/watch?v=p91ugcaGhTs I'm not sure where to go from where I'm at. As it goes I have a state system:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurnBasedCombatStateMachine : MonoBehaviour
{
public bool battle = true;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
while (battle = true)
{
PlayerChoose ();
PlayerAttack ();
EnemyChoose ();
EnemyAttack ();
}
}
void PlayerChoose()
{
}
void PlayerAttack()
{
}
void EnemyChoose()
{
}
void EnemyAttack()
{
}
void EndRound()
{
}
and I'm not wanting multiple combatants, it'll be basically just the player vs one monster.
Answer by MaxGuernseyIII · Sep 26, 2017 at 05:50 PM
Well don't put the infinite loop in Update, that's for sure. Update runs once per frame. If you put an infinite loop there, it will basically freeze your game.
You don't really want someone to write your game for you, do you? If so, you should be posting this on the jobs board.
If you are looking for advice on how to do it, here's what I've got.
There's a state pattern built into every turn-based game system.
Without getting into the details, think about all the events that can happen to the state of the game - the current actor chooses their attack, the current actor completes their attack, a character is killed, et ctera. Those become methods in the interface of your state classes. Create different implementations for each variant as needed - one variant for the player is choosing an action, one for the AI choosing an action, one for executing an action, et cetera. Typically, calling a method on a state object returns a state object which can either be the same state or a new state, depending on what happened.
Wire all your events into some kind of container for the state, and marshal all the appropriate data back and forth as needed,
Sorry about that. I didn't specify I'm just looking for advice to write it myself, I did not want someone to write it for me.
I just thought of the base of the state system, I didn't think about changing update to something else.
I didn't think you were but I could see that someone might interpret your question thusly.
Answer by Schaezar · Sep 29, 2017 at 12:46 PM
I would suggest that you take a look at this youtube channel : xOctoManx. He does explain in great details how to create the state machine for the whole turn-based battle system. It might help you, I know it did help me a lot when trying to design the ATB system.
Even if you're not going for an ATB like the FF series, you can still get a pretty good understanding on how to implement the state machine.
Answer by ifonlyme1000 · Aug 20, 2020 at 10:10 AM
Try this https://www.udemy.com/course/turn-based-strategy-game-development/ Complete turn based strategy game course