Skip to content

Instantly share code, notes, and snippets.

@sonic2kk
Created July 16, 2015 17:21
Show Gist options
  • Save sonic2kk/ddc4302a250d52c911e1 to your computer and use it in GitHub Desktop.
Save sonic2kk/ddc4302a250d52c911e1 to your computer and use it in GitHub Desktop.
A Gist showing the basics of how to write a system which lets you create players and optionally store them in variables
Enemies = {}
function Enemies.new(x, y, w, h, name, health)
local e = { x = x, y = y, w = w, h = h, name = name, health = health }
table.insert(Enemies, e)
return e
end
function Enemies.update(dt)
for i,v in ipairs(Enemies) do
-- Update your enemies here
end
end
function Enemies.draw()
for i,v in ipairs(Enemies) do
-- Draw your enemies here
end
end
-- any other function for the enemies should follow a similar format,
-- such that they all begin with "Enemies." and contain a "for i,v in ipairs(Enemies)" loop
require 'enemy'
local enemy
function love.load()
enemy = Enemies.new(10, 10, 50, 50, 'Jacques von Hämsterviel', 9001)
end
function love.update(dt)
Enemies.update(dt)
end
function love.draw()
Enemies.draw()
end
function love.quit()
love.event.quit()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment