Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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

Life HUD


The life HUD will display the number of lives the player has left. We'll just do simple math to add life when a player collides with the life item, and subtract it when a player dies.

local life = 3

When a player hits the life item, the calculations are as follows:

life = life + 1

When s player dies, the calculations are as follows:

life = life – 1

Print the life count on screen using the following code:

love.graphics.print("Life: " life, 32, 32)
love.graphics.setFont(medium)

Now let's insert this into our main chunk:

life = 3
---when player picks life item
function LifePick(v)
  v.picked = true
  LifePicked = true
  
  lifebar = lifebar + 1
  
end
Now when player dies, update the Die() function:
---for now make the player re-spawn to position 32,32 on the tilemap when it dies.

function Die()

  life = life - 1

  player.l = 32

  player.t = 32
end
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