These modules are small applications to test different Love 2D features. This repository's goal is to provide a Lua syntax guide, and to try out functions and custom Lua modules to be shared across all 2D game projects, using the Love 2D framework.
- Module 0: Hello World
- Module 1: Low-res
- Module 2: Font
- Module 3: Grid
- Module 4: Corners
- Module 5: Circle
- Module 6: Current time
- Module 7: Font sizes
- Module 8: Square object
- Module 9: Grid object
- Module 10: Circle object
- Module 11: Random circle
- Module 12: Basic timer
- Module 13: Square move
- Module 14: Timer object
- Module 15: Color Mapper
- Module 16: Square chain
- Module 17: Chain object
- Module 18: Quit game
- Module 19: Title
- Module 20: FPS
- Module 21: Chain move
- Module 22: Chain grow
- Module 23: Chain velocity
- Module 24: Offset grid
- Future modules
Module 0: Hello World
Prints "Hello World" at the center of the screen, with the default Font.
Module 1: Low-res
Prints the same text as the first module, but with a low resolution, crisp, pixelated aesthetic. It uses Ulydev's push library to do so.
Module 2: Font
Imports an old-fashioned font, and applies it to the welcome message from the previous module.
It uses Ulydev's push library.
-- main.lua
-- .........
-- Bootstrap the `push` library
push = require 'push'
-- ...
function love.load()
-- ...
-- Define "retro-looking" font object to use for any text
smallFont = love.graphics.newFont('font.ttf', 8)
-- Set Love 2D's active font to the smallFont object
love.graphics.setFont(smallFont)
-- ...
end
function love.draw()
-- Begin rendering at virtual resolution
push:start()
-- Use `love.graphics.printf` to display the text at the center of the screen
-- End rendering at virtual resolution
push:finish()
end
Module 3: Grid
Defines a 16 by 16 pixel square, and uses it to draw as many copies as needed for them to cover the entire screen.
Used for debugging.
Module 4: Corners
Prints text at each of the corners of the screen, with a low-res aesthetic, and a "retro-looking" Font.
Defines an offset for both 'x' and 'y' positions.
Draws the 4 texts by applying the offsets to the rectangles used for each text alignment.
Module 5: Circle
Displays a circle inside one of the 16x16 pixel grid cells.
Defines values for both the circle's center position and the circle's pivot. It draws a small rectangle to indicate the aforementioned pivot.
Module 6: Current time
Prints the current time in 12 hour format, at the center of the screen.
Module 7: Font sizes
Prints a couple of font sizes inside a margin.
Draws a small text at the top center of the screen, and a large text at the botton center of the screen.
Module 8: Square object
Displays a filled square as a class object.
Defines values for both the 'x' and 'y' position, and the width of the square.
Uses vrld's class library to represent the square object as code, and place all of its properties and functions in a separate file.
Draws the aforementioned square inside one of the grid cells.
Module 9: Grid object
Displays a 16x16 pixel grid as a class object.
Defines values for the width, the height, and the unit of measurement for each cell of the grid.
Represents the grid object as code, and places all of its properties and functions in a separate file. It uses vrld's class library to do so.
Draws the aforementioned grid to cover the entire screen.
Used for debugging.
Module 10: Circle object
Displays a circle as a class object, using vrld's class library.
Defines values for both the circle's center position and the circle's center indicator.
It draws both the shape and the aforementioned indicator inside one of the grid cells.
Module 11: Random circle
Displays a circle, represented as a class object, inside of a random grid cell. It uses vrld's class library to do so, just like in the previous module.
Updates the Circle class to that it receives a grid and, if the x and y positions of the center of the circle are not specified, it places the shape inside a grid cell that varies every time on startup.
Module 12: Basic timer
Prints a timer that affects the position of a circle on the screen.
Sets a second timer to increase by delta time, and switch the position of the circle, between 2 grid cells, every 2 seconds.
Module 13: Square move
Gets the user's input to move a filled square, represented as a class object, in 4 directions. It uses vrld's class library to represent the square object as code.
Takes the input to set the direction of the movement.
Moves the square in one of four directions to adjacent grid cells, depending on the pressed key, one grid cell at a time.
Updates the square position every second.
Module 14: Timer object
Set 2 timers, represented as class objects. It uses vrld's class library to do it.
Defines a timer class that affects an output on the screen, at certain intervals, by executing a given callback action.
Sets a second timer to increase by delta time, and switch the position of a circle, between 2 grid cells, every 2 seconds (just like in the Basic timer module).
It also sets another timer to update a seconds counter every second.
Module 15: Color Mapper
Displays shapes with a cross-version color mapper.
In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.
https://love2d.org/wiki/love.graphics.clear
Represents the color mapper as a class object, which calls color related operations and modifies component values as needed. It uses vrld's class library to do so, as usual.
Draws 2 colored squares inside different grid cells, and applies the same color for both shapes, one with component values within the range of 0 to 255, and the other with component values ranging from 0 to 1.
Module 16: Square Chain
Displays a chain of filled squares, represented as class objects, inside a 16x16 pixel grid.
Uses vrld's class library to represent the squares as data, and uses the Color Mapper class from the previous module to apply different colors to the structure, and highlight the chain's head and tail.
Module 17: Chain object
Displays the chain from the previous module, and represents it as a single class object. Uses vrld's class library to do so; and uses the Color Mapper class from module 15 for the same reasons as the previous module.
It places the structure into a 16x16 pixel grid as well.
Module 18: Quit game
Prints a message at the center of the screen that indicates the user what key to press to quit the game, and terminates the game when that key is pressed.
Module 19: Title
Sets the title of the game window as 'Game title'.
Module 20: FPS
Renders a simple FPS display for debugging, and draws a filled square, represented as a class object, inside one of the grid cells. Uses the Color Mapper class from module 15 to highlight the display, and vrld's class library to represent the square as data.
The game takes input from the user and moves the square in one of four directions to adjacent grid cells, depending on the pressed key; and updates the square position every second. Applies the same logic from the Square move module.
Module 21: Chain move
Gets the user's input to move a chain of filled squares. It uses vrld's class library to represent the chain object as code; and uses the Color Mapper class from module 15 for the same reason as the Square chain module, to highlight the chain's head and tail.
Takes the input to set the direction of the movement.
Moves the chain's head in one of four directions to adjacent grid cells, depending on the pressed key, one grid cell at a time.
Updates the chain's head position every second. Modifies the rest of the squares so that they follow its trajectory.
Module 22: Chain grow
Takes the user's input to increase the chain size. It uses vrld's class library and the Color Mapper class from module 15 for the same reason mentioned in the Square chain module.
Gets the input to set a growth flag to true. Sets that flag back to false right after a new square is added to the chain.
It also gets input from the user to move the chain's head in one of four directions to adjacent grid cells, depending on the pressed key, as the rest of the squares follow the head's trajectory. This feature was implemented in the previous module.
If the structure has a single square, the growth flag is set to true, and the chain's size is increased once by 1 as well.
Changes the head's color while the chain is growing, with the Color Mapper, to display visual feedback.
Updates the chain's state every second.
Module 23: Chain velocity
Gets the user's input to increase the chain velocity. It uses vrld's class library and the Color Mapper class from module 15 for the same reason as mentioned in the Square chain module.
Takes the input to set a momentum percentage to 25%. Uses that value to reduce the structure's refresh rate by that amount.
It also gets input from the user to move the chain's head in one of four directions to adjacent grid cells, as it was mentioned in the Chain move module.
Ensures the refresh rate isn't so low that the game becomes unplayable.
Updates the chain's state, depending on the amount of seconds specified by the structure's refresh rate.
Module 24: Offset grid
Displays a 16x16 pixel grid as a class object, smaller than the screen and offset by an arbitrary amount.
Represents the grid object as code, and places all of its properties and functions in a separate file, as it was mentioned in the Grid object module. It uses vrld's class library to do so.
Draws the aforementioned grid, which will be used as the playing field in later modules.
- Module 25: Inner bounds
- Module 26: Self collision
- Module 27: Game over
- Module 28: Game reset
- Module 29: Game state
- Module 30: Sounds
- Module 31: State object
- Module 32: Direction arrow
- Module 33: Direction object
This repository was inspired by CS50's Introduction to Game Development online course, which was mainly instructed by Colton Ogden, and contains lectures and hands-on projects related to the development of 2D and 3D interactive games. It was also inspired by that course's repository, Olivine Labs' Lua Style Guide, cocos2d's cocos2d Javascript test and games, and OneSignal's Emoji Picker. This version is focused on the basics of the Lua programming language, and the Love 2D framework.
- Operating system: Windows
- Text editor of choice: Sublime Text 3
- Lua programming language: http://www.lua.org
- Love 2D: https://love2d.org