Skip to content

Instantly share code, notes, and snippets.

-- 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))
-- 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 )
-- 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
@codepaladin
codepaladin / getPath.lua
Created April 21, 2014 15:26
Find Jumper Path
-- 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
@codepaladin
codepaladin / startAndEnd.lua
Last active August 29, 2015 14:00
Jumper - Draw Start and End
-- 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
@codepaladin
codepaladin / drawGrid.lua
Last active August 29, 2015 14:00
Jumper Draw Grid
-- 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
@codepaladin
codepaladin / jumpersetup.lua
Last active August 29, 2015 14:00
Jumper Setup
-- 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
@codepaladin
codepaladin / allowableGrid.lua
Created April 14, 2014 17:06
Allowable Grid Movement
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
@codepaladin
codepaladin / spritesheet3.lua
Last active August 29, 2015 13:58
SpriteSheet3
local sequenceData =
{
name="walking",
start=3,
count=2,
time=1000,
}
local character = display.newSprite( imageSheet, sequenceData )
@codepaladin
codepaladin / spritesheet2.lua
Last active August 29, 2015 13:58
SpriteSheet2
local sequenceData =
{
name="walking",
start=3,
count=2,
time=1000,
}