Turn-Based RPG - Scratch Wiki (2024)

Turn-Based RPG - Scratch Wiki (1)This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet, as we cannot guarantee the safety of other websites.

A turn-based RPG is a form of role-playing game. In turn-based RPGs, battles consist of turns where a player can command their characters to perform various actions to defeat opponents. Turn-based RPGs are one of the most popular types of RPGs on gaming consoles, but are not very popular as Scratch projects.

This article contains a guide on how to create a turn-based system for an RPG.

When finished, the project should look something like this.

Contents

  • 1 Game Statistics
  • 2 Battle Formulas
  • 3 Programming Actions
  • 4 Character Animation
  • 5 Automating the Enemy
  • 6 Ending the Game
  • 7 Finishing Remarks
  • 8 See Also

Game Statistics

Turn based RPG battles focus mainly on statistics and formulas. In this tutorial the player has the following statistics:

Atk: Physical attack power

Def: Physical defense

MaxHP: Most HP (Health Points) the character can have

HP: Health points, the player is dead when this is at 0

MaxMP: Most MP (Magic Points) a character can have

MP: Magic points, used for magic attacks

MGAtk: Magic attack power

MGDef: Defense from magic attacks

Additionally, the player character has statistics for their weapons:

Atk: A set increase in attack powerP: A random increase in attack power

An enemy has the same statistics as the player character except without the extra statistics for weapons and Magic Points.

The first thing you should do is create the statistic variables. Variables belonging to the player character should start with "C_" those belonging to the player character's weapon should start with "C_Wep" and those belonging to the enemy should start with "E_".

We are also going to gives the variables some test values when the green flag is clicked so that we may properly play the game during testing. When finished, your set of variables should look something like this:

When flag clickedset [C_Atk v] to [5]set [C_Def v] to [5]set [C_MGAtk v] to [15]set [C_MGDef v] to [5]set [C_MaxMP v] to [100]set [C_MP v] to (C_MaxMP)set [C_MaxHP v] to [100]set [C_HP v] to (C_MaxHP)When flag clickedset [C_Wep_Atk v] to [5]set [C_Wep_P v] to [5]When flag clickedset [E_Atk v] to [5]set [E_Def v] to [10]set [E_MaxHP v] to [120]set [E_HP v] to (E_MaxHP)set [E_MGAtk v] to [0]set [E_MGDef v] to [0]

Battle Formulas

Next you will learn the formulas for the different attacks. The variables you have just created fit snugly into those formulas. The formulas we will use are based on a classic RPG called Super Mario RPG.

Player Melee Attack Damage Formula:

C_Atk(C_Wep_Atk+(pick random (0-C_Wep_P) to (C_Wep_P))-E_Def)

(((C_Atk) + ((C_Wep_Atk) + (pick random ((0) - (C_Wep_P)) to (C_Wep_P)))) - (E_Def))

Player Magic Attack Damage Formula:

C_MGAtk+"spellrating"-E_MGDef

(((C_Atk) + (22)) - (E_MGDef))
  • Each spell has a strength rating which must be set.


Enemy Melee Attack Damage Formula:

E_Atk-C_Def

((E_Atk) - (C_Def))

Enemy Magic Attack Damage Formula:

E_MGAtk+"spellrating"-C_MGDef

(((E_MGAtk) + (0)) - (C_MGDEF))
  • Each enemy spell has a strength rating which must be set.

You need to build these scripts and leave them on the stage. They will be used as parts of the scripts for the battle actions.

Programming Actions

Now that you know how the game will handle formulas and stats, it is time to allow the user to play a simple RPG game.

To control the game, we need a few variables that serve to make the game run as opposed to building the battle formulas.

You will now need to create the following variables:

dam: Stores the results of the damage calculations

gamestate: Tells the game what is currently supposed to be doing e.g. letting the player pick attacks, or letting the enemy character attack

  • The number of the gamestate variable tells the program different things. This is the list of values for the variable:

1. Wait for player to enter a command

2. Wait for player character animation to finish

3. Allow the enemy to pick an action and carry it out

0. The RPG battle is over

C_Stance: Tells the character sprite which animation to play e.g. standing, attacking, cast spell.


E_Stance: Tells the enemy sprite which animation to play e.g. standing, attacking, cast spell.

  • The stance variables tell the which animations to play, for this game we will make the following animations:
  1. Idle animation
  2. Attack animation 1 (melee)
  3. Attack animation 2 (spell)
  4. Hurt animation
  5. Death animation


You will also need the following Broadcasts:

melee: Makes the player character use a melee attack

spell: Makes the player character do a magic attack

emelee: Makes the enemy character use a melee attack

espell: Makes the enemy character do a magic attack

stance: Tells the player sprite to do an animation

enemy_stance: Tells the enemy sprite to do an animation

Now, create the following scripts on the stage

when I receive [melee v]set [C_Stance v] to [2]set [gamestate v] to [2]broadcast [stance v] and waitset [dam v] to (((C_Atk) + ((C_Wep_Atk) + (pick random ((0) - (C_Wep_P)) to (C_Wep_P)))) - (E_Def))if <(dam) < (0)> thenset [dam v] to (0)endchange [E_HP v] by ((-1) * (dam))set [E_Stance v] to [4]broadcast [E_stance v] and waitset [gamestate v] to [3]set [C_Stance v] to [1]broadcast [stance v]when I receive [spell v]set [C_Stance v] to [3]set [gamestate v] to [2]broadcast [stance v] and waitset [dam v] to (((C_Atk) + (22)) - (E_MGDef))if <(dam) < (0)> thenset [dam v] to [0]endchange [E_HP v] by ((-1) * (dam))set [E_Stance v] to [4]broadcast [E_stance v] and waitset [gamestate v] to [3]set [C_Stance v] to [1]broadcast [stance v]when I receive [emelee v]set [E_Stance v] to [2]broadcast [E_stance v] and waitset [dam v] to ((E_Atk) - (C_Def))if <(dam) < (0)> thenset [dam v] to [0]endchange [C_HP v] by ((-1) * (dam))set [C_Stance v] to [4]broadcast [stance v] and waitset [E_Stance v] to [1]broadcast [E_stance v] and waitset [gamestate v] to [1]when I receive [espell v]set [E_Stance v] to [3]broadcast [E_stance v] and waitset [dam v] to (((E_MGAtk) + (0)) - (C_MGDef))if <(dam) < (0)> thenset [dam v] to [0]endchange [C_HP v] by ((-1) * (dam))set [C_Stance v] to [4]broadcast [stance v] and waitset [E_Stance v] to [1]broadcast [E_stance v] and waitset [gamestate v] to [1]


You will also need a way to allow the player to broadcast these actions so make 2 buttons with the following scripts:


Melee Button

when this sprite clickedif <(gamestate) = (1)> thenbroadcast [melee v]endwhen flag clickedforeverif <(gamestate) = (1)> thenshowelsehideend


Spell Button

when this sprite clickedif <<(gamestate) = (1)> and <<(C_MP) > (15)> or <(C_MP) = (15)>>> thenbroadcast [spell v] and waitchange [mp v] by (-15)endwhen flag clickedforeverif <(gamestate) = (1)> thenshowelsehideend


The player should only be able to press these buttons when the gamestate variable is at 1 so we hide them if the variable is not at one. The buttons work in similar ways but the spell button check to see if the player has enough MP and only make the broadcast if there is enough MP.


As a finishing touch we are going to set the variables that are not involved in the battle formulas to a default value.

when flag clickedswitch backdrop to [background1 v]set [gamestate v] to [1]set [C_Stance v] to [1]set [E_Stance v] to [1]broadcast [stance v]broadcast [E_stance v]

Character Animation

You will need an animation for each stance, you can either draw them yourself, download a premade sprite sheet, or use a sprite generator such as the Charas-Project Generator

For this project, the article will use the Charas generator for quick and easy sprites but those who are more artistically inclined can draw them. If you are not drawing sprite then you must import the sprite sheets and cut the sprite out. For a quick guide on how to do this go to this forum topic.

The animations that you need are the following:

  1. Idle animation
  2. Attack animation 1 (melee)
  3. Attack animation 2 (spell)
  4. Hurt animation
  5. Death animation

To make the character sprites to play a little animation every time the stance broadcasts are called so we need a script like this one. The blocks inside the if blocks are for the animations are can be customized in any way you like.

when I receive [stance v]if <(C_HP) < [1]> thenswitch costume to [dead_1 v]elseif <(C_Stance) = [1]> thenswitch costume to [idle v]endif <(C_Stance) = [2]> thenswitch costume to [idle v]move (100) stepsswitch costume to [melee_1 v]wait (0.1) secsswitch costume to [melee_2 v]wait (0.1) secsswitch costume to [melee_3 v]wait (0.1) secsgo to x: (-90) y: (-89)switch costume to [idle v]endif <(C_Stance) = [3]> thenswitch costume to [idle v]move (100) stepsswitch costume to [spell_1 v]wait (1) secsgo to x: (-90) y: (-89)switch costume to [idle v]endif <(C_Stance) = [4]> thensay (dam)switch costume to [hurt_1 v]repeat (3)move (-10) stepsendrepeat (3)move (10) stepsendwait (0.5) secsswitch costume to [idle v]say []endend


The script for the enemy sprite will look the same except that the broadcast will be the enemy's broadcast (E_stance) and the stance variable will belong to the enemy (E_stance).

A picture of the enemy script can be seen below.

when I receive [E_stance v]if <(E_HP) < [1]> thenswitch costume to [dead_1 v]elseif <(E_Stance) = [1]> thenswitch costume to [idle v]endif <(E_Stance) = [2]> thenswitch costume to [idle v]move (100) stepsswitch costume to [melee_1 v]wait (0.1) secsswitch costume to [melee_2 v]wait (0.1) secsswitch costume to [melee_3 v]wait (0.1) secsgo to x: (90) y: (-89)switch costume to [idle v]endif <(E_Stance) = [3]> thenswitch costume to [idle v]move (100) stepsswitch costume to [spell_1 v]wait (1) secsgo to x: (90) y: (-89)switch costume to [idle v]endif <(E_Stance) = [4]> thensay (dam)switch costume to [hurt_1 v]repeat (3)move (-10) stepsendrepeat (3)move (10) stepsendwait (0.5) secsswitch costume to [idle v]say []endend

Automating the Enemy

Since the enemy does not have a player to control its actions, it will do so on its own.

Build this script on the enemy sprite and it should attack the player by itself when gamestate is equal to 3.

when flag clickedforeverif <(gamestate) = [3]> thenif <(E_HP) < [1]> thenbroadcast [win_battle v] and waitendif <(gamestate) = [3]> thenset [randAtk v] to (pick random (1) to (2))if <(randAtk) = [1]> thenbroadcast [emelee v] and waitendif <(randAtk) = [2]> thenbroadcast [espell v] and waitendif <(C_HP) < [1]> thenbroadcast [lose_battle v] and waitendendend


This script as you can see also is able to call the broadcasts that end the game, the win_battle and lose_battle broadcasts.

Ending the Game

There are two conditions in which the game ends:

  1. The player loses all HP and loses the game
  2. The enemy character loses all HP and the player wins

As you can see from the above script that automates the enemy, the enemy checks to see if these conditions have been fulfilled and calls the appropriate broadcast.

In the demo project, a different background plays and the gamestate is set to 0, which means that the battle sequence is done.

when I receive [lose_battle v]set [gamestate v] to [0]switch backdrop to [background3 v]when I receive [win_battle v]set [gamestate v] to [0]switch backdrop to [background2 v]

Finishing Remarks

Test your project out, if you followed this tutorial correctly, then you should have a working RPG project. If it is not working then it is likely you did not correctly copy the scripts in this article. The best way to troubleshoot is to compare it with the example one given at the start of this article.

See Also

  • RPG
  • RPG Projects
  • How to Make an RPG Overworld
Turn-Based RPG - Scratch Wiki (2024)

FAQs

What is turn-based RPG? ›

A turn-based MMORPG is a type of massively multiplayer online role-playing game that utilizes turn-based game flow, meaning that game actions are partitioned into well-defined and visible parts, called turns.

Is chess a turn based RPG? ›

Many board games are turn based, such as chess, Reversi, checkers, Hare games, and Go, as well as many modern board games.

What does RPG mean? ›

A role-playing game (RPG) is a game in which each participant assumes the role of a character that can interact within the game's imaginary world. Many RPGs are set in fantasy or science fiction environments. Among the earliest and most popular RPGs are Dungeons and Dragons (D&D), BattleTech, and Star Wars Galaxies.

What makes a game turn-based? ›

Turn-based games are different from real-time games, where events happen continuously and simultaneously. In real-time games, players require to react quickly and make decisions on the fly. In turn-based games, players have more time to think and strategize before making a move.

Is Child of Light a turn-based RPG? ›

Child of Light's gameplay has the attributes of a side-scroller with role-playing elements such as leveling up to increase stats over time. Battles with enemies use a system of turn-based combat similar to the active-time battle system found in games of the Final Fantasy and the Grandia series.

Is Paper Mario a turn-based RPG? ›

All games except Super Paper Mario feature a turn-based combat system, where Mario and one or more opponents take turns attacking one another. The first two games, Paper Mario and Paper Mario: The Thousand-Year Door, feature elements similar to that of a typical role-playing video game (RPG).

Is Undertale a turn-based RPG? ›

Undertale employs a bullet hell/turn-based combat system in which the player controls the heart, avoiding attacks from enemies in between fighting, acting and sparing enemies, or healing. Undertale is a role-playing game that uses a top-down perspective.

Does 3d chess exist? ›

Three-dimensional variants have existed since at least the late 19th century, one of the oldest being Raumschach (German for "Space chess"), invented in 1907 by Ferdinand Maack and considered the classic 3‑D game.

What does RPG 7 stand for? ›

First produced as an anti-armor weapon in the early 1960s, the Soviet-designed RPG-7 (rocket-propelled grenade) is a shoulder-fired, reusable tube that launches an unguided, rocket-propelled grenade.

What does RPG mean in Russian? ›

The term "rocket-propelled grenade" is a backronym from the Russian acronym РПГ (Ручной Противотанковый Гранатомёт, Ruchnoy Protivotankovy Granatomyot), meaning "handheld anti-tank grenade launcher", the name given to early Russian designs.

Why are RPGs so popular? ›

Mobile role-playing games are popular because of their highly immersive storytelling and strategic decision-making elements. Players progress through levels as a character in a fictional world. What Are the Best Mobile RPG Games?

Is Final Fantasy a turn-based RPG? ›

The answer depends on who you ask and your own definition of "turn-based". FF used ATB system since FF4. It is essentially real time system with cooldown between actions. But older implementations played a lot like turn-based games while newer games like 12, 13, 15 and this Remake can be played entirely in real time.

Is Pokemon a turn-based JRPG? ›

If you've played Pokemon before, ... The game features the same turn-based combat system as the original games, where players select different moves for their Pokemon to use in battle.

What is the difference between RTS and turn-based? ›

Real-time strategy (RTS) is a subgenre of strategy video games that does not progress incrementally in turns, but allow all players to play simultaneously, in "real time". By contrast, in turn-based strategy (TBS) games, players take turns to play.

Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 5979

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.