From 996cc257cdce285b29102407b2e68fa811d169c3 Mon Sep 17 00:00:00 2001 From: Niouby Date: Fri, 20 Feb 2015 17:07:32 +0100 Subject: [PATCH] add point class --- Point.lua | 17 +++++++++++++++++ World.lua | 15 ++++++++++----- main.lua | 12 +++++++++++- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 Point.lua diff --git a/Point.lua b/Point.lua new file mode 100644 index 0000000..f7de401 --- /dev/null +++ b/Point.lua @@ -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 \ No newline at end of file diff --git a/World.lua b/World.lua index 0c9b46b..cb5b491 100644 --- a/World.lua +++ b/World.lua @@ -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 diff --git a/main.lua b/main.lua index f53c4b8..a77ba3b 100644 --- a/main.lua +++ b/main.lua @@ -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)