Category Archives: Level 15

Level 15

Level 15 Intro

You have learned how to store numbers and text using variables, lists, maps, and grids.  In this level you will learn one final way to store values – Arrays.

Arrays are common to almost all programming languages.  Arrays allow you store many values under one variable name.   Arrays are similar to lists, but more simple to use.  There are certain game tasks that just don’t need the complexity of using the scripts that go along with lists.  That’s when arrays are great to use.  Lets go learn how to use arrays and show you some examples of how arrays can make your games easier to code.

Level 15 Lesson 01 [ Arrays ]

Introduction
A variable is great at storing one value. But is it possible to store several values under one variable name? Of course. One option you have explored in Level 13 is the list data structure. In this level we will take a look at arrays and how they can make certain game tasks much easier and efficient to code. Almost every programming language makes use of arrays because arrays are awesome.

Part A – What is an Array?
Watch the video: 15-01-A
Done File: 15-01-A-Done.gmk


Part B – Three Simple Array Game Examples
Watch the video: 15-01-B
Done File: 15-01-B-Done.gmk


Challenge 1 – Dropper

Start with the project file 15-01-X1-Start.gmk

All the monsters have a parent object called o_monsterParent. Currently when you click on a monster it is destroyed. Add code to the o_monsterParent mouse pressed event that will randomly generate a dropped object such as a potion, apple, or gold when a monster is destroyed. Use an array to store the possible dropped objects and randomly select from this array when deciding which object to drop.

  Solution Video:  15-01-X1-Solution
  Solution File:  15-01-X1-Done.gmk


Challenge 2 – Dropper Cycled

Start with the project file 15-01-X1-Start.gmk

Modify your answer to Challenge 1 (Dropper) so that the items dropped by the destroyed monsters cycle. For example, the first monster destroyed will drop a potion, then the second monster will drop an apple, the third some gold, and then the next monster will drop a potion, then the next an apple, then the next some gold – see the cycle?

    Solution Video: 15-01-X2-Solution
    Solution File: 15-01-X2-Done.gmk


Challenge 3 – Level Names

Start with the project file 15-01-X1-Start

a) Each time you mouse click on a monster to destroy it the script increaseLevelPoints is executed and it increases the level points by 1 (This is already coded for you!). When the level points reaches 3 you should reset the level points to 0 AND increase the global.level by 1 (the player has gone up one level). The highest level should be limited to level 3. Add this behaviour by adding code into the increaseLevelPoints script. No arrays are required for this part!

b) Use an array to keep track of the name of each level so that you can write the name of the level next to the level number when using the draw object that is already in provided in the project.

Level 1 : Noob
Level 2 : Warrior
Level 3 : Master

   Solution Video: 15-01-X3-Solution
   Solution File: 15-01-X3-Done.gmk