Word Search Starter Kit
This starter kit will allow you to rapidly write 'word search' style games and edit puzzles for your game.
Also Included
This starter kit is made using a standard base that can be found in all current and future 'try before you buy' kits. Those parts are:
-
buttonMaker - Button builders for push, toggle, and radio buttons.
- Docs coming soon...
-
soundMgr - Basic sound manager that you can easily tweak and extend.
- Docs coming soon...
-
utils - Utilities module that includes tons of featues, including a button generator.
- Docs coming soon...
The Viewer
Example Usage
require "easy.globals"
local utils = require "easy.utils"
require "presets.presets" -- For button maker
local buttonMaker = require "easy.buttonMaker"
local wordSearch = require "easy.wordSearch"
local group
local puzzleNum = 0
local function run()
puzzleNum = puzzleNum + 1
puzzleNum = (puzzleNum > 2) and 1 or puzzleNum
display.remove(group)
group = display.newGroup()
--
-- Draw a background
--
local back = display.newRect( group, centerX, centerY, fullw, fullh )
--
-- Draw a win label
--
local winLabel = display.newText( group, "Puzzle Complete",
centerX, bottom - 40, "Lato-Black.ttf", 60 )
winLabel:setFillColor(1,1,1)
winLabel.isVisible = false
--
-- Add a button to 're-run' this example
--
local button = buttonMaker.easyPush( { parent = group, x = right - 55, y = top + 20,
fontSize = 20, width = 100, height = 30,
labelText = "Next", listener = run } )
button.isVisible = false
--
-- Add a button to 're-run' this example
--
local button = buttonMaker.easyPush( { parent = group, x = right - 55, y = top + 20,
fontSize = 20, width = 100, height = 30,
labelText = "Next", listener = run } )
button.isVisible = false
--
local puzzleToLoad = string.format( "puzzle_%0.3d.json", puzzleNum )
local tileSize = 50
local info = wordSearch.getPuzzle( puzzleToLoad )
--utils.dump(info,"info")
--
local puzzleWidth = info.cols * tileSize
local puzzleHeight = info.rows * tileSize
--
local puzzleX = centerX - puzzleWidth/2 - 180
local puzzleY = centerY - puzzleHeight/2 - 10
--
-- Draw word list
--
local wordList = info.rawList
wordList = utils.split(wordList,"\n")
--utils.dump(wordList, "wordList")
local wordLabels = {}
--
local x = puzzleX + puzzleWidth + 21
local y = puzzleY
local tray = display.newRect( group, x, y, 350, puzzleHeight )
tray:setStrokeColor(unpack(utils.hexcolor("#128223")))
tray.strokeWidth = 5
tray.anchorX = 0
tray.anchorY = 0
--
local tmp = display.newText( group, "Difficulty: " ..
tostring(utils.round(info.difficulty,2)),
centerX, top + 30, "Lato-Black.ttf", 25 )
tmp:setFillColor(unpack(utils.hexcolor("#128223")))
--
x = x + 350/2
y = y + 40
--
for i = 1, #wordList do
local word = wordList[i]
local tmp = display.newText( group, word, x, y, "Roboto-Thin.ttf", 20 )
tmp:setFillColor(0,0,0)
wordLabels[word] = tmp
tmp.line = display.newLine( x - 10 - tmp.contentWidth/2, y, x + tmp.contentWidth/2 + 10, y )
tmp.line.strokeWidth = 2
tmp.line:setStrokeColor(0,0,0)
tmp.line.isVisible = false
y = y + 40
end
--
-- Listener for puzzle
--
local function onPuzzleEvent( event )
if( event.phase == "foundWord" ) then
print(event.word)
print(wordLabels[event.word])
wordLabels[event.word].line.isVisible = true
elseif( event.phase == "puzzleComplete" ) then
winLabel.isVisible = true
button.isVisible = true
end
end
--
-- Draw current puzzle
--
wordSearch.setTileSize( tileSize )
local colorCodes = { "#7ec696", "#e9c9bc", "#aaf2e7", "#df93ed", "#dbc1a6",
"#7f89ad", "#9194ff", "#7fafc5", "#93d3b8", "#aa84cd",
"#e1e5c2", "#e1e5c2", "#f9f7c4", "#92ba9f", "#ec99e1",
"#af89d6", "#a3a1c9", "#afdece", }
wordSearch.setColors( colorCodes )
local params =
{
tileImg = "images/fillT.png",
letterColor = { 0, 0, 0 },
--letterSize = 25,
letterFont = "Lato-Black.ttf",
listener = onPuzzleEvent
}
wordSearch.setLineWidth( 36 )
wordSearch.createPuzzleViewer( group, puzzleX, puzzleY, puzzleToLoad, params )
end
run()
The Editor
Basic Usage
local mode = "edit" -- edit view
if( mode == "edit" ) then
local utils = require "easy.utils"
require "presets.presets" -- For button maker
local wordSearch = require "easy.wordSearch"
wordSearch.setFont( "editor.ttf" )
wordSearch.setTileSize(34)
wordSearch.createEditor()
else
require "easy.globals"
local utils = require "easy.utils"
require "presets.presets" -- For button maker
local wordSearch = require "easy.wordSearch"
--
local tileSize = 60
local info = wordSearch.getPuzzle( "puzzle_001.json" )
local puzzleWidth = info.cols * tileSize
local puzzleHeight = info.rows * tileSize
--
local x = centerX - puzzleWidth/2
local y = centerY - puzzleHeight/2
--
wordSearch.setTileSize( tileSize )
local params =
{
tileImg = "images/fillW.png",
letterColor = { 0, 0, 0 },
letterSize = 25,
letterFont = "Roboto-Thin.ttf" }
wordSearch.createPuzzleViewer( nil, x, y, "puzzle_001.json", params )
end
Quick Reference
createEditor
wordSearch.createEditor( group )
- Creates and starts the editor.
- group - An optional display group to place all content in.
createPuzzleViewer
wordSearch.createPuzzleViewer( group, x, y, puzzleToLoad, params )
- Creates a puzzle 'viewer'.
The 'viewer' is essentially a fully functional game instance that you can place anywherey you like, in any group you like.
- group - An optional display group to place all content in.
- x, y - < x, y > position of center of puzzle.
- puzzleToLoad - Full name of puzzle, including the .json extension.
- params - A table of optional parameters.
- listener - Function to call when board is solved.
- landWidth, landHeight - Width and height of 'lands'.
- landStroke - Stroke width of land.
- landImage - Image to use for drawing lands. If none supplied, a rectangle is drawn.
- landColor - Fill color to use for land. Default is white.
- tileWidth, tileHeight - Width and height of 'tiles'.
- tileStroke - Stroke width of tile.
- tileImage - Image to use for drawing tiles. If none supplied, a rectangle is drawn.
- tileImages - If supplied, you are telling the module to look in this folder for the letter tiles.
- tileExtension - Optionally used with 'tileImages' parameter and must be either ".png" or ".jpg".
- tileColor - Fill color to use for tile. Default is white.
- letterFont - Font to use for letters if you're not supplying letter tiles.
- letterSize - Size of letters (only for non-letter tile case).
- letterColor - Color of letters (only for non-letter tile case).
Note: All puzzle definitions are assumed to be in the folder
~/puzzles/
.
destroyEditor
wordSearch.createEditor()
- Destroys current editor.
destroyPuzzleViewer
wordSearch.createPuzzleViewer()
- Destroys current 'viewer'.
getPuzzle
wordSearch.getPuzzle( puzzleToLoad )
- Returns a table containing the puzzle definition for a named puzzle.
- puzzleToLoad - Full name of puzzle, including the .json extension.
Returned Table Fields
- rows - Number of rows in puzzle.
- cols - Number of colums in puzzle.
- inCols - Words in columns.
- inRows - Words in rows.
- inDiagonals - Words in diagonals.
- difficult - Rated dificulty of puzzle from 1 .. 10.
- rawPuzzle - Raw puzzle (rows of letters separated by "\n").
- rawList - Raw list of words in puzzle, separated by "\n".
Note: All puzzle definitions are assumed to be in the folder
~/puzzles/
.
setColors
wordSearch.setColors( colorCodes )
- Set your own custom color codes for lines.
- colorCodes - A table of strings, where each string is a hex encoded color.
- Ex: This is red
#FF0000
- Ex: This is red
setFont
wordSearch.setFont( ef )
- Changes the font used to draw letters.
- ef - Name of font to use for letters. Set to
nil
to reset to default.
setLineWidth
wordSearch.setLineWidth( width )
- If running viewer, this will set the width of the lines.
- width - Width of lines and end-caps.
setTileSize
wordSearch.setTileSize( size )
- Set size of tiles.
- size - Width and height of tiles.
Posting Questions To The Forums
I will be providing help (exclusively) through the Corona SDK Forums. (Sorry: Direct e-mails and private messages will not be answered.)
When posting a question in the forums, be sure to follow these guidelines:
- Post to this forum: https://forums.coronalabs.com/forum/553-other-third-party-tools/
- Make sure the title starts with: Word Search Starter Kit and includes a short and meaninful name for the the problem.
- In the body of the post give me clear, concise, and precise description or question.
~ The Roaming Gamer
Copyright © Roaming Gamer, LLC. 2008-2017; All Rights Reserved