|
<lua>
module(..., package.seeall)
-->main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
--> This is how we start every single file or "screen" in our folder, except for main.lua
-- and director.lua
--> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
------------------------------------------------------------------------------
------------------------------------------------------------------------------
local physics = require ("physics")
physics.start ()
-->Background
local background = "" ("blackbackground.png")
localGroup:insert(background)
--> This sets the background
-->Gameboard
local gameboard = display.newImage ("gameboard.png")
gameboard.x = 310
gameboard.y = 200
localGroup:insert(gameboard)
-->This sets the gameboard
-->Table Array Begins
local gameboard = (1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16)
-->This creates the Table data
local redblock = display.newImage ("redblock.png")
localGroup:insert(redblock)
redblock.x = 70
redblock.y = 50
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if "began" == phase then
-- Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
-- Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif "moved" == phase or "ended" == phase or "cancelled" == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
-- Stop further propagtion of touch event!
return true
end
redblock:addEventListener( "touch", startDrag );
-->This ends the redblock drag code
local backbutton = display.newImage ("backbutton.png")
localGroup:insert(backbutton)
backbutton.x = 75
backbutton.y = 300
backbutton.xScale = .5
backbutton.yScale = .5
local function touchedBackbutton (event)
if ("ended" == event.phase) then
director:changeScene( "titlescreen", "fade" )
end
end
backbutton:addEventListener ("touch", touchedBackbutton)
-->MUST return a display.newGroup()
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--> This is how we end every file except for director and main, as mentioned in my first
return localGroup
end
</lua>