Skip to content

Instantly share code, notes, and snippets.

@sonic2kk
Created July 16, 2015 17:11
Show Gist options
  • Save sonic2kk/44fa7338a141c2ba6c17 to your computer and use it in GitHub Desktop.
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
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
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