mirror of
https://github.com/libretro/lutro-game-of-life.git
synced 2024-11-22 23:39:39 +00:00
add point class
This commit is contained in:
parent
d9201ce4a8
commit
996cc257cd
17
Point.lua
Normal file
17
Point.lua
Normal 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
|
15
World.lua
15
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
|
||||
|
12
main.lua
12
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)
|
||||
|
Loading…
Reference in New Issue
Block a user