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
-- get start position based off of startX and startY grid (cartesian) coordinates | |
function drawStart() | |
local x = (display.contentWidth * 0.5 + ((startX - startY) * tileHeight)) | |
local y = (((startX + startY)/2) * tileHeight) - (tileHeight/2) | |
local myText = display.newText( "A", x, y, native.systemFont, 34 ) | |
end | |
-- get end position based off of endX and endY grid (cartesian) coordinates | |
function drawEnd() | |
local x = (display.contentWidth * 0.5 + ((endX - endY) * tileHeight)) |
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
-- draw a tile map to the screen | |
-- populate the tile map | |
function drawGrid() | |
for row = 0, 5 do | |
local gridRow = {} | |
for col = 0, 5 do | |
-- draw a diamond shaped tile | |
local vertices = { 0,-16, -64,16, 0,48, 64,16 } | |
local tile = display.newPolygon(group, 0, 0, vertices ) |
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
-- include the jumper library | |
local Grid = require ("jumper.jumper.grid") | |
local Pathfinder = require ("jumper.jumper.pathfinder") | |
local walkable = 0 -- used by Jumper to mark obstacles | |
local map = {} -- table representing each grid position | |
local startX = 1 -- start x grid (cartesian) coordinate | |
local startY = 1 -- start y grid (cartesian) coordinate | |
local endX = 3 -- end x grid (cartesian) coordinate | |
local endY = 4 -- end y grid (cartesian) coordinate |
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
-- find the path from point A to point B | |
function getPath() | |
-- create a Jumper Grid object by passing in our map table | |
local grid = Grid(map) | |
-- Creates a pathfinder object using Jump Point Search | |
local pather = Pathfinder(grid, 'JPS', walkable) | |
pather:setMode("ORTHOGONAL") | |
-- Calculates the path, and its length |
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
-- draw start position by using the pixel coordinates | |
-- set the startx and starty grid coordinates | |
function drawStart(xyPixelCoordinate, xyGridCoordinate) | |
local myText = display.newText( "A", xyPixelCoordinate.x, xyPixelCoordinate.y, native.systemFont, 34 ) | |
myText:setFillColor( 255, 255, 255 ) | |
startx = xyGridCoordinate.x | |
starty = xyGridCoordinate.y | |
end | |
-- draw end position by using the pixel coordinates |
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
-- draw a tile map to the screen | |
-- populate the map table | |
function drawGrid() | |
for row = 1, 10 do | |
local gridRow = {} | |
for col = 1, 10 do | |
-- draw a tile | |
local tile = display.newRect((col * 50) - 25, (row * 50) - 25, 48, 48) | |
-- make some tiles un-walkable |
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
-- main.lua | |
display.setStatusBar( display.HiddenStatusBar ) | |
local Grid = require ("jumper.jumper.grid") | |
local Pathfinder = require ("jumper.jumper.pathfinder") | |
local map = {} -- table representing each grid position | |
local walkable = 0 -- used by Jumper to mark obstacles | |
local startx = 0 -- start x grid coordinate |
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
local allowableMoves = 3 -- how many tiles a character can move | |
local x = 0 --starting x position on a grid | |
local y = 0 --starting y position on a grid | |
for xMoves = (x - allowableMoves), (x + allowableMoves) do | |
for yMoves = (y - allowableMoves), (y + allowableMoves) do | |
if (math.abs(x - xMoves)) + (math.abs(y - yMoves)) <= allowableMoves then | |
print(xMoves ..","..yMoves) -- this is an allowable movement grid position | |
end | |
end |
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
local sequenceData = | |
{ | |
name="walking", | |
start=3, | |
count=2, | |
time=1000, | |
} | |
local character = display.newSprite( imageSheet, sequenceData ) |
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
local sequenceData = | |
{ | |
name="walking", | |
start=3, | |
count=2, | |
time=1000, | |
} |