Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 0.0.1
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (40 sloc) 1.021 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
SimplexNoise = require("lib/SimplexNoise")
LuaBit = require("lib/LuaBit")
Tile = class("Tile")
Tile:include({
  entities = {},
  color = nil,
  seedVal = 0
})

function Tile:initialize(x, y)
  self.entities = {}
  self:seed(x,y)
end

function Tile:seed(x, y)
  self.seedVal = math.floor((SimplexNoise.Noise2D(x*0.1, y*0.1) + 1) * 120) % 255
  local s = self.seedVal
  if s < 80 then
    self.color = {0,0,0}
  elseif s >= 80 and s < 120 then
    self.color = {s, s-20, math.floor(s / 2)}
  elseif s >= 120 and s < 200 then
    self.color = {s, s, s}
  else
    self.color = {s-40, s, s-40}
  end
end

function Tile:addEntity(self, entity)
  if not self.entities[entity.class.name] then
    self.entities[entity.class.name] = {}
  end
  table.insert(self.entities[entity.class.name], entity)
end

function removeEntity(self, entity)
  for i, e in pairs(self.entities[entity.class.name]) do
    if e == entity then
      table.remove(self.entities[entity.class.name], i)
      return true
    end
  end
  return false
end

Something went wrong with that request. Please try again.