Discord
Login
Community
DARK THEME

end screen/title screen

I need a simple yet functional title and end screen. i already have sprites for them, but I need a way to make them work. I need that when you press space, you start, and when the and screen is showing, the game restarts after 5 secconds. The deadline is saturday and I'm stressing. Help please.

if you need a scene manager or a status manager, take a look at explore.

you can also do a restart like this: if keyboard.release.SPACE then init() end // restart

For a simple state manager, you can just use a variable:

init = function()
  state = "title"
end

update = function()
  if state == "title" and keyboard.release.SPACE then
    state = "play"
  elsif state == "play" then
    // update game
    if /* game over */ then
      state = "game_over"
      after 5 seconds do
        state = "title"
      end
    end
  end
end

You can also use objects with init(), update(), and draw() functions:

set_scene = function(new_scene)
  scene = new_scene
  scene.init()
end
scene_title = object
  init = function()
    
  end
  
  update = function()
    if keyboard.release.SPACE then
      set_scene(scene_play)
    end
  end
  
  draw = function()
    
  end
end
scene_play = object
  init = function()
    
  end
  
  update = function()
    if /* game over */ then
      set_scene(scene_game_over)
    end
  end
  
  draw = function()
    
  end
end
scene_game_over = object
  init = function()
    after 5 seconds do
      set_scene(scene_title)
    end
  end
  
  update = function()
    
  end
  
  draw = function()
    
  end
end
init = function()
  set_scene(scene_title)
end

update = function()
  scene.update()
end

draw = function()
  scene.draw()
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community