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

Score HUD


Whenever a player hits a coin, kills a player, or picks a diamond, we would need to increase their score by 50, 100, and 150 respectively.

local score = 100
---when player picks coin
function CoinPick(v)
  v.picked = true
  CoinPicked = true

  score = score + 50

end
---when player picks coin
function DiamondPick(v)
  v.picked = true
  DiamondPicked = true

  score = score + 150

end
---when player kills enemy score 100, else remove 100
function collideEnemyWithPlatform(dx,dy,v,obj)
  if obj == player then 
    if (player.t + player.h < v.t + 2) then
      EnemyDie(v)
      Score = score + 100
    else
      Die()
      Score = score - 100 
    end
  end


end
We can now update the love.draw function to print the Life and Score on the screen:

function love.draw()

  if gamestate == "playing" then

    love.graphics.print("Life:"..life, 32, 32)
    love.graphics.print("Score:"..score, 320, 32)

    love.graphics.setFont(medium)

    map:draw()

    DrawPlayer()

    DrawEnemy...
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