How to add characters to a 2-player battle in Scratch

To add more characters to a 2-player battle game in Scratch, you create new sprites, give each one a costume (the character's appearance), and write code that lets players choose which character to control before the game starts. The simplest way is to add a character selection screen where one player picks their sprite, then the other player picks theirs, and the game remembers which sprite belongs to which player during the battle.

The core idea is that instead of hardcoding one specific sprite for each player, you use variables to store which sprite each player selected. Then during the battle, you check those variables to know which sprite to move, animate, or damage when each player presses their controls.

Key Takeaways

  • Create multiple character sprites in Scratch, each with their own costumes and code blocks for movement and attacks.
  • Use variables like "Player 1 Character" and "Player 2 Character" to remember which sprite each player chose before the battle starts.
  • Build a selection screen where players click buttons or press keys to pick their character, and the game stores that choice in a variable.
  • Write conditional code that checks the character variable and runs the correct sprite's movement, animation, and damage code based on what was selected.

Creating multiple character sprites

Start by making separate sprites for each character you want in your game. In Scratch, click the "Choose a Sprite" button and either pick from the library or paint your own. Give each sprite a clear name like "Knight", "Wizard", or "Archer" so you can tell them apart in your code.

For each character sprite, add the costumes (different images) you need — a standing pose, an attack pose, a hit pose, and a defeated pose are common ones. You can draw these yourself, upload images, or use Scratch's built-in sprite library. The more costumes you create, the smoother your character animations will look during the battle.

Once all your character sprites exist with their costumes, hide them all at the start of the game. You'll only show the ones the players actually selected. Add a block like "hide" to each character's startup code so they don't clutter the screen before the selection screen appears.

Setting up character selection with variables

Create two variables: one called "Player 1 Character" and one called "Player 2 Character". These variables will store the name of the sprite each player chose. You can create variables by going to the Variables category, clicking "Make a Variable", and typing the name.

Build a selection screen that appears when the game starts. This can be as simple as displaying text that says "Player 1: Press 1 for Knight, 2 for Wizard" and then checking which key was pressed. When a player presses a key, set the corresponding variable to the character name. For example, if Player 1 presses 1, set "Player 1 Character" to "Knight".

You can also use clickable buttons instead of keyboard input. Create small sprites that act as buttons — one labeled "Knight", one labeled "Wizard", and so on. When a player clicks a button, set the variable to that character's name. This approach works well for games where both players share the same keyboard.

Showing the selected characters during battle

Once both players have made their selections, show only the sprites they chose. Use conditional blocks that check the character variables. For example, add code to the Knight sprite that says "if Player 1 Character = Knight, then show". Do the same for every character sprite — each one checks whether it was selected for Player 1 or Player 2, and only shows itself if it was.

Position each character sprite on the screen based on which player selected it. You can use code like "if Player 1 Character = Knight, go to x: -100 y: 0" to place Player 1's character on the left side, and "if Player 2 Character = Wizard, go to x: 100 y: 0" to place Player 2's character on the right side.

Make sure the character sprites are positioned so they don't overlap and both players can see their character clearly. Test your positioning by selecting different character combinations and checking that each one appears in the right spot.

Connecting controls to the selected character

The tricky part is making sure that when Player 1 presses a movement key, only Player 1's selected character moves. Use conditional blocks that check the character variable before running movement code. For example, add a block that says "if Player 1 Character = Knight, then move 10 steps" inside the code that runs when Player 1 presses the right arrow key.

Do this for every character and every control. If you have three characters and four movement directions, you'll need twelve conditional blocks total for Player 1 alone — one for each character-direction combination. It sounds like a lot, but it's straightforward: check the variable, then run the movement code if it matches.

The same approach works for attacks and special moves. When Player 1 presses the attack button, check which character they selected, then run that character's attack animation and damage code. This way, different characters can have different attack speeds, ranges, or damage amounts without interfering with each other.

Handling damage and health for multiple characters

Create health variables for each character slot: "Player 1 Health" and "Player 2 Health". These track how much damage each player has taken, regardless of which character sprite they're controlling. When an attack hits, subtract from the opponent's health variable, not from a specific sprite's variable.

When displaying health on screen, show the health variables, not the sprite properties. Use "say" blocks or text sprites to display "Player 1 Health: 100" and "Player 2 Health: 100" so both players can see the current score. Update these displays every frame so they stay current during the battle.

When a player's health reaches zero, end the game and announce the winner. You can check "if Player 1 Health ≤ 0, then broadcast Game Over" and have a separate sprite handle the end-game screen. This way, the winner is determined by health, not by which sprite was selected.

Testing different character combinations

Run your game and test every possible pairing of characters. If you have three characters, test Knight vs. Knight, Knight vs. Wizard, Knight vs. Archer, Wizard vs. Wizard, Wizard vs. Archer, and Archer vs. Archer. This catches bugs where one character's code interferes with another's, or where the wrong sprite shows up on screen.

Pay special attention to attacks and animations. Make sure that when Player 1 attacks with Knight, the Knight sprite plays the attack animation and Player 2's health decreases. Then test the same attack with a different character to make sure the code still works. If a character's attack doesn't land or the animation doesn't play, check the conditional blocks that check the character variable.

Also test edge cases: what happens if both players select the same character? What if a player presses a movement key before the selection screen is done? What if an attack lands at the exact moment the opponent's health reaches zero? Finding and fixing these issues now saves frustration later.

Frequently Asked Questions

Can I let players pick the same character?

Yes. Your code doesn't prevent it — both players can select Knight, for example. If you want to allow this, make sure each player's code is independent so they don't interfere with each other. If you want to prevent duplicate selections, add a check: when Player 2 tries to pick a character, first check if Player 1 already picked it, and if so, display a message saying that character is taken.

What if I want characters to have different stats like speed or damage?

Create variables for each character's stats: "Knight Damage", "Wizard Damage", "Knight Speed", "Wizard Speed", and so on. When a player selects a character, set their player's stats to match. For example, "if Player 1 Character = Knight, set Player 1 Damage to Knight Damage". Then use the player's stat variables during the battle instead of hardcoded numbers.

How do I make the selection screen look better?

Create a background sprite or use the stage backdrop to draw a title and instructions. Add character preview images so players can see what each character looks like before picking. You can also add sound effects when a player selects a character, or display the selected character's name on screen to confirm the choice was registered.

Can I add a third or fourth player?

Yes, but the code gets more complex. Create variables "Player 3 Character" and "Player 4 Character", add a selection screen for each player, and write conditional code for each player's controls and health. The logic is the same — check which character each player selected, then run the right code — but you'll have more variables and more conditional blocks to manage.

What if a character's attack code is really long?

Use custom blocks to organize your code. Create a block called "Knight Attack" that contains all the animation and damage code for the Knight's attack. Then in your main attack code, just check "if Player 1 Character = Knight, call Knight Attack". This keeps your code readable and makes it easier to change a character's attack later without hunting through dozens of blocks.