Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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

Pickups


Let's give the player the task of picking stuff up while it's trying to avoid the antagonists. The pickup items will be in the form of coins and diamonds to reward the player, or up the player's lifespan. And by rewarding the player, we are adding to the player's score. These pickup items include the following:

  • Coins

  • Diamonds

  • Life

Now let's update our LoadLevel() function to load our items; we assume we have already added these objects in the Tiled map.

The items enlisted can be loaded into our game code as highlighted in bold text, similar to the way we loaded the player and enemy character inside in the LoadLevel() function, as shown in the following code:

function LoadLevel(levelFile)
  map = loader.load(levelFile)
  ---fetch gravity property from map
  gravity = map.properties.gravity
  --- set gravity to 1000
  gravity = 1000 

  FindSolidTiles(map)
    for i, obj in pairs( map("Objects").objects ) do

    if obj.type == "player" then PlayerSpawn(obj.x,obj.y-8) end
    if obj...
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