Created
December 26, 2011 11:53
-
-
Save wookay/1520976 to your computer and use it in GitHub Desktop.
Test MOAI path finder
This file contains hidden or 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
-- test_moai_path_finder.lua | |
-- wookay.noh at gmail.com | |
package.path = package.path .. ";../?.lua" | |
require 'libmoai' | |
function test_moai_path_finder() | |
local grid = Grid.new({32,32}) | |
grid.rows = { | |
{0x03, 0x03, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03}, | |
{0x03, 0x03, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03}, | |
{0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x03, 0x03}, | |
{0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x03, 0x03}, | |
{0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x03, 0x03}, | |
{0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x03, 0x03}, | |
{0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x03, 0x03}, | |
{0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x03, 0x03}, | |
} | |
local pathFinder = PathFinder.new(grid, {1,1}, {8,8}) | |
pathFinder.findPath(5) | |
pathFinder.fillGrid(0x01, 0x02, 0x04) | |
assert_equal({ | |
{ 1, 0x03, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03}, | |
{0x03, 2, 0x00, 0x03, 0x03, 2, 0x03, 0x03}, | |
{0x03, 2, 0x00, 0x03, 2, 0x00, 2, 0x03}, | |
{0x03, 2, 0x00, 0x03, 2, 0x00, 0x03, 2}, | |
{0x03, 2, 0x00, 0x03, 2, 0x00, 0x03, 2}, | |
{0x03, 2, 0x00, 0x03, 2, 0x00, 0x03, 2}, | |
{0x03, 0x03, 2, 0x03, 2, 0x00, 0x03, 2}, | |
{0x03, 0x03, 0x03, 2, 0x03, 0x00, 0x03, 4}, | |
}, grid.rows) | |
local layer = Sim.layer() | |
layer.enableTouchEvents() | |
local deck = Deck.new("./images/numbers.png", {8,8}) | |
assert_equal({32,32}, deck.size) | |
local prop = Prop.new(deck) | |
prop.grid = grid | |
prop.location = {-128, 128} | |
prop.deckRectDimension = 0.5 | |
layer.add(prop) | |
local catDeck = Deck.new("./images/cathead.png") | |
catDeck.wrap:setRect(-16, 16, 16, -16) | |
local catProp = Prop.new(catDeck) | |
catProp.deckRectDimension = 16 | |
catProp.origin = {0,0} | |
layer.add(catProp) | |
local locations = Table.map(pathFinder.pathLocations, function(xy) | |
local x, y = unpack(xy) | |
return {x - 128, 128 - y} | |
end) | |
local anim = catProp.animate(locations, 5) | |
anim.start(true) | |
layer.addExitButton() | |
end | |
if is_main() then | |
UnitTest.run() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment