How to make classical Rock,Paper,Scissor

3
  • 10 favourites

Attached Files

The following files have been attached to this tutorial:

Stats

2,246 visits, 4,482 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Before We Start

This is the first tutorial of the “Why Series”. The “Why Series” is new type of tutorial, it tells you what to do and then it tells you why. For Example: “Use the bullet and wrap behavior to the cloud and set bullet speed to 30” Why? That’s because bullet move directly and wrap because there are always new cloud come while the old leave, and the speed of bullet is set to 30 because the cloud should move slowly and smoothly through the layout. All why series will have its name and a number like this: Why Series #29. Hope I helped.

- Why Series #01

Basic Items Needed

First, you’ll need 5 important graphics: Background, Paper hand, Rock hand, Scissors hand, and enemy hand.

Background: Any background or color (You can use blue for example)

The hands are in the shape of the hand when you play it, if you don’t know how, just take graphics as paper, a rock, and a scissor.

The enemy hand should have the same graphics to make the three main hands, but it have four graphics: Illusion, rock, paper, and scissor. Why? The first three hands have their own animation separated because the player is going to choose one of them, while the enemy hand is going to be chosen by the CPU , and it needs illusion so the player don’t know what the CPU had chose. To make the illusion animation, we must use three frames: also the rock, paper, and scissor. Put the speed 1 frame per sec and set Loop to Yes. Why? The illusion must be slow so to make the player confused what to choose, and set loop yes to continue as the player is choosing the right hand.

Second, we need 4 global variables and 1 instance variable. The instance variable should be for the background, or any extra sprite that is not the main graphics for the game. Name the variable: (RPS_Time => Number => 0). RPS is the shortcut for the word rock paper scissor. For the global variables we need 4: (RPS_Score => Number => 0) & (RPS_Highscore => Number => 0). Then we need global variables: (PlayerChoice => Text => “Rock”) & (EnemyChoice => Text => “Rock”). Why? Player Choice variable is used to set the player’s choice. After he click a hand the variable will change. Every 3 seconds the enemy choice variable change due to an event. (Talk about later in the Event Section), so that the Enemy choice don’t stay rock forever.

Third, we need 2 text objects, ScoreText & HighscoreText. One is for score and other for high score. Put them on the left top of the layout.

After we got the basic elements for the game, we’ll then start with events.

The Events

The total events we will use are 22 Events with the global variables. So even if you have free edition, you can make it.

1) Every tick => ScoreText => Set Text => RPS_Score

2) Every tick => HighsoreText => Set Text => RPS_Highscore

Why? Events are used to read the high score and score on the screen.

3) RPS_Score > RPS_Highscore => Set RPS_Highscore to RPS_Score

Why? When the score is higher than the value of the high score variable, that mean that the player had beaten his old high score and new high score should be set. This event helps the high score value change when the score get higher than it.

4) RPS_Time = 0 => Set Enemy Hand animation to “illusion” (play from the beginning)

5) RPS_Time = 0 & Every 3 seconds => Set Enemy Choice to choose(“paper”,”rock”,”scissor”)

6) Depend on your platform you will choose touch or mouse cursor or maybe both. Here we are going to choose Touch: On Touched “Rock” & RPS_Time = 0 => 1- Set player choice to “Rock”, 2- Paper Destroy 3-Scissor Destroy 4- Set RPS_Time to 1.

7) Touch: On Touched “Paper” & RPS_Time = 0 => 1- Set player choice to “Paper”, 2- Rock Destroy 3-Scissor Destroy 4- Set RPS_Time to 1.

8) Touch: On Touched “Scissor” & RPS_Time = 0 => 1- Set player choice to “Scissor”, 2- Paper Destroy 3-Rock Destroy 4- Set RPS_Time to 1.

9) RPS_Time = 1 or RPS_Time = 0 => Enemy Hand: set animation to EnemyChoice (play from the beginning)

Why? When the player chooses a hand the other two hands are deleted. They are deleted because when the RPS_Time (the instance variable) is set to 1, the CPU see the results by the last Sprite, while for the enemy hand, the CPU see the results by the selected animation. We’ll explain more down there

10) RPS_Time = 0  Rock: Is visible & Enemy Hand is animation “Paper” => 1- Set RPS_Time to 2 2-Set RPS_Score to 0 3-wait 2 seconds 4- Restart Layout. Do this event for one paper and one rock with the hand that will make them lose.

11) RPS_Time = 0  Rock: Is visible & Enemy Hand is animation “Rock” => 1- Set RPS_Time to 2 2-wait 2 seconds 3- Restart Layout. Do this event for one paper and one rock with the hand that make them neutral or draw.

12) RPS_Time = 0  Rock: Is visible & Enemy Hand is animation “Scissor” => 1- Set RPS_Time to 2 2- Add 1 to score 3-wait 2 seconds 4- Restart Layout. Do this event for one paper and one rock with the hand that make them neutral or draw.

Why? When I first tried to make the RPS game I thought I made it right but in the last three events (10, 11, and 12) it didn't work. I first tried to compare the global Variables: PlayerChoice and EnemyChoice instead of the animation and visibility check. It turns out that it didn't work, when comparing two sprites or animation use only global variables to change the animation, don’t use the variables to compare.

Extra Events & Animation

Thus we used only 22 events, you can add a moving animation and cute things to make the game better, because of course you will not put main sprites only, you will decorate the background and add some effects to it. So if you were willing to just do what I said without decorating the game and add buttons, and a Menu page, I will guarantee your game will be boring. If you have free edition you still have 78 events to make the game better, and if you have the personal or business license you are free to have many events as you want so why not to make it better.

tghe .capx file is included with this tutorial. Hope you'll find it useful.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!