Game menu

I made a game menu that you can use for a game.
This is the first thing I have programmed in codea
I’m sure there are easier wasys of doing the things I did, but this is the first thing I’ve made


function setup()
    timer = 0
    SceneGo1 = false
    GameStart = false
     gsx=900
    DEV_MODE = false
    menu=true
    start=false
    y1 = 515
    yrect = 440
    y2 = 515
  displayMode(FULLSCREEN) --May be made into FULLSCREEN_NO_BUTTONS, thats why theres a dev mode
end
function draw()
    background(134, 216, 244, 255)
    if menu==true then
        fill(0, 0, 0, 255)
         text("Welcome",515,550)
        fill(31, 183, 243, 255)
        rect(440,155,150,100)
        fill(0, 0, 0, 255)
          text("Tap here to begin",515,200)          
    if CurrentTouch.state == ENDED and CurrentTouch.tapCount == 1 and CurrentTouch.x >= 440 and CurrentTouch.y >= 155 and CurrentTouch.x <= 615 and CurrentTouch.y <= 270 then
            menu = false
            start = true
        end
    end
    if start == true then  
        y1 = y1 - 2
        yrect = yrect - 2
        y2 = y2 - 2
      if gsx < 901 and gsx > 514 then
          gsx = gsx - 2
       end
            background(134, 216, 244, 255)
      zLevel(-3)
          fill(0, 0, 0, 255)
        text("Welcome",y1,550) 
        fill(31, 183, 243, 255)
        rect(yrect,155,150,100)
        fill(0, 0, 0, 255)
          text("Tap here to begin",y2,200)       
         text("Made by Mason",gsx,375)
         if gsx < 901 and gsx > 514 then
            SceneGo1 = false
            else 
            timer = timer + 1
            if timer == 100 then
                SceneGo1= true
            end
        end
        if SceneGo1 == true then
            gsx = gsx - 2
        end
        if gsx <=0 then
            GameStart = true
        end    
           zLevel(3)
          fill(134, 216, 244, 255)
        rect(-1,-1,300,7000) 
        
                   zLevel(3)
          fill(134, 216, 244, 255)
        rect(800,-1,300,7000) 
        
    end    
        if GameStart ==  true then
        fill(0, 0, 0, 255)
            text("Game here",515,400)
        end
      if DEV_MODE == true then
        fill(0, 0, 0, 255)
          text("close",1000,15)
        if CurrentTouch.x >= 995 and CurrentTouch.y <= 15 then
            close()
        end
        end
end


@Mason Nice job. It’s a good start to many more things you’ll be writing.

Hi @Mason - well done for getting this far. I have a suggestion.

Why not store the game “state” in a variable, and set it to a constant that tells Codea what to draw. For example, in setup

States={MENU=1,START=2,PLAYING=3,ENDED=4}
state=MENU  --sets state to 1

and then in draw

function draw()
   if state==MENU then DrawMenu()
   elseif state==STARTPLAYING then DrawStartPlay()
   elseif state==PLAYING then DrawPlaying()
   elseif state==ENDED then DrawEnded()
   end
end
--and you have a separate function for drawing each state, as named above, eg
function DrawMenu()
    fill(0, 0, 0, 255)
    text("Welcome",515,550)
    fill(31, 183, 243, 255)
    --etc
end

This approach makes your code much cleaner and easier to read and change. It also makes it easy to add new states.

This is the way many, if not most, games are designed. It is called a “finite state” design, because the game can only be in one state at a time.

More here
http://codeatuts.blogspot.com.au/2012/07/tutorial-5-finite-state-machines.html
http://coolcodea.wordpress.com/2013/05/04/47-game-template/

@ignatz: what makes a FSM like your above post better than something like…

function setup()

mode = Menu()

end

function draw()

mode:draw()

end

function touched(t)

mode:touched()

end

Then you’d have a class Menu, and from there you could change mode to another class such as a main game class, or tutorial class, ect…

What’s the benefit from an FSM vs the way that I normally do it?

The user and all related content has been deleted.

@Invad3rZIM - you are using classes, which is fine, but I understand that @Mason is still starting out, so what I did is easier to program.

@NatTheCoder - what is awesome?