About FLL |
Navigation |
Playbook |
Strategy |
Models |
Techniques |
RobotC |
Programming |
Robot News |

genericShapes Module (genericShapes-ModuleScript.htm)

Copy the code from this page into the genericShapes module in your program.

The next step is to go to the Workspace in Roblox and add a Script. Rename that script: **startingScript** and paste the code in the example below.

We will be working with this starting script.

A game may become boring if the objects were in the same positions every time you played. So, we will introduce some degree of randomness.

Also, to make the gamer interesting, we will have various levels of difficulty in the task (starting easy and then becoming more difficult over time or more difficult with each level or layer completed).

For our first game, to get started, we will create an empty array to store "spheres". A zOffset will be used to create the collection of spheres in front of the avatar's spawn point.

In this first game, the layers of difficulty will be rendered as multiple layers of spheres.

A variable will be used to keep track of the current level.

A

The first time through the loop, the

This outer

The y-Coordinate for the spheres will start at 0.5 times the size of the sphere so that the bottom of the sphere will rest on the baseplate. The y-Coordinate will be incremented following the rendering of each layer of spheres. The increment to the y-Coordinate will be the square root of two which is approximately 1.414. This value is used as the increment to the y-Coordinate because a 45-degree angle is formed in stacking the spheres. This 45-degree angle creates an offset on the

The first time through the loop, the

The

As an experiment, try changing the

In math, we sometimes express the relationships between variables. For example, consider this math expression: **A = B***If A is 5, then what is the value of B if I know also that A = B?*

In trying to find the value of

to solve the equation, we often place the variable of interest on the left side of the "equals" sign. Therefore, we would re-write the expression as:

And then we would substitute the value for

That was simple. Now let's take this one step further. Consider the expression:

This would often be written as:

If

Since

The next step would be to take the square root of both sides of the equation which would give us:

As in the previous example, you can solve the equation for a specific term if you know the values of the other terms. For example, if you know the values of

From the previous lesson, we learned that Pythagoras discovered in 500 B.C. that the equation:

When stacking spheres in a pyramid (with a square base), this same formula can be altered slightly to identify the change in height for each layer of the pyramid of spheres. The alteration to the Pythagoras formula is very simple. If the formula:

To experiment with **right** triangles, explore the code below. Change the values of **A** and **B** to see different triangles.

Simple: each higher layer of the pyramid has spheres that are positioned exactly 1/2 of a sphere different from the lower layer. For example, the spheres in layer 2 of the pyramid are placed "inbetween" the spheres of layer 1. In other words, the center of a sphere in layer 2 is 1/2 of the diameter of the sphere different from the center of the sphere in layer 1. Run the program below to visualize this relationship between layer 2 and layer 1.

As you explore this Roblox example, notice that each row of spheres in layer 2 is in between two rows of spheres in layer 1. Each column of spheres in layer 2 is in between two columns of spheres in layer 1. Since the spheres in layer 1 are touching each other, the spheres in layer 2 are 1/2 the diameter of a sphere shifted on both the

Therefore

The equation for determining distances in 3-dimensional space is:

We can now start to fill in the values that we know:

We also know that

Now all we have to do is solve for

Replace terms with expressions representing the positions of spheres in the pyramid.

Add like terms:

Place

Rewrite as:

Cancel the "2" as:

Rewrite as:

In order to perform the subtraction, we need to make sure both terms have the same denominator. Multiply the first term by one as:

Rewrite the

Rewrite as:

Now you can perform the subtraction:

Rewrite as:

The expression on the left of the equals sign is still squared. Get the square root of both sides as:

The change in height (deltaY) of each layer of the pyramid is equal to the size of the sphere divided by the square root of 2. In summary, if you are building a pyramid of spheres (with a square base), each layer of the pyramid increases by:

In summary, when storing "user defined" data in an object you will use:

In our example, to store 1 point in a sphere object, we will use the following statement:

Your Leaderboard script should contain the following code:

This script creates a

If you examine the code above, you will notice that there is a parentheses after the

Answer:

The variable

Each object created in the game will include a function that will be triggered whenever something touches the object. Each time something touches a sphere, the

For our game, we will create a function that will be executed whenever something touches a sphere and in the function we will check to see if it was an Avatar "part" that touched the sphere--specifically one of the Avatar's feet. This means that you will need to kick or jump onto the sphere in order to score a point.

Once the Avatar jumps onto the sphere, the "

Advancing to the next game level will be conditioned upon clearing the game board of any available points. This means that each sphere needs to be cleared of its point value. However, because the spheres will eventually roll off the game board, the computer will also need to check to see if there are any spheres

The code excerpt below creates a variable to store the number of spheres on the board. Then it will enter a

A

Once there are no more points or spheres available, then the code will exit the

If you play the game now, using this code, you may notice that at higher

Also, after the pyramid is drawn, it might be nice to climb onto the pyramid for a few seconds before releasing them by setting their

Try to think of where you should make these modifications to the code.

Over the past several weeks, we've explored various small programs as exercises. Revisit some of these earlier programs and turn them into games by adding a Leaderboard, points attribute, and user interaction (i.e., jumpung by the Avatar).