Categories
Love2D and Lua Programming Languages

Installing Lua (64bit) on Window 10

Download site

http://luabinaries.sourceforge.net/download.html

Extract (unzip) the lua-5.x._win64_bin.zip

Unzip (files)

Create a new folder

D:\Program Files\LUA

Copy all the unzip files into this folder

Rename the lua54.exe to lua.exe

Append a new path for lua.exe to the Windows 10 System environment variable path

Launch the Lua 5.x interpreter from command prompt (terminal)

If everything has been done correctly then you see the Lua 5.x.x Copyright (C) otherwise check the system variable environment path again. Note the semcolon ( ; ) entries before and after the path value.

Categories
Love2D and Lua

Love2D Resources

Wikipedia and Documentation API

https://www.love2d.org/wiki/Main_Page

Categories
Love2D and Lua

How LOVE2D Work

LÖVE calls 3 functions. First it calls love.load(). After that it calls love.update() and love.draw(), repeatedly in that order.

So: love.load -> love.update -> love.draw -> love.update -> love.draw -> love.update, etc.

Behind the scenes, LÖVE calls these functions, and we to create them, and fill them with code. This is what we call a callback.

LÖVE is made out of modules, love.graphics, love.audio, love.filesystem. There are about 15 modules, and each module focuses on 1 thing. Everything that you draw is done with love.graphics. And anything with sound is done with love.audio.

Categories
Love2D and Lua

2D World Coordinate (x-axis, y-axis)

The 2D coordinate system that we use in video games is a relatively straightforward one. Everything is measured in pixels from the top left corner. Nearly all of the drawing commands that we do will be expressed in these coordinates.

The top left corner, (0,0) origin with width and height has a value of zero, zero. The x-axis value (positive) increase moving the left to the right direction. The y-axis value increase moving top to bottom direction.

Categories
Love2D and Lua

Structure of Love2d

love.load()

 love.load to do one-time setup of your game

love.update(dt)

 love.update which is used to manage your game’s state frame-to-frame. Much like a game loop

love.draw()

 love.draw() which is used to render the game state onto the screen.

Example

Draw a rectangle and it continues to expand in height and width

-- Load some default values for our rectangle.
function love.load()
    x, y, w, h = 20, 20, 60, 20
end
 
-- Increase the size of the rectangle every frame.
function love.update(dt)
    w = w + 1
    h = h + 1
end
 
-- Draw a coloured rectangle.
function love.draw()
    -- In versions prior to 11.0, color component values are (0, 102, 102)
    love.graphics.setColor(0, 0.4, 0.4)
    love.graphics.rectangle("fill", x, y, w, h)
end
Categories
Love2D and Lua

Running a Love2D game from Visual Studio Code.

From a folder that contains a main.lua file.

On the VSC’s project folder has the main.lua file, and the Pixelbyte’s Love2D extension support installed. To run the main.lua file just press ALT + L (default keybinding) to run the Love2D game.

Categories
Love2D and Lua

Setup Pixelbyte’s Love2D Extension for Visual Code (Windows)

https://marketplace.visualstudio.com/items?itemName=pixelbyte-studios.pixelbyte-love2d

Keybindings (Default – ALT + L)

  • Run Love2D on the current project folder:
  • NOTE: YOU CAN CHANGE THESE KEYS IN File->Preferences->Settings
Win: {"key": "Alt+L,", "command":"pixelbyte.love2d.run"}

Path of the love.exe program (Default)

  • Set the path to the Love2D executable:
  • Change these in File->Preferences->Settings
"pixelbyte.love2d.path" : "C:\Program Files\Love\love.exe"
Categories
Love2D and Lua

Download and fresh install Love2D version 11.3

Love2D come with battery include (Lua application). So no need to download and install Lua.

https://love2d.org/wiki/Getting_Started