Difference between revisions of "Battle System Tutorial by Radnen"

From Spherical
Jump to: navigation, search
(created from http://web.archive.org/web/20120414032626/http://www.spheredev.org/wiki/Battle_System_Tutorial_by_Radnen)
 
(No difference)

Latest revision as of 00:58, 8 June 2013

This is ridiculously small and simple battle system tutorial. It's made to get you thinking about things a certain way and applying it to great affect. It's intended for those who already know how to program simple systems and want to wrap their head around how one would design a battle system, and then implement it.

Programming Level: Beginner to Mediocre.

Design Phase

In this phase you will look at the fundamental objects that make up a battle system. Since I'm going to keep things abstract I'm not going to go over the details of specific battle systems. Instead I'll go over details prevalent in all battle systems. In future tutorials I'll modify this tutorial to show how particular systems can be made, you can even request one from me if I haven't done it already. For now it's just the generic stuff.

Entities

First we need to identify the entities that are present in our battle system. Two main entities are

  • Players
  • Monsters

Other entities can be (won't cover yet):

  • Items
  • Spells/Abilities

What are the attributes that build a player entity?

  • Health
  • Mana
  • Defense
  • Attack

Other (I won't cover these):

  • Equipment
  • Has own inventory?
  • Spells/Abilities
  • Other attributes (strength, speed, wisdom)...
  • More stuff you can specify.

What we can easily elicit here is that enemies and players are one and the same. Therefore you can build a single class that handles both.

Now that we have defined the entities and their attributes, let's continue and examine what these entities can do.

  • Attack
  • Defend

Also (I won't cover these here):

  • Level up
  • Equip an item
  • Use an item
  • Cast a spell
  • Flee

So, as a rule of thumb when creating a new object/entity identify what it is by it's attributes then identify what it can do. The things I am not covering you can figure out yourself. Also some will be covered in specific battle system tutorials, for example the "Flee" behavior may use a speed value, and would be involved in a turn based system (it may not make sense in an action system). Attack and Defend are going to be fundamental to the example, so I'll cover those.

The Interface

The interface is an abstract class, more or less that helps you control the events of things. I'm going to write a generic interface for this battle system and I'll extend it in further tutorials.

The interface needs to hold data pertaining to the battle. It may contain:

  • A list of players.
  • A list of enemies.
  • For turn based, the current turn.
  • For turn based, turn conditionals.

The interface controls:

  • Turns (if turn based)
  • Condition that player attacks
  • Condition that enemy attacks
  • The AI of the enemy
  • Menus for when entities use items
  • Menus for spells/abilities
  • Other menus...

So, again, as you can see the interface controls how the battle is played out. And depending on how you implement the interface you can have whatever kind of battle system you want.

Implementation Phase