Created
November 29, 2012 17:41
-
-
Save mroberti/4170676 to your computer and use it in GitHub Desktop.
mathlib demo 'IsOnRight'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("mathlib") | |
gameBoard = display.newGroup() | |
screenW = display.contentWidth | |
screenH = display.contentHeight | |
centerX = display.contentWidth/2 | |
centerY = display.contentHeight/2 | |
local mRand = math.random | |
local object1 = display.newCircle(gameBoard, 0, centerY, 10) | |
gameBoard:insert(object1) | |
-- Set up our point data... | |
north = display.newCircle(mRand(0,screenW),0,20) | |
south = display.newCircle(mRand(0,screenW),screenH,20) | |
-- Draw line using the above data... | |
local tempLine = display.newLine(gameBoard, north.x, north.y, south.x, south.y) | |
tempLine:setColor(0, 255, 0) | |
---------------------------------------------------------------- | |
-- MAIN LOOP | |
---------------------------------------------------------------- | |
local function Main( event ) | |
-- Continuously check to see if point has crossed | |
-- over to the right side of our test points' line... | |
if(isOnRight( north,south, object1 )) then | |
tempLine:setColor(255, 0, 0) | |
else | |
tempLine:setColor(0, 255, 0) | |
end | |
object1.x = object1.x + 2 | |
end | |
Runtime:addEventListener( "enterFrame", Main ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment