lunes, 29 de febrero de 2016

Breaking Fast: Menu Navigation

Hi all!

Breaking Fast is moving forward. This last week we worked on the menu navigation part, which includes the menu screens through which players navigate until the race begins. As for the technical side, I want to discuss the two main issues you have to consider when implementing this aspect of a game: how to manage the flow between screens, and how to pass information among screens. Let's get started!

Flow Management Schemes

There are two main "schemes" (I can't think of a better word) during menu navigation. In the first scheme, each screen is actually a different screen. This implies that, upon changing among screens, we swap the contents of one screen with the contents of the other screen. This can be implemented as a function in the screen manager:

 function changeScreen(newScreen)  
  currentScreen.unload()  
  currentScreen = newScreen  
  currentScreen.load()  
 end  

In order to manage transitions among screens (i.e. the implementation of the screen manager), it is useful to think of Finite State Machines. You can watch a series of two videos that I prepared for gaining insight on the matter.



 
In games it is also very common to use another scheme, in which the contents of different screens are all drawn, but only one of them has the focus at any moment. Think for example of a racing game in which you have to choose a scenario and then, the time of the race. You can implement this by using the aforementioned scheme, but it feels kind of overkill to unload one screen and to load another one just for the purpose of selecting the time. It seems more natural that the same screen presents both options, but that the player can only change one of them at any time. Actually, we can stop thinking of different screens in this situation. This "move the focus" approach can be implemented by means of screen phases or states

In particular, in Lua, we can hold a table of states, and we iterate over this table in order to draw and update the screen. We also have a variable that holds the value of the current state (the current focus), and we delegate the interaction of the player (be it with the keyboard or a gamepad) to the actual focused state. Some self-explanatory code is shown next:

 function load()  
  table.insert(states, state1)  
  table.insert(states, state2)  
  currentStateFocus = state1  
 end  
 function draw()  
  for _, v in ipairs(states) do   
   v.draw()  
  end  
 end  
 function update(dt)  
  for _, v in ipairs(states) do   
   v.update(dt)  
  end  
 end  
 function onKeyPressed(key)  
  currentStateFocus.onKeyPressed(key)  
 end  

Communication between Screens and States

Passing information among screens is essential. In particular for Breaking Fast, consider the following flow of actions:
  1. Players select the characters that will participate in the race.
  2. Players select the scenario in which the race will take place.
  3. Players select the duration of the race.

Consider the figure above, in which we mix the two menu navigation schemes explained before. Each transition among screens and states conveys both new information and the information carried by older transitions. In the end, when we prepare the race screen, we need to know all the options that have been chosen by the players through the different screens. Fortunately, implementing this in Lua is very simple thanks to a powerful feature of the language: function overriding of imported modules. Consider the following module, which models the Time Selection State:

 local timeSelectionState = {}  
   
 -- other functions  
   
 function timeSelectionState.toScenarioSelection()  
 end  
   
 function timeSelectionState.toGame(timeChosen)  
 end  
   
 return timeSelectionState  

As you can see, we are defining two empty functions. Any module that imports this module can re-define (i.e. override) these functions. So for example, consider the Scenario Selection Screen module, which contains the Time Selection State:

 local scenarioSelectionScreen = {}  
   
 -- other functions  
   
 function timeSelectionState.toScenarioSelection()  
      currentStateFocus = scenarioSelectionState  
 end  
   
 function timeSelectionState.toGame(timeChosen)  
      for _, v in ipairs(states) do  
           v.unloadResources()  
      end  
      scenarioSelectionScreen.toGame(numberOfPlayers, playersInfo, scenarioChosen, timeChosen)  
 end  
   
 function scenarioSelectionScreen.toGame(numberOfPlayers, playersInfo, scenarioChosen, timeChosen)  
 end  
   
 return scenarioSelectionScreen  

As you can observe, this module re-defines toScenarioSelction() and toGame() functions. In particular, toGame() unloads all the states of this screen, forwards the racing time that has been chosen by the player, and pads it to more information accumulated during previous phases. In turn, scenarioSelectionScreen defines an empty toGame() function that cam be re-defined by the module importing it. This latter module could therefore add some more information and pass it to the Race Screen.

And this is it! As always, I hope you enjoyed this tutorial, and if you have any question, don't hesitate to ask! Any feedback is also well appreciated.

See you!
FM

16 comentarios:

  1. MS Office setup is very easy to install, download and redeem. Use of MS Office is also simple and the user can learn the use of it easily. Online help option is also available in all application of the MS Office which provides an instant guideline.
    office.com setup
    www.office.com
    www office com setup

    ResponderEliminar
  2. How you install or reinstall Office 365 or Office 2016 depends on whether your Office product is part of an Office for home or Office for business plan. If you're not sure what you have, see what office.com setup products are included in each plan and then follow the steps for your product. The steps below also apply if you're installing a single, stand-alone Office application such as Access 2016 or Visio 2016. Need Help with office.com/ setup Enter Product Key?
    office.com set up
    office com setup
    microsoft office product

    ResponderEliminar
  3. McAfee provides security for all sorts of users. They supply services and products for home and office at home, enterprise businesses with over 250 workers, and small organizations with under 250 employees, and also venture opportunities.


    mcafee.com activate
    mcafee com activate
    mcafee activate

    ResponderEliminar
  4. We are providing help and support for Microsoft office Setup and activation. Call us or email us the error or problem, our one of the expert contact you with the suitable perfect solution. Get the MS Office application suite and as per your need and see how it is easy to work with Microsoft Office.


    Office.com setup
    www office com setup
    Install Office

    ResponderEliminar
  5. setup.office.com

    Before you plan to install the Office 2016 or Office 365 on your device be it a Computer, Laptop, Mobile Phone or a Tablet, you are required to take few important steps on of them is to remove any existing Office installations from your PC. Just like the previous Office products, Office 2016 & 365 will conflict with the previously installed versions. So, it becomes necessary to remove the previous office files properly.


    setup.office.com
    www.office.com/setup
    office.com

    ResponderEliminar

  6. www.office.com/myaccount

    To Setup retail card please visit official website Www.Office.Com/Setup. Office Retail Cards allow you to download your security product from the internet instead of installing from a CD, ensuring recent versions.


    www.office.com/myaccount
    www.office.com/setup
    Microsoft Office product

    ResponderEliminar
  7. Microsoft office setup is the software setup file with this setup file you can install on your computer and some of the supported device to use Microsoft office.
    www.office.com/setup
    office.com/setup
    office com setup

    ResponderEliminar
  8. Microsoft Office setup has various products for various purposes.These versions include office setup 2016, office setup 365, office setup Home & Student and much more. For All these products you will need a Microsoft office account to access the full features of office setup. If you use services like Outlook, OneDrive, & Skype then you should definitely have a Microsoft account.
    www.office.com/setup

    ResponderEliminar
  9. Download and install your Norton product on your computer. Sign In to Norton. If you are not signed in to Norton already, you will be prompted to sign in. In the Norton Setup window, click Download Norton. Click Agree & Download. Do one of the following depending on your browser:
    ‎Install Norton from your service


    www.norton.com/setup

    ResponderEliminar
  10. www.office.com/setup
    How to Install or Download Microsoft Office
    You Have a Two option Where you Can Purchase this Product
    1.Shop

    if You will purchase a Microsoft office From Store You will get a Gift card Over there on the back you will find a Black strip there which you have to remove By a coin or anything else Then you will see there a 25 digit key code which you have to use.First you have to open a internet browser Then type www.office.com/setup Then you will see two options sigin or create account. If you already have an account you have to use your email & password then you will get a Key box where you have to enter the key which you got from store & then click next & follow screen options.

    2. Online (Internet like Microsoft official website,amazon,ebay etc)

    How To use Download The Product Which you Bought Online.Whenever you bought Office Product Online You have to put in your email where you get Your Payment receipt in your email aaccount & use the same email for Your Microsoft account Also you will recive Your 25 Digit Key code in your email Just copy that Key & Go to internet Browser & type there www.office.com/setup Then you will see a official website it will ask you to Enter Your 25 digit Key Enter it & follow Screen options .I hope We Gave you easy Steps through which you can install Microsoft office By yourself.Thank you!

    ResponderEliminar
  11. How to reset a aol password. Open your aolmail.com in your web browser. Click Sign in. Click Forgot your password? Enter the email address you used to create the account. You'll need access to this email account to reset your password. Check your email inbox, and click the link in the email you received to reset your password.
    www.aolmails.xyz/aol-mail-help
    aol mail
    aol mail help

    ResponderEliminar
  12. Insert the Microsoft Office media disc into the DVD drive. Click "Start" followed by "Computer." Double-click the disc drive if Windows fails to launch setup automatically. Enter your product key when prompted and click "Continue."
    www.office.com/setup

    ResponderEliminar