Game Development Reference
In-Depth Information
tmpVec.x = tmpVec.x / vecMag
tmpVec.y = tmpVec.y / vecMag
end
return tmpVec
end
function _vec2D:addVec(theVec, theVec2)
local tmpVec = Vector2D:new(0,0)
tmpVec.x = theVec.x + theVec2.x
tmpVec.y = theVec.y + theVec2.y
return tmpVec
end
local tmpVec = Vector2D:new(0,0)
tmpVec.x = theVec.x - theVec2.x
tmpVec.y = theVec.y - theVec2.y
return tmpVec
local tmpVec = Vector2D:new(0,0)
tmpVec.x = theVec.x * scalar
tmpVec.y = theVec.y * scalar
return tmpVec
end
function _vec2D:divideVec(theVec, scalar)
local tmpVec = Vector2D:new(0,0)
tmpVec.x = theVec.x / scalar
tmpVec.y = theVec.y / scalar
return tmpVec
end
function _vec2D:distance(theVec, theVec2)
return math.sqrt((theVec2.x - theVec1.x)^2 + (theVec2.y - theVec1.y)^2)
end
return _vec2D
Summary
The functions described in this chapter represent only a small selection of the functionality you
might need when creating your games. Some of the most frequently used functions were included
here, and they can be used in many ways. The tips and tricks mentioned in this section are generic
and do not rely on any particular framework, which means that they will work with every Lua-based
framework mentioned in this topic. After you finish reading the next few chapters, which introduce
the various frameworks, Chapters 13 and 14 will provide you more details on framework-specific
libraries and third-party applications to get things done.
 
Search WWH ::




Custom Search