LuaSTG Pattern Making Tool-Part I Exercises

From LuaSTG Wiki
Jump to navigation Jump to search

In this page I provide some exercises of part I sorted by the index of the tutorial.

Using For Loops[edit | edit source]

These exercises will be referring to the two examples on the page Using the For Loops. Recall the first example is a simple for loop generating a ring of bullets, the second example is about nested for loops.


1. In the first example, SpawnBulletByTable calls can be substituted by SpawnBullet calls. Re-write the example using SpawnBullet.

2. In both examples we've incremented at least one of four spawn parameters in the loops. Why would it not be a good idea to not incrementing them at all?

3. Consider changing the value of the increments in a single for loop. What is the shape of a pattern if the increment of x is a non-zero value and all other increments are zeros?

4. In the first example all bullets have the same sprite "Arrowhead.jpg". Perhaps one may want to re-write it so half of the bullets on the ring has a different sprite, say "PurpleArrowhead.jpg". How would you do this? There are no restrictions on which bullets have which specific sprite. Be careful about table pollution. (Hint: since the loop variable i is different for each bullet, you can test its value inside the for loop to decide which sprite to use)

5. Write a for loop to spawn bullets on a circle of radius r.

6. Instead of a circle, if you are going to spawn bullets on a n-polygon shaped pattern, is it better to use a single for loop or a nested for loop? Why?

7. Suppose you want to spawn bullets at a single point and from that point expand into a n-polygon shaped pattern. Is it easy to use SpawnBullet to generate the pattern? Why? Think about the parameter choices. What could have been used in SpawnBullet instead of a and v?

Parametrization[edit | edit source]

Consider the following SpawnSplitter function.

A Function that Spawns a Bullet that Spawns Smaller Bullets


1. What parameters of the function can be incremented?

2. Suppose you want to spawn 20 such bullets, the ith one (0 <= i <= 19) will spawn at 2d position (0, 60); it will move downwards with speed 2 distance unit per frame and after t = i * 6 frames split into n = i + 1 bullets. Write a for loop that calls SpawnSplitter to do this job.

3. Parametrize the for loop you wrote in the previous exercise into a function SpawnMultipleSplitters, call the function to do exactly the same thing as the previous exercise by filling its parameter list.