Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
L÷VE for Lua Game Programming
L÷VE for Lua Game Programming

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.

By AKINLAJA DAMILARE JOSHUA
$19.99 $13.98
Book Sep 2013 106 pages 1st Edition
eBook
$19.99 $13.98
Print
$32.99
Subscription
$15.99 Monthly
eBook
$19.99 $13.98
Print
$32.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Sep 25, 2013
Length 106 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782161608
Category :
Languages :
Table of content icon View table of contents Preview book icon Preview Book

L÷VE for Lua Game Programming

Chapter 1. Getting Started with LÖVE

LÖVE is a fantastic framework that leverages the Lua scripting language for developing 2D games; it is open source, free to use, and licensed under zlib/libpng. You can learn more about Lua programming at www.lua.org.

In this chapter we'll go through the following:

  • All we need to get started with LÖVE

  • How to install LÖVE

  • How to run a LÖVE game

  • Choosing the editors

And a step further to understand the basic structure that makes a LÖVE game.

Downloading LÖVE


Before we build our game, we need a copy of LÖVE's engine running on our computer; a copy of the framework installed will help the computer to interpret the code we will be writing.

Direct your web browser to www.love2d.org, scroll to the download section of the site and choose the installer that is compatible with your computer.

It is advisable that we download an installer instead of the source codes, except for when we want to be geeky and build it ourselves.

For Windows users


When you are through with downloading the installer, run the setup and follow the instructions.

When your installation is complete, run the program; you should see a the window displaying a beautiful animation on the screen.

For Linux users


Linux users are required to download the .deb install file by clicking on build number of their operating system; users running Precise Pangolin Ubuntu OS should click on the 12.04 link. Run the install program and follow the instructions. If the LÖVE framework is fully installed, you can double-click on a .love file to run it.

For Mac users


Mac users should visit the LÖVE wiki (https://www.love2d.org/wiki/Getting_Started) page for instructions on how to install LÖVE and run a packaged game.

Choosing your editor

In choosing a suitable editor, you can use any text editor that supports the Lua programming language; we recommend Notepad++; it is free and has a clean and non-confusing GUI.

Running a LÖVE game

First of all, we assume we do not have any LÖVE game yet. OK, then let's just write a simple "Hello World!" program and run it with LÖVE. Open up a text editor and write the following Lua code:

--create a display

function love.draw()
--display a text on a 800 by 600 screen in the positions x= 400, and --y=300
   love.graphics.print('hello world!', 400, 300)

end

Now save this code as main.lua. Open a folder for your game project, put your main.lua file inside the folder, and compress the content of the folder. Change the .zip extension to .love. You'll notice a change in the icon of the compressed file; it changes to a LÖVE logo. Now that we've done all that, we can run our game. If you follow the instructions correctly, you should see a screen similar to the following screenshot:

If you do not compress the file properly, you will get the following blue screen displaying error information:

Note that it is the content of your game folder that should be compressed and not the folder itself, and make sure the main.lua file is at the top level.

Basic structure of LÖVE

There are three basic functions that make up a LÖVE game that are essential in most of the games you will be designing with LÖVE. For now, the following are the basics to make a small game:

  • love.load(): This preloads all the necessary assets we need to make our game.

  • love.update(dt): This is where we do most of our maths, where we deal with events; it is called before a frame is drawn. dt is the time it takes to draw a frame (in seconds).

  • love.draw(): This draws all that we want to display on the screen.

Examples

The basic structure of the game is done as you can see in the following code:

--load our assets
function love.load()
   --load all assets here
end




--update event
function love.update(dt)
--do the maths
end


--draw display
function love.draw()
--describe how you want/what to draw.
end

That's just it, well... maybe! So let's play with these chunks one more time.

Now let's edit main.lua to enable loading sample assets that we want to use within the game:

function love.load()

   local myfont = love.graphics.newFont(45)

   love.graphics.setFont(myfont)

   love.graphics.setColor(0,0,0,225)

   love.graphics.setBackgroundColor(255,153,0)
end


function love.update()



end

function love.draw()

   love.graphics.print('Hello World!', 200, 200)

end

Conf.lua

Before you go on and start coding your game, you need to give your video game some specs such as window width, window height, and window title. So set up a new file named conf.lua; inside it you can then create your game specs as shown in the following code snippet:

function love.conf(w)

w.screen.width = 1024 

w.screen.height = 768

w.screen.title = "Goofy's Adventure"

end

You can manipulate the figures and titles any way and also change that w to whatever variable you want.

The preceding code does the following:

  • Loads our font

  • Sets the font color

  • Sets the background color

  • Draws text on the screen

  • Configures the screen size

Basically we are using the love.graphics module; it can be used to draw (in the real sense) texts, images, and any drawable object in the scene. In the previous code snippets, we defined our fonts with the love.graphics.newFont(45) that formats our text by declaring the size of the font as 45. setFont() loads the font we defined as myfont, setColor() colors the text in the RGB format, and setBackgroundColor() sets the background.

Then we printed text using the love.graphics.print('text', x, y) function in the draw function with three parameters parsed in it: the text and the x and y coordinates. We are not going to do anything in the love.update() function yet, because we are not dealing with scene events.

So let's load our game as a .love file and see what it displays:

Summary


Now we can grab a mug of cappuccino with Ray-Bans on and smile; we have installed the LÖVE game engine, text editor, and Visual tile-level editor (Tiled). We have also got a quick look at the basic structure for writing our game in Lua and displayed "Hello World!" in a colored background window. Next we'll go through how to draw 2D objects, move objects, and animate character sprites.

Left arrow icon Right arrow icon

Key benefits

  • Discover the L?ñVE framework and build games easily and efficiently
  • Learn how to utilize the L?ñVE framework's tools to create a 2D game world
  • A step-by-step approach to learning game development

Description

L?ñVE is a game development framework for making 2D games using the Lua programming language. L?ñVE is totally free, and can be used in anything from friendly open-source hobby projects, to closed-source commercial ones. Using the Lua programming framework, one can use L?ñVE2D to make any sort of interesting games. L?ñVE for Lua Game Programming will quickly and efficiently guide you through how to develop a video game from idea to prototype. Even if you are new to game programming, with this book, you will soon be able to create as many game titles as you wish without stress. The L?ñVE framework is the quickest and easiest way to build fully-functional 2D video games. It leverages the Lua programming language, which is known to be one of the easiest game development languages to learn and use. With this book, you will master how to develop multi-platform games for Windows, Linux, and Mac OS X. After downloading and installing L?ñVE, you will learn by example how to draw 2D objects, animate characters using sprites, and how to create game physics and game world maps. L?ñVE for Lua Game Programming makes it easier and quicker for you to learn everything you need to know about game programming. If you're interested in game programming, then this book is exactly what you've been looking for.

What you will learn

Create different environments to make your games more interesting Add sound and music to your games Apply game physics and real-time particle collisions Animate game characters using sprites Deploy your games to Windows, Linux, and Mac platforms

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Sep 25, 2013
Length 106 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782161608
Category :
Languages :

Table of Contents

15 Chapters
LÖVE for Lua Game Programming Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Getting Started with LÖVE Chevron down icon Chevron up icon
LÖving Up! Chevron down icon Chevron up icon
Before You Build a Game Chevron down icon Chevron up icon
Making Your First Game Chevron down icon Chevron up icon
More About Making the Game Chevron down icon Chevron up icon
Meeting the Bad Guy! Chevron down icon Chevron up icon
Pickups and Head-Up Display and Sounds Chevron down icon Chevron up icon
Packaging and Distributing Your Game Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.