Game Development Reference
In-Depth Information
local theColor = {255,0,0}
--[[
this is easier to specify than
theColorR = 255
theColorG = 0
theColorB = 0
--]]
The functions that accept the color generally take four variables, as in the following function:
setTheColor(r, g, b, a)
theColor , which is a table, cannot be passed to the function, as the function expects numbers, not a
unpack function, as follows:
, like so:
This section demonstrates a set of functions that help perform tasks using vectors. This topic will
not get into explaining vectors; however, if you are looking for some good reading points, the Vectors
for Flash site, at http://tonypa.pri.ee/vectors/index.html , is a good starting point. Place this
entire code into a file called vectors.lua .
_vec2D = {}
function _vec2D:new(x, y)
local _newVec = {x = x, y = y}
setmetatable(_newVec, { __index = _vec2D } )
return _newVec
end
function _vec2D:magnitude()
return math.sqrt(self.x * self.x + self.y * self.y)
end
function _vec2D:normalize()
local t = self:magnitude()
if t > 0 then
self.x = self.x / t
self.y = self.y / t
end
end
 
Search WWH ::




Custom Search