To load a level, you will create a new method for it. Depending on how the field levelNum
is set, it will load a corresponding text file into a string variable. This will then be split up so we can determine the ID of each tile.
1. Create a new method inside the
game
class, calledLoadLevel
.Method LoadLevel:Int()
2. Set the default layer for new objects, from now on, to
layerGame
.eng.SetDefaultLayer(layerGame)
3. Remove all objects from the game layer, and reset the number of crates and the number that are on target.
layerGame.RemoveAllObjects() crateNum = 0 onTarget = 0
4. Next, load the text file and store the result in the local
String
variablelevelText
.Local levelText:String = LoadString("level"+levelNum+".txt")
5. Split each line of the string into a string array. For this, use the NewLine ASCII character code (
10
).Local lines:= levelText.Split(String.FromChar(10))
6. Determine how many lines (rows) a level has.
Local ly:Int = lines.Length(...