Scratch

Automatic Random Motion of an Enemy Character

Video - Automatic Random Motion of an Enemy Character


Video Transcript

Good evening!

The game "banana hunt" seems very interesting to me. I'm looking forward to finish, so I can play it, too.

In this lesson, which consists of 2 parts, great progress will be made.

New characters will be embedded in the game and you will program their behavior.

Stevie you are on!

 

Thank you Athena!

I'm glad you find the game interesting. You will definitely be one of the first to try it out. I promise!

Good evening!

We have left a task in the middle. In today's lesson, we will continue to create "Banana Hunt" even further.

Before we continue, we need to remember what we have done so far.

I have prepared videos that you will watch at fast forward that will help you remember where we are.

Let's watch it ...

I have many things to show you today so I should get into the screen.

I need a way to get into the screen please .. (finger clapping ..)

To begin with, we should make the monkey a little bit smaller.

I think it's too big and it will make it hard for us to play this game.

We want to see the new size from the beginning of the game and throughout its whole duration.

So we want the size of the monkey to be much smaller by clicking on the green flag when the game starts.

From the "Looks" command palette, locate the command block "set size to 75%".

Drag the instruction to the script area and apply it directly under the command "When the green flag is clicked".

I recommend that you change it from 75% to 30%.

Try the script after the new change ..

Very nice. The next step will be to change the stage.

Let's get rid of this boring white by choosing a background from the scratch library.

This is the area of the software that manages the backgrounds.

Let me push this button that will take me to the scratch library.

Select the "woods" backdrop and click OK.

Very nice! Our game has already the desired shape.

It is time to deal with the rest of the sprites. Let's start with the lions. It is important to note that each lion moves differently.

To add another item from the Scratch library, follow the procedure that we followed with the monkey.

This time select the Lion sprite. Quite large. Let me make sure it is smaller when the game starts.

I will follow the same procedure I just followed with the monkey.

When the green flag is clicked then

"Set size to 50%"

Let's give motion now to the lion. We will of course use the Command palette “Motion”.

I will first select the 'move 10 steps' instruction.

Let me put it in my script and press of the green flag.

You have surely noticed that the lion barely moved.

If this command enters a block repeat forever, once this little move has finished it will do it again and again.

This way it will move continuously throughout the game, and the movement will look contiguous. Let's try it ..

The lion reaches the boundaries of the setting where it necessarily stops.

It is a good idea to set the lion to continue its move after finding the edge of the stage, making a gel on it.

This feature is provided by scratch with the command "If on edge bounce".

Let's put it in our scenario, and let's run the script.

The new problem that we have to solve now is to set the object's orientation after the bounce as it is upside down.

To correct this problem we need to change the sprite's rotation axis. This is done by its attributes.

Let's set the axis of rotation horizontally and run our program again.

Much better! But the lion's movement is horizontal, so it covers a small area of the

scene.

If the lion started from a diagonal position would cover most of the stage. I will set it off from a corner.

From the "Motion" palette, I will incorporate at the beginning of my script the sprite’s turn.

Let me try my script now ...

Perfect ... I think we have made significant progress.

The Game – Presentation of Details

Video - The Game - Presentation of Details



Video Transcript

Hello!

This course will present the step-by-step process of creating the online game called "Banana Hunt".

The software to be used is scratch.

If you are anxious, it will be hard to let it go. Believe me, you will succeed and at the same time you will have fun!

Stevie will be your trainer throughout this process.

But he will often lend his voice to special scientists who will analyze for you, some important details of the game-making process.

The first lesson is divided into 2 parts.

In the first part you will hear Stevie present you the game you will create by analyzing its components.

The second part involves more action. You will create the first character and program its behavior.

Are you looking forward?

Let's start!

 

Good evening!

It's time to finally create your first game.

You will not have difficulty doing it

Follow precisely the steps I will tell you and everything will go well!

First, watch a few seconds from the game we're about to make.

The game is called "Banana Hunt".

The reason the game is called so is obvious and you will understand it immediately!

Video please! (Finger clapping)

Soon you will make this game and challenge your friends to surpass your personal record

First let's clarify some basic elements of the game.

All games have a purpose.

The purpose of "Banana hunt" is to collect as many bananas as possible.

The monkey collects bananas while trying to avoid the terrible lions hunting to eat it!

The latter determines the only rule of the game.

The hero of the game is allowed to move in any way on the game screen but can’t touch the lions.

If that happens the game is over.

The main character of the game is the monkey.

The monkey moves along the length and width of the screen - by following the mouse pointer!

There are three other main characters - the lions, and they are the opponent.

They also move across the screen. They move in a different way and at different speeds from one another.

Another object of our game is bananas. Bananas appear randomly on the screen of the game.

Every time the monkey touches a bunch of bananas, the score rises by 1.

The game is played exclusively with the mouse or touchpad if you have a portable computer.

All scratch programs are made by joining colored bricks or blocks like the pieces of a puzzle.

Each brick is a command that tells an object what to do.

The 5 different objects contained in our game each have their own script.

Script is the set of commands - and blocks - that we programmers use, in order to achieve the performance we want on each object.

To be clearer, it would be better to say that a scenario is a pile of blocks (and commands) in an object.

It is also important to mention that an object can have more piled blocks and more scenarios.

All scenarios together determine the behavior of this object in the game.

 

Events and Sprite Communication

Video – Events and Sprite Communication



Video Transcript

Hello

When we create electronic games we often want some actions of the heroes to take place in the same time.

Also we want the different sprites we use to communicate with each other.

So games become more interesting.

You will find the answers to the above 2 issues in the upcoming video by Stevie.

Please watch carefully.

 

Hello,

Events are the various events that can be made in the progress of the game we create and cause the execution of specific instructions, therefore also behaviors in the sprites of this game.

An event we have encountered in Scratch several times is the command: "when the green flag is clicked".

This instruction basically proceeds to execute the instructions that follow when the user clicks on the green flag, i.e. when he causes the specific event.

In addition to the specific events we have just mentioned, very important events we often use are the following

  • When a specific button is pressed
  • When you click on a specific sprite
  • When a specific message is received.

It is important to say that when an event occurs, such as pressing the green flag, more than one piles of code can run.

Watch the scenario we will assign to one of the lions that chases the monkey, in the game we will create in the next lesson.

Notice that there are 2 piles of codes running when the green flag is clicked.

This code runs at the same time.

Very often there is a need for communication between the sprites of our game.

For example, in the game we talked so much about in this lesson, where the monkey chases bananas, let's assume that as soon as the player has accumulated 10 points, another character must appear, let’s say, Gas, and he will say the phrase "Congratulations you reached 10 points" and then he will disappear.

Let's see what we want to do in practice and then let's see how it happened (video follows)

Let's look at the solution to this problem. We'll need to use the 'Broadcast' command and the 'When I receive a message' command.

Soon we can say that once the points reach 10, the banana character (which measures the points) shows the message "10 points".

Any character can communicate messages.

Messages are streamed to all sprites.

In order for the sprite to hear this message, in our case Gas, it must dispose the event "When I receive the message".

Let's now see how we have achieved the appearance of the "Gas" object at the right time.

Perform actions multiple times

Video - Perform actions multiple times

Video Transcript

Good evening.

3rd in a row but equally important with the previous 2 programming structures is the repetition structure.

If we want some actions to be executed many times then we should be able to use commands of that particular structure.

Let's listen to Steve on an extremely interesting video.

 

Hello,

Often, as developers, we want some instructions to run again and again. Repeat them several times.

Let's look at a very simple program I've created to show you just that.

First let's run the script and see its effect in our setting.

You see how our sprite repeats some actions.

Let's take a look at the code. Indeed, we see that this command block is repeated three times.

We can repeat these code lines as many times as we want.

In this way, however, we create very large scenarios that are difficult to read and change if needed.

Instead of writing again and again the same commands we can set up running as many times as we want if these commands enter a block of repeats.

Let’s have a look…

A block of commands can also be repeated even if we do not know the exact number of repetitions. It can be repeated until something happens.

It can be repeated until something happens.

On my screen you will see the same scenario as before, only now the repetition is done with the command "Repeat until".

See the same lines of code. Repeat until the variable counter is equal to 10.

Note that the variable “counter” which initially gets the value 1 and after executing the repeat block its value rises by 1.

This keeps repeating until the value of the variable is 10.

Repetition is used too often in computer programming.

It is always used when we have to create games by programming.

In all games, we always want to be happening.

For example, remember the game we  discussed in the previous lesson.

Remember that throughout the game, when the monkey touches a banana the score raises and the bananas moves to another point of the stage.

We want action like this throughout the whole game.

The instructions that perform these actions must be in a repeat mode.

Because we do not know how long the game will take in order to set the exact number of repeats, nor can we define an event that these instructions will run until it is done easily, the instruction FOREVER.

The "forever" instruction is a repeat command that is used very often in scratch game programming.

In the game we mentioned earlier and we will create in the next lesson, it is used in every sprite.

Let's have a look.

Music please..

Actions only if something happens

Video - Actions only if something happens

Video Transcript

Good evening.

Many often we want to perform some actions only if something happens that is a certain event occurs.

If this does not happen then it is most likely that we do not want these actions to be performed.

For instance we say:

IF it rains THEN I will open the umbrella

The action "I will open the umbrella" will only be executed if it rains. If does not rain the umbrella probably will not open.

We almost always have to deal with such choices in computer programming.

We only want to execute some commands if a specific event occurs.

This is exactly the subject of today's lesson.

The programming concept described above is the "Selection Structure"

Let's listen to Stevie and what he has to say about this matter

 

Hello

Often when we create scripts, we want some instructions to only run when something occurs.

IF something specific occurs THEN some instructions should be executed.

Are you confused?

I am sure that with the next example you will understand what I mean.

Please display the program that I have prepared ...

Although as you see the script is small - it contains some commands you probably have not seen before.

First let's run the script to see what is happening..

You see how the sprite asks the user.

We have accomplished this with the "ask and wait" instruction from the pallet “Sensing”.

As you see the program waits for the answer.

Once I type my age it will be stored in the variable “answer”.

I did not make the variable "answer". It is a ready-made variable in scratch.

No matter what answer I give - it will go into the box named "answer".

Let me type my age ..

The message "You are a minor" appears. Let's run the script once more.

I will give an age of over 18.

You see that nothing happens.

Observe the instructions now .. The "You are a minor" message is within the IF instruction.

The "you are a minor" message will only be shown if the answer is less than 18.

As is the case. You saw that it is not running if the value is greater than 18.

Let's change the script so that the message "You are an adult" appears in the corresponding case.

We still need an IF instruction to check the other case.

Let's run the script now.

You may have noticed that by entering the value 18 no message appears on the screen.

Try in your own scratch window another IF or other change in the code in order to fix this little gap in the Script.

Instead of using a lot IF instructions you could use the instruction IF - then ELSE.

Watch the same scenario in the next few seconds but with the command IF then ELSE.

I think you understood it and became wiser with this video, isn’t that right?

Write in the scene

Video - Write in the scene

Video Transcript

Good evening.

In order to cook an omelet you must execute specific steps in the right row.

First you have to buy the eggs then break them, shuffle them into the cookware etc.

These steps must be done in a row without being mixed up. Each step will be executed after the previous one is completed.

This is the function and sequence structure in computer programming.

I'll let Stevie describe it in more details.

 

Hello,

When you want to create a scenario in scratch or in any other programming

language, you should think of the steps that will be carried out in a row, one after the other.

Instructions are executed in a row. Each instruction is executed after the completion of the previous one.

Let's have an example.

Let me show you the program I have prepared for this reason (finger clapping).

I also need a way to get into the screen... (fingers clapping)

In this scenario assigned to the scratch cat as you see, are mainly used instructions from the pallet “Motion” and “Pen”.

The “Pen” palette has instructions which allow the sprite to draw patterns in the stage.

Note how the instructions run one after the other in a sequence.

Note how each instruction is executed after the previous one has finished running.

With this scenario, the cat creates a gray square.

Let's run the script to see the result in the stage.

Let's run the script again step by step in order to understand what each instruction does exactly.

I will move the cat here and modify its size.

Just run the first instruction now. You see how the cat's size restores at the one we set up.

There is no result when executing the 2nd order.

What happened was that we raised the pen so that the cat did not draw when it moved.

If we had not executed this command then the cat would draw each time it moved to the original square position.

So take a look..

Once the pen has been raised, the command “clear” will be executed so that any old drawing is erased and then the command that moves the sprite to the start position for the square design.

With the instruction “pen down” nothing seems to be done.

But we know that the next move will leave its trace.

With the next instruction we define the color of the pen.

With the next 4 instructions, we create the square ...

Points and Other Information in our Games

Video - Points and Other Information in our Games

Video Transcript

Hello

In this lesson, Stevie will talk about the “variables”.

Variables are a programming concept that is used in all programming languages.

Understanding the meaning and usefulness of variables is essential to the progress of these courses.

Watch this video more than once, freeze the picture wherever you need to read the texts more carefully and of course try the presenter's suggestions in your Scatch window.

Have fun.

 

Good evening!

In most computer games, the leading heroes collect points.

Suppose we create a game where a monkey is seeking bananas to eat.

But it must avoid the lions who are hunting to eat the monkey.

Every time the monkey eats bananas it earns points.

Let's see a few snapshots of such a game ...

You see how the score value changes whenever the monkey achieves its goal.

That is to eat a bunch of bananas.

The score is a variable. It is named so because the value it contains can vary during the execution of a program.

We can imagine the score as a box in our computer that at any moment may contain a different value. This value can change in a number of ways.

The programmer may set to decrease it when something occurs (for example, when the lion touches the monkey) or increase it in another case, as the programmer invents using his imagination.

Because the programmer can’t know at any moment the value he has in that box, as it can change in many ways, when he wants to use this value instead of the number he uses the box name.

Each time the programmer uses the word “score”, he chooses the number he has inside, whatever this number is.

Let's look at the game for a few seconds but from another perspective.

So we have five sprites. The bananas, the monkey and the 3 lions.

If we click on the lions to see the script assigned to each one,we will notice that each of them has a different script that allows him to have a different behavior in the game.

Let's see this in practice.

Note how the speed of lions varies.

One goes very slowly, the other a little faster and the third even faster.

If you become a little more careful you will see how the speed of one of the lions grows as the score rises.

Let's now look at the code, the way the variable score is used.

In the banana scenario, you see how the original score value is set to 0.

So every time a new game starts, the score will start from the beginning.

The following lines contain codes that will be discussed in more details in one of the following lessons of this section.

Now we can say that these lines set the number containing in the variable score changes by +1 every time the banana touches the monkey.

That is, if the variable score contains the number 0, once the banana touches the monkey - it will become 1,if it happens again, it will become 2 and will continue to increase in this way.

In the 1st and 3rd lion the variable score is not used at all.

But the second lion is the one that changes its speed according to the score.

With these lines we can achieve this result.

You see how the programmer adjusts the lion's movement according to the value of the variable score.

Note how the variable score is used. With the instruction

Move (score / 4) steps, the programmer, of course, instructs the object to move as many steps as contained within the variable score divided by 4.

As the score value increases with the evolution of the game, the lion's movement will be greater.


The Heroes Positions in the Stage

Video – The Heroes Positions in the Stage

Video Transcript

Hello

The following courses refer to very important programming concepts.

Their knowledge will help you build strong foundation in order to understand computer programming.

All you have to do now is to freeze this video and open Scratch in another window.

It is essential to try anything that Stevie suggests. This is the only way that will help you achieve the goals of this lesson.

Remember that the more time you spend with this application the better you become!

So remember. We often freeze the image and try at Scratch.

Stevie you can start ..

 

Hello

The programming concept we will discuss in this lesson is the “coordinates”.

Coordinates are a very important programming concept as they determine the location of sprites in the stage.

Understanding them will help you create games using scratch.

Gas! I will need your help with the screen.

The scratch stage has 480 pixels length and 360 pixels height.

In order for the programmer to determine the precise location of a sprite in the scene, he should accurately specify its coordinates.

The coordinates are 2 numbers. The first number, named X, defines the horizontal position of the sprite in the stage.

The second is named Y and defines the vertical position of the sprite in the stage.

The values that the X coordinate can take are between -240 and 240.

If it has a -240 value then it is somewhere on the far left of the stage.

If it has a value of 0 is in the middle of the stage and if it has a value of 240 it is on the right edge of the stage.

The corresponding values of the Y coordinate are from -180 to 180.

If the sprite has a value of Y = -180 then its position will be at the lower end of the stage and if it is 180 at its upper end.

To determine the exact location of a sprite, we specify its coordinates as a pair.

The position (0,0) means that X = 0 and Y = 0 and is located exactly in the center of the stage.

Now let's move on to the scratch program to see how things work in practice.

As soon as the program starts, it is in the new project by default,

Here you 'll find a sprite named: "Sprite1". It is our well-known cat.

The name of the item is visible here and we can change it if we want.

Usually we change the name of each item that we use according to its shape.

Let's change it to "cat".

Note how the cat's position seems to be in the center of the stage.

Its exact position is determined, as we previously mentioned, from its coordinates.

As you can see, it's at 0.0.(zero point zero)  That is precisely in the center of the stage.

I can use my mouse to move the cat to whatever point I want on the stage.

Watch how the X and Y values change as i move it.

Let me leave it here.

Let me now try to change the position of the cat by creating a scenario for it.

The blocks I use are blue.

I will try to experiment for a while with these instructions.

After watching my moves I recommend you do the same in your own Scratch

window.

Music please ...