Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
L÷VE for Lua Game Programming

You're reading from   L÷VE for Lua Game Programming If you want to create 2D games for Windows, Linux, and OS X, this guide to the L?ñVE framework is a must. Written for hobbyists and professionals, it will help you leverage Lua for fast and easy game development.

Arrow left icon
Product type Paperback
Published in Sep 2013
Publisher Packt
ISBN-13 9781782161608
Length 106 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
AKINLAJA DAMILARE JOSHUA AKINLAJA DAMILARE JOSHUA
Author Profile Icon AKINLAJA DAMILARE JOSHUA
AKINLAJA DAMILARE JOSHUA
Arrow right icon
View More author details
Toc

Head-Up Display (HUD)


The HUD can be described as the graphical interface for displaying the game information such as life stat, player score, and so on.

Menu HUD

Here we'll simply create a "Start Game" and "Quit Game" button with text, but before we do that we have to set up game states— a type of state machine that tells the various modes of a game whether the game is at the menu mode or is currently playing (game-play mode).

In the love.load() function, set a game state as menu, so whenever the game loads its first state is the menu.

function love.load()
gamestate = "menu"
love.graphics.setBackgroundColor(225, 153, 0)
-- load the level and bind the variable map
  LoadTileMap("tilemap.tmx")
end

Next, we are setting another gamestate condition; game should update and draw only when game state is "playing":

--Update them
function love.update(dt)
  if gamestate == "playing" then
    bump.collide()
    PlayerMovement(dt)
    EnemyUpdate(dt)
    CoinUpdate(dt)
    DiamondUpdate(dt)
    LifeUpdate...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime