This is the ninth part of the “Everyone can Make games” series. This series of tutorials is aimed at absolute novices without any game development experience. It’s not very difficult to make a micro channel game, and you can do it too.

The small game development tool used in the tutorial is wechat official small game production tool: wechat small game production tool

If you are interested in game development, please follow my wechat official account: Little Ant Game Development.

In this section we will look at two of the most common types of logic used in game development:

  • cycle

  • If, then

cycle

“Looping” means doing the same thing over and over again, such as running, jumping, playing sound over and over, playing animation over and over.

“Loops” are divided into two types, one with stop conditions and one without.

Getting the enemy to move from point A to point B is A loop with A stop condition, the stop condition is point B. Let the background music loop 5 times, also have a stop condition loop, stop condition is 5 times.

The loop with no stop condition starts at the beginning of the game and ends at the end of the game. You can keep the background music playing on a loop until the game is over.

If, then

The logic of “if, then” is pretty straightforward: if the player dies, the game should end. Conversely, if the player doesn’t die, the game shouldn’t end. If I kill an enemy, then my score should be increased by one. If an enemy is hit by a bullet, it should explode……

Let the small plane fly in a loop

Let’s use a simple example to learn how to use both types of logic.

Suppose there are two points in the game, point A and point B. The enemy plane flies from point A to point B, and when it reaches point B, it comes back to point A again, and then continues on to point B, and so on.

Analysis of the logic, in order to make the enemy aircraft fly from point A to point B, we need to use the “circular” logic, so that the enemy aircraft keep moving in the direction of point B. When you get to point B, to get back to point A again, you need to resort to “if, then” logic. If the enemy plane reaches point B, then the enemy plane is repositioned to point A.

Next, let’s look at how building blocks can be used to achieve this simple function.

First, let’s import some materials to build a simple scene, and review if you forget how to import materials.

As shown in the picture, we imported “dot” and “basic text” materials, and set two dot positions of A and B in the editing area.

Tip: The color of the image can be changed by adjusting “Color Overlay” in the properties area.

Select “Enemy aircraft” in the hierarchy, and click the “Add Event” button in the block area to add an “When the scene starts” event.

This adds A “when the scene is on” block, and we put all the logic into the “when the scene is on” block, so that enemy planes keep flying from point A to point B as soon as the game starts.

Next, let’s add the first block. Select “Movement” on the right of “block area” and drag the block “move yourself to random relative coordinates” into the block area.

Tip: All blocks related to movement and rotation are included in the “Movement” on the right.

We want the enemy to be at point A from the start of the game, so choose to move to the “dot” position, where “dot” represents point A and “dot _1” represents point B.

Next, add a “loop” block, click “Logic” on the right, and drag the “repeat execution” block to the block area. The loop blocks with no stop conditions are used here, and the three blocks in the blue box below are the loop blocks with stop conditions.

It looks like this, and then you put the movement of the enemy aircraft in this “repeat execution” building block.

Select “Movement” and drag the “increase your X value by 10” block to the block area.

Since point B is located directly below point A, it is only necessary to set the position of Y-axis to make the enemy aircraft move directly below point A continuously, which is achieved by making the enemy aircraft’s Y-coordinate constantly decrease.

Click “Preview scene” to see the effect.

At the start of the game, the enemy aircraft will fly straight down from point A, but once they reach point B, they will continue to fly straight down until they leave the screen.

Next, we add the “if, then” block to make it possible for the enemy aircraft to fly from point A again after reaching point B.

Locate the “if” block in logic on the right and drag it to the block area.

Then add the judgment condition, select “operation” on the right, find the comparison block, and drag it to the judgment condition of the “if” block.

We need to compare the position of the enemy aircraft and the position of point B, select “Detect” on the right, find “my own X” block, and drag it to the ellipse on the comparison block.

We only need to compare the enemy aircraft and the position of point B on the Y-axis, so choose Y for comparison. If the position of the enemy plane on the Y-axis is smaller than the position of point B, it proves that the enemy plane has reached point B, and then the “if” condition of the block is valid.

The dot _1 in the figure represents point B.

Once the conditions are met, we will return the enemy aircraft to point A again.

On the right, find the “Move yourself to random relative coordinates” block in “Movement” and drag it to the “If” block.

This is what it looks like in the end.

Let’s look at the picture above and go over the whole logic again:

After the game starts, the enemy planes are placed at point A, and then the loop begins, the enemy planes move to point B. When the enemy planes reach point B (y of the enemy planes is less than Y of point B), the enemy planes are placed at point A again, and the enemy planes move from point A to point B again.

Click “Preview scene” to see the effect again.

Does your game achieve this effect?

To summarize

We looked at two of the most commonly used logic in games: “loops” and “ifs, then”.

Using these two logics we have implemented a simple example of a small aircraft flying in a loop.

practice

If an enemy aircraft flies from point A to point B, and then from point B to point A, how does the round-trip logic work?