Level 13 – Lesson 04 [Game Loops n Lists]

Introduction
In this lesson you will be introduced to how you can combine your knowledge of loops and lists with the lists of game objects that GameMaker is keeping track of for you.  Lets walk through a few examples of using the instance_find script from earlier lessons inside of loops.

Part A – Fire At Closest Monster
Watch the Video:  13-04-A
Done-File: 13-04-A-Done.gmk


Part B – Splash Damage
Watch the Video: 13-04-B
Done-File: 13-04-B.gmk


Part C – Move Towards Weakest Monster

Watch the Video: 13-04-C
Done-File: 13-04-C.gmk


Challenge 1 – Repel Tower
Use the file 13-04-X1-Start.gmk
Add code to the repel tower ‘press space bar’ that uses a loop to go through all the monsters and repel each one.  For a simple repel, make monsters to the left of the tower move leftward, and monsters to the right of the tower move rightward.  If you think you are really good, make the monsters move away from the tower as if they are actually repelled.

Solution
Solution Video: 13-04-X1-Solution
Solution File: 13-04-X1-Done.gmk


Challenge 2 – Repel Tower Mod

Continue from your Challenge 1 File.
Make a simple modification so that only monsters with a shield value less than 50 are affected by the repel tower.

Solution
Solution Video: 13-04-X2-Solution
Solution File: 13-04-X2-Done.gmk

There we go!