Tilt Monster - Adjusting the Games Level of Difficulty

Written by Paul Allan Harrington

This is my second post related to products we are working on at VisualsWork.com that will be incorporating many of the features and game play of Jonathan and Biffy Beebe's (http://beebegames.kodingen.com/) open sourced Tilt Monster app ( http://developer.anscamobile.com/code/tilt-monster).

For this installment we will be making adjustments to the games level of difficulty.

As we review the code Jonathan authored we see just how easy he has made it to modify the code that controls the games level of difficulty. Around line: 4862 in maingame.lua you'll notice Jonathan created a local function called "gameInit". Within that function we find the following code:

     if difficultySetting == "0" then
          -- Medium
          gameSettings[ "difficulty" ] = "medium"
          gameSettings["gameMoveSpeed"] = 7.7
          gameSettings["defaultMoveSpeed"] = 7.7

          print ( "Difficulty: Medium" )

     elseif difficultySetting == "1" then
          -- Easy
          gameSettings[ "difficulty" ] = "easy"
          gameSettings["gameMoveSpeed"] = 7.3
          gameSettings["defaultMoveSpeed"] = 7.3

          print ( "Difficulty: Easy" )

     elseif difficultySetting == "2" then
          -- Hard
          gameSettings[ "difficulty" ] = "hard"
          gameSettings["gameMoveSpeed"] = 8.1
          gameSettings["defaultMoveSpeed"] = 8.1

          print ( "Difficulty: Hard" )
     end

Jonathan has made it very easy for us. All we need to do is modify the appropriate "gameMoveSpeed" and defaultMoveSpeed" values for each of the 3 difficulty levels; "Medium", "Easy", and "Hard".

For our games intended audience we will be testing the following values: ("Medium" = 6, "Easy" = 3, "Hard" = 8

Example:

     if difficultySetting == "0" then
          -- Medium
          gameSettings[ "difficulty" ] = "medium"
          gameSettings["gameMoveSpeed"] = 6
          gameSettings["defaultMoveSpeed"] = 6

          print ( "Difficulty: Medium" )

     elseif difficultySetting == "1" then
          -- Easy
          gameSettings[ "difficulty" ] = "easy"
          gameSettings["gameMoveSpeed"] = 3
          gameSettings["defaultMoveSpeed"] = 3

          print ( "Difficulty: Easy" )

     elseif difficultySetting == "2" then
          -- Hard
          gameSettings[ "difficulty" ] = "hard"
          gameSettings["gameMoveSpeed"] = 8
          gameSettings["defaultMoveSpeed"] = 8

          print ( "Difficulty: Hard" )
     end

Also take a peek around Line: 212 at the local gameSettings table and notice:

     defaultMoveSpeed = 7.7, --> set to 3.7 for 60 fps; 7.7 for 30 fps
     gameMoveSpeed = 7.7,

You will likely what to change those values (currently 7.7) to the default of your choice. In our case, we will be testing a default value of 3.

Give it a try and feel free to contact me if you have questions, comments and suggestions.