Home‎ > ‎

Winning and Losing and Keeping Score

What do you do when your player runs into a wall? or gets hit by a moving object? Do you end the game? start over? or just penalize the player with points or time?

Likewise, what happens when your player wins? Do you pop-up a box that congratulates them? Do you go to a card with fancy graphics and celebrations (animations?). Do you take them to a new but harder level? or Do you give them a chance to play again?

These are decisions that you have to make

1. Game Over - Won or Lost
Here you can pop-up a dialog box to congratulate them or tell them that they won or lost. And ask them if they want to play again.
Another option is to automatically send them to the next level if they win or back to the start if they lose. You would do this with a hidden button at the end (hide the button or set visible of button to false) and when they intersect with it, send them to another card (go to card "level2") or send them back to the start

If you decide to allow them the chance to try it again, you will need a Start or Reset button

2. Start or Reset Button
This button returns the player to the start of the game and resets everything (like scores, timers, sets things visible/invisible depending on how they were originall set, and other housekeeping duties

To make a Start button, drag over a button from the Tools Palette 
Name it - "Start" in the Property Inspector
Add the code to it's Script

    on mouseUp
        set the loc of button "box" to 50,100
        set the visible of the enemy "Dragon" to "true"
        ... and whatever else that you need to do
    end mouseUp

3. Keeping Score

It is fun to see how high a score that you can get. It makes games more fun and challenging. 

How We Do It

To keep a score, all you need is a "Text Entry Field". Turn off (unclick) the borders make it "opaque" so you do not see the text field, only the score.

Drag over a "label' field and a "Text Entry" field:

                       

Change the CONTENTS of the "label" field to "Your Score:" (The field's name does not matter because we will not access it. But the "contents" is what shows on the screen)
Name the "Text Entry" field - "Score"

              
                    
Then just "add" points to it when the player does something - like click a button, intersect with an object or reach a certain point.

  for instance,

     if you name the field "Score", you just add the line:

        add 10 to field "Score"

    to add points to it.

        e.g. 
              if intersect (button "box" , image "diamond") then
                  add 10 to field "Score"
              end if

Don't Forget to add a way to reset the score to zero (0) to start again:

    On a "Reset" or "Start" button, include the code:

             put 0 into field "Score"

    e.g.
               on mouseUp
                     put 0 into field "Score"
               end mouseUp

    to start the scoring over again

Comments