how do i add additional photos to my jigsaw puzzle game so there is more to choose from? and is there a way to increase the amount of puzzle pieces? like if i wanted a jigsaw puzzle that had 15 puzzle pieces or 25 puzzle pieces. is there a way to do that and after they compleated the puzzle piece how would i let them go to the next one?
here is my code for gameplay:
local widget = require(“widget”)
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
_W = display.contentWidth
_H = display.contentHeight
puzzlePiecesCompleted = 0
totalPuzzlePieces = 9
puzzlePieceWidth = 120
puzzlePieceHeight = 120
puzzlePieceStartingY = {
80,220,360,500,640,780,920,1060,1200 }
puzzlePieceSlideUp = 140
puzzleWidth, puzzleHeight = 320, 320
puzzlePieces = {}
puzzlePieceCheckpoint = {
{x=-243,y=76},
{x=-160, y=76},
{x=-76, y=74},
{x=-243,y=177},
{x=-143, y=157},
{x=-57, y=147},
{x=-261,y=258},
{x=-176,y=250},
{x=-74,y=248}
}
puzzlePieceFinalPosition = {
{x=66, y=59},
{x=165, y=70},
{x=265, y=65},
{x=66, y=150},
{x=165, y=170},
{x=270, y=165},
{x=74, y=252},
{x=174, y=263},
{x=270, y=263}
}
playGameGroup = display.newGroup()
finishGameGroup = display.newGroup()
function shuffle(t)
local n = #t
while n > 2 do
local k = math.random(n)
t[n] = t[k]
t[k] = t[n]
n = n - 1
end
return t
end
local function onDrag(event)
local t = event.target
if event.phase == “began” then
t.xScale, t.yScale = 1.3, 1.3
t:toFront()
display.getCurrentStage():setFocus( t )
t.isFocus = true
xOrigin,yOrigin = t.x,t.y
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if “moved” == event.phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == event.phase
or “cancelled” == event.phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
if t.x <= puzzlePieceCheckpoint[t.id].x+30
and t.x >= puzzlePieceCheckpoint[t.id].x-30
and t.y <= puzzlePieceCheckpoint[t.id].y+30
and t.y >= puzzlePieceCheckpoint[t.id].y-30 then
puzzleGroup:insert(t)
t:toBack()
t.place = “moved”
t.x, t.y = puzzlePieceFinalPosition[t.id].x,
puzzlePieceFinalPosition[t.id].y
t:removeEventListener(“touch”,onDrag)
for i = 1, totalPuzzlePieces do
if puzzlePieces[i].place == “start”
and puzzlePieces[i].y > yOrigin then
puzzlePieces[i].y = puzzlePieces[i].y - puzzlePieceSlideUp
end
end
puzzlePiecesCompleted = puzzlePiecesCompleted+1
if puzzlePiecesCompleted == totalPuzzlePieces then
playGameGroup.isVisible = false
finishGameGroup.isVisible = true
end
else
t.xScale,t.yScale = 1,1
t.x, t.y = xOrigin, yOrigin
end
end
end
return true
end
function scene:createScene( event )
local group = self.view
puzzleGroup = display.newGroup()
woodBoard = display.newImageRect(“woodboard.png”, 480, 320)
woodBoard.x = 562
woodBoard.y = _H/2
woodBoard:toBack();
puzzleGroup:insert(woodBoard)
scrollView = widget.newScrollView
{
top=0,
left = _W - 160,
height=_H,
width = 160,
hideBackground = true,
scrollWidth = 50 ,
scrollHeight = 1000
}
local shufflePuzzleY = shuffle(puzzlePieceStartingY)
for i = 1, totalPuzzlePieces do
puzzlePieces[i] = display.newImageRect(i…".png", puzzlePieceWidth, puzzlePieceHeight)
puzzlePieces[i].x = 85
puzzlePieces[i].y = shufflePuzzleY[i]
puzzlePieces[i].id = i
puzzlePieces[i].place = “start”
puzzlePieces[i]:addEventListener(“touch”, onDrag)
scrollView:insert(puzzlePieces[i])
end
puzzleGroup:insert(scrollView)
playGameGroup:insert(puzzleGroup)
function returnToMenu(event)
if(event.phase == “ended”) then
storyboard.gotoScene(“menu”)
end
end
txt_gameComplete = display.newText(“Puzzle Complete”, 0,0,120,100,native.systemFont,22)
txt_gameComplete.x = 400
txt_gameComplete.y = _H/2 - 50
finishGameGroup:insert(txt_gameComplete)
txt_return = display.newText(“Return to Menu”, 0,0,120,100,native.systemFont,22)
txt_return.x, txt_return.y = 400, _H/2 + 50
txt_return:addEventListener(“touch”, returnToMenu)
finishGameGroup:insert(txt_return)
baseBG = display.newImageRect(“puzzle-base.png”, puzzleWidth, puzzleHeight)
baseBG.x, baseBG.y = 160, _H/2
finishGameGroup:insert(baseBG)
group:insert(finishGameGroup)
group:insert(playGameGroup)
finishGameGroup.isVisible = false
playGameGroup.isVisible = true
end
function scene:enterScene( event ) end
function scene:exitScene( event ) end
function scene:destroyScene( event ) end
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
return scene
and menu:
–
– Project: puzzle
– Description:
–
– Version: 1.0
– Managed with http://CoronaProjectManager.com
–
– Copyright 2014 . All Rights Reserved.
–
local widget = require “widget”
local storyboard = require ( “storyboard” )
local scene = storyboard.newScene ( )
function scene:createScene ( event )
local group = self.view
background = display.newImageRect (
“woodboard.png”, 480, 320 )
background.x = display.contentWidth *0.5
background.y = display.contentHeight *0.5
group:insert (background)
logo = display.newImageRect ( “logo.png”, 400, 54 )
logo.x = display.contentWidth/2
logo.y = 65
group:insert(logo)
– Function to handle button events
local function handleButtonEvent( event )
if ( “ended” == event.phase ) then
print( “start game” )
storyboard.gotoScene (“gameplay”)
end
end
function PlayBtnRelease ( )
print( “start game” )
storyboard.gotoScene (“gameplay”)
end
local button1 = widget.newButton
{
width = 240,
height = 120,
defaultFile = “button-play.png”,
overFile = “button-play.png”,
onEvent = handleButtonEvent
}
– Center the button
button1.x = display.contentCenterX
button1.y = display.contentCenterY
group:insert(button1)
playBtn = widget.newButton{
default=“logo.png”,
over=“button-play.png”,
width=200 , height=83 ,
–onRelease = onPlayBtnRelease
}
playBtn.x = display.contentWidth/2
playBtn.y = 115-- display.contentHeight/2
group:insert(playBtn)
end
function scene:enterScene ( event )
storyboard.removeScene ( “gameplay” )
end
scene:addEventListener ( “createScene”, scene )
scene:addEventListener ( “enterScene”, scene )
return scene