Remove old examples

This commit is contained in:
Tjakka5 2020-05-02 20:42:26 +02:00
parent b906e2a910
commit c889b15d44
7 changed files with 0 additions and 272 deletions

View file

@ -1,63 +0,0 @@
local Concord = require("src")
local Entity = Concord.entity
local Component = Concord.component
local System = Concord.system
local Assemblage = Concord.assemblage
local Legs = Component("Legs", function(e, legCount)
e.legCount = legCount or 0
end)
local Instinct = Component("Instinct", function(e) -- luacheck: ignore
end)
local Cool = Component("Cool", function(e, coolness)
e.coolness = coolness
end)
local Wings = Component("Wings", function(e)
e.wingCount = 2
end)
local Animal = function(e, legCount)
e
:give("Legs", legCount)
:give("Instinct")
print("Animal")
end
local Lion = function(e, coolness)
e
:assemble(Animal, 4)
:give(Cool, coolness)
print("Lion")
end
local Eagle = function(e)
e
:assemble(Animal, 2)
:give(Wings)
print("Eagle")
end
local Griffin = function(e, coolness)
e
:assemble(Animal, 4)
:assemble(Lion, coolness * 2)
:assemble(Eagle)
end
local myAnimal = Entity()
:assemble(Griffin, 5)
--:apply()
print(myAnimal:has("Legs"))
print(myAnimal:has("Instinct"))
print(myAnimal:has("Cool"))
print(myAnimal:has("Wings"))

View file

@ -1,6 +0,0 @@
local PATH = (...):gsub('%.[^%.]+$', '')
local Concord = require("src")
local C = require(PATH..".src.components")
local S = require(PATH..".src.systems")

View file

@ -1,5 +0,0 @@
local PATH = (...):gsub('%.init$', '')
return {
}

View file

@ -1,5 +0,0 @@
local PATH = (...):gsub('%.init$', '')
return {
}

View file

@ -1,67 +0,0 @@
local Concord = require("concord")
local function display(t)
print("Table: " ..tostring(t))
for key, value in pairs(t) do
if type(value) == "table" then
display(value)
else
print(key, value)
end
end
end
local test_component_1 = Concord.component("test_component_1", function(e, x, y)
e.x = x or 0
e.y = y or 0
end)
function test_component_1:serialize()
return {
x = self.x,
y = self.y,
}
end
function test_component_1:deserialize(data)
self.x = data.x or 0
self.y = data.y or 0
end
local test_component_2 = Concord.component("test_component_2", function(e, foo)
e.foo = foo
end)
function test_component_2:serialize()
return {
foo = self.foo
}
end
function test_component_2:deserialize(data)
self.foo = data.foo
end
-- Test worlds
local world_1 = Concord.world()
local world_2 = Concord.world()
-- Test Entity
Concord.entity(world_1)
:give("test_component_1", 100, 50)
:give("test_component_2", "Hello World!")
-- Serialize world
local data = world_1:serialize()
-- Deserialize world
world_2:deserialize(data)
-- Check result
local test_entity_copy = world_2:getEntities()[1]
local test_comp_1 = test_entity_copy["test_component_1"]
local test_comp_2 = test_entity_copy["test_component_2"]
print(test_comp_1.x, test_comp_1.y)
print(test_comp_2.foo)

View file

@ -1,125 +0,0 @@
local Concord = require("src")
local Entity = Concord.entity
local Component = Concord.component
local System = Concord.system
local Game = Concord.world()
local Position = Component('Position', function(e, x, y)
e.x = x
e.y = y
end)
local Rectangle = Component('Rectangle', function(e, w, h)
e.w = w
e.h = h
end)
local Circle = Component('Circle', function(e, r)
e.r = r
end)
local Color = Component('Color', function(e, r, g, b, a)
e.r = r
e.g = g
e.b = b
e.a = a
end)
local RectangleRenderer = System{pool = {'Position', 'Rectangle'}}
function RectangleRenderer:draw()
for _, e in ipairs(self.pool) do
local position = e:get('Position')
local rectangle = e:get('Rectangle')
local color = e:get('Color')
love.graphics.setColor(255, 255, 255)
if color then
love.graphics.setColor(color.r, color.g, color.b, color.a)
end
love.graphics.rectangle("fill", position.x, position.y, rectangle.w, rectangle.h)
end
end
local CircleRenderer = System{pool = {'Position', 'Circle'}}
function CircleRenderer:flush()
for _, e in ipairs(self.pool.removed) do
print(tostring(e).. " was removed from my pool D:")
end
end
function CircleRenderer:draw()
for _, e in ipairs(self.pool) do
local position = e:get('Position')
local circle = e:get('Circle')
local color = e:get('Color')
love.graphics.setColor(255, 255, 255)
if color then
love.graphics.setColor(color.r, color.g, color.b, color.a)
end
love.graphics.circle("fill", position.x, position.y, circle.r)
end
end
local RandomRemover = System{pool = {}}
function RandomRemover:init()
self.time = 0
end
function RandomRemover:update(dt)
self.time = self.time + dt
if self.time >= 0.05 then
self.time = 0
if self.pool.size > 0 then
local i = love.math.random(1, self.pool.size)
self.pool:get(i):destroy()
end
end
love.window.setTitle(love.timer.getFPS())
end
Game:addSystem(RandomRemover(), "update")
Game:addSystem(RectangleRenderer(), "draw")
Game:addSystem(CircleRenderer(), "draw")
for _ = 1, 100 do
local e = Entity()
e:give('Position', love.math.random(0, 700), love.math.random(0, 700))
e:give('Rectangle', love.math.random(5, 20), love.math.random(5, 20))
if love.math.random(0, 1) == 0 then
e:give('Color', love.math.random(), love.math.random(), love.math.random(), 1)
end
Game:addEntity(e)
end
for _ = 1, 100 do
local e = Entity()
e:give('Position', love.math.random(0, 700), love.math.random(0, 700))
e:give('Circle', love.math.random(5, 20))
if love.math.random(0, 1) == 0 then
e:give('Color', love.math.random(), love.math.random(), love.math.random(), 1)
end
Game:addEntity(e)
end
function love.update(dt)
Game:emit("update", dt)
end
function love.draw()
Game:emit("draw")
end

View file

@ -1 +0,0 @@
require("examples.serialization")