Game Programming‎ > ‎FlappyBird‎ > ‎

Flappy Bird - Turbo

Adding a Turbo mode - Two Ways

1. With a keyboard key

              
   1. Add a label field with the contents:

                    Press the "T" key for Turbo Mode
 

    2. On the card script, ,at the top add the new global variable - colSpeed where the other variables are

local birdDirection    
local gravity
local gameRunning
global colSpeed
        
      3. On the card script, in the "startGame" handler add the following:

                      put 4 into colSpeed

      4. On the card script, in the "moveCols" handler change the number 4 to colSpeed

     5. On the card script, in the "keyDown" handler add the following code:

on keyDown x
   if x is space then
      put -1 into birdDirection
      set the angle of image "bird" of stack "Resources" to 20
   end if
   if x is "t" then
      put 10 into colSpeed
   end if
end keyDown

           or  if you want it to speed up more than once, (add 5 every time they press the spacebar)

on keyDown x
   if x is space then
      put -1 into birdDirection
      set the angle of image "bird" of stack "Resources" to 20
   end if
   if x is "t" then
      add 5 to colSpeed
   end if
end keyDown

2. With a button

We can add a button to the screen to put the columns into a "Turbo" mode where they go twice as fast

                        


   1. Add a button called "Turbo" and put the following script on it
 
on mouseUp
    global colSpeed
    put 10 into colSpeed
end mouseUp

    2. On the card script, ,at the top add the new global variable - colSpeed where the other variables are

local birdDirection    
local gravity
local gameRunning
global colSpeed
        
      3. On the card script, in the "startGame" handler add the following:

                      put 4 into colSpeed

      4. On the card script, in the "moveCols" handler change the number 4 to colSpeed

on moveCols
  lock screen
   repeat with x = 1 to 4
      put the right of btn ("col"&x&"Top") - colSpeed into newPosition
      if newPosition < 0 then
         set the left of btn ("col"&x&"Top") to the right of card "FlappyBird"
         set the left of btn ("col"&x&"Bottom") to the right of card "FlappyBird"
         add 10 to field "score"
      else
         set the right of btn ("col"&x&"Top") to newPosition
         set the right of btn ("col"&x&"Bottom") to newPosition
      end if
   end repeat
   unlock screen
end moveCols

Comments