add point class

This commit is contained in:
Niouby 2015-02-20 17:07:32 +01:00
parent d9201ce4a8
commit 996cc257cd
3 changed files with 38 additions and 6 deletions

17
Point.lua Normal file
View File

@ -0,0 +1,17 @@
Point = {}
Point.__index = Point
function Point.new(x,y)
local self = setmetatable({}, Point)
self.x=x
self.y=y
return self
end
function Point:getx()
return self.x
end
function Point:gety()
return self.y
end

View File

@ -1,9 +1,10 @@
require "Cell"
World = {}
World.__index = World
function World.new(n)
function World.new()
local self = setmetatable({}, World)
self.grid = {}
for i=0,99 do
@ -12,11 +13,15 @@ function World.new(n)
self.grid[i][j] = Cell.new()
end
end
self.grid[10][10] = AliveCell.new()
self.grid[20][10] = DeadCell.new()
return self
end
function World:init(cells)
for i=0,#cells do
self.grid[cells[i]:getx()][cells[i]:gety()] = AliveCell.new()
end
end
function World:getNbColumn()
return #self.grid
end
@ -26,8 +31,8 @@ function World:getNbLine()
end
function World:draw()
for i=1,self:getNbColumn() do
for j=1,self:getNbLine() do
for i=0,self:getNbColumn() do
for j=0,self:getNbLine() do
lutro.graphics.rectangle(i*2,j*2,1,1, self.grid[i][j]:getColor())
end
end

View File

@ -1,15 +1,25 @@
-- ./informatique/RetroArch/retroarch -L informatique/libretro-lutro/lutro_libretro.so informatique/lutro-game-of-life/main.lua
require "Point"
require "World"
require "Cell"
require "AliveCell"
require "DeadCell"
function lutro.conf(t)
t.width = 200
t.height = 200
end
function lutro.load()
w1 = World.new(1)
points = {}
points[0]= Point.new(1,1)
points[1]= Point.new(2,2)
points[2]= Point.new(3,3)
w1 = World.new()
w1:init(points)
end
function lutro.update(dt)