Created
July 16, 2015 17:11
-
-
Save sonic2kk/44fa7338a141c2ba6c17 to your computer and use it in GitHub Desktop.
A Gist showing the basics of how to write a system that returns a local module in Lua/LOVE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local player = require 'player' | |
| function love.load() | |
| player.new(10, 10, 50, 50, 'Chandler Bing', 100) | |
| end | |
| function love.update(dt) | |
| player.update(dt) | |
| end | |
| function love.draw() | |
| player.draw() | |
| end | |
| function love.quit() | |
| love.event.quit() | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local player = {} | |
| function player.new(x, y, w, h, name, gold) | |
| local p = { x = x, y = y, w = w, h = h, name = name, gold = gold } | |
| table.insert(player, p) | |
| end | |
| function player.update(dt) | |
| for i,v in ipairs(player) do | |
| -- Update your player here | |
| end | |
| end | |
| function player.draw() | |
| for i,v in ipairs(player) do | |
| -- Draw your player here | |
| end | |
| end | |
| -- any other function for the player should follow a similar format, | |
| -- such that they all begin with "player." and contain a "for i,v in ipairs(player)" loop | |
| return player |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment