Sure. This is all basically copied from GvM where I was just taking what I thought was needed.
[code]module(…, package.seeall)
– Main function - MUST return a display.newGroup()
function new()
local gameGroup = display.newGroup()
gameGroup.x = -960
– MODULE-SPECIFIC VARIABLES
local backgroundFilename1 = “bar_background_01.png”
local backgroundFilename2 = “bar_background_02.png”
print( “Loaded Background File”)
– EXTERNAL MODULES / LIBRARIES
local movieclip = movieclip --require( “movieclip” )
local physics = require “physics”
local ui = ui --require(“ui”)
print( “Loaded Externals” )
– OBJECTS
local backgroundImage1
local backgroundImage2
local glass1
local glass2
local glass3
print( “Loaded Objects”)
–VARIABLES
local gameIsActive = false
local waitingForNewRound
local restartTimer
local ghostTween
local screenPosition = “left” --> “left” or “right”
local canSwipe = true
local swipeTween
local gameLives = 4
local gameScore = 0
local bestScore
local monsterCount
print( “Loaded Vairables” )
local drawBackground = function()
– Background gets drawn in this order: backdrop, clouds, trees, red glow
– BACKDROP
backgroundImage1 = display.newImageRect( backgroundFilename1, 960, 640 )
backgroundImage1:setReferencePoint( display.CenterLeftReferencePoint )
backgroundImage1.x = 0; backgroundImage1.y = display.contentHeight/2
backgroundImage2 = display.newImageRect( backgroundFilename2, 960, 640 )
backgroundImage2:setReferencePoint( display.CenterLeftReferencePoint )
backgroundImage2.x = 960; backgroundImage2.y = display.contentHeight/2
gameGroup:insert( backgroundImage1 )
gameGroup:insert( backgroundImage2 )
end
print( “Drew Background” )
local createTargets = function()
– GLASSES
glass1 = display.newImage( “to_mart_glass.png” )
glass1.x = 1220; glass1.y = 439
leftside = { -60,-75, -55,-75, 0,0, -5,0 }
rightside = { 55,-75, 65,-75, 0,5, 0,0 }
stem = { -3,0, 3,0, 3,76, -3,76 }
base = { -40,76, 40,76, 40,80, -40,80 }
glass2 = display.newImage( “to_mart_glass.png”)
glass2.x = 1410; glass2.y = 439
glass3 = display.newImage( “to_mart_glass.png” )
glass3.x = 1600; glass3.y = 439
physics.addBody( glass1, “dynamic”,
{ density=1.0, friction=0.5, bounce=0.2, shape=leftside },
{ density=1.0, friction=0.5, bounce=0.2, shape=rightside },
{ density=1.0, friction=0.5, bounce=0.2, shape=stem },
{ density=1.0, friction=0.5, bounce=0.2, shape=base }
)
physics.addBody( glass2, “dynamic”,
{ density=1.0, friction=0.5, bounce=0.2, shape=leftside },
{ density=1.0, friction=0.5, bounce=0.2, shape=rightside },
{ density=1.0, friction=0.5, bounce=0.2, shape=stem },
{ density=1.0, friction=0.5, bounce=0.2, shape=base }
)
physics.addBody( glass3, “dynamic”,
{ density=1.0, friction=0.5, bounce=0.2, shape=leftside },
{ density=1.0, friction=0.5, bounce=0.2, shape=rightside },
{ density=1.0, friction=0.5, bounce=0.2, shape=stem },
{ density=1.0, friction=0.5, bounce=0.2, shape=base }
)
gameGroup:insert( glass1 )
gameGroup:insert( glass2 )
gameGroup:insert( glass3 )
end
print( “Created Targets” )
local createGround = function()
–groundLight1 = display.newImageRect( “groundlight.png”, 228, 156 )
–groundLight1.x = 150; groundLight1.y = 190
groundObject1 = display.newImageRect( “bar_top1.png”, 960, 122 )
groundObject1:setReferencePoint( display.BottomLeftReferencePoint )
groundObject1.x = 0; groundObject1.y = display.contentHeight
groundObject2 = display.newImageRect( “bar_top2.png”, 960, 122 )
groundObject2:setReferencePoint( display.BottomLeftReferencePoint )
groundObject2.x = 960; groundObject2.y = display.contentHeight
groundObject1.myName = “ground”
groundObject2.myName = “ground”
local groundShape = { -480,-61, 480,-61, 480,61, -480,61 }
physics.addBody( groundObject1, “static”, { density=2.0, bounce=0, friction=0.5, shape=groundShape } )
physics.addBody( groundObject2, “static”, { density=2.0, bounce=0, friction=0.5, shape=groundShape } )
–gameGroup:insert( groundLight1 )
gameGroup:insert( groundObject1 )
gameGroup:insert( groundObject2 )
end
print( “Created Ground” )
print( “Start touch Funstion” )
local onScreenTouch = function( event )
if gameIsActive then
– Swipe to view other end of the screen
if leftRight == “left” and screenPosition == “left” and event.xStart > 360 then – Swiped game screen to the left
print( “Swiped left!” )
canSwipe = false
local switchPosition = function()
screenPosition = “right”
local swipeTimer = timer.performWithDelay( 200, function() canSwipe = true; end, 1 )
end
if swipeTween then transition.cancel( swipeTween )
end
if (event.xStart - event.x) >= 300 then
swipeTween = transition.to( gameGroup, { time=700, x=-960, onComplete=switchPosition } )
else
swipeTween = transition.to( gameGroup, { time=100, x=0, onComplete= function() canSwipe = true; end } )
end
elseif leftRight == “right” and screenPosition == “right” then – Swiped screen to the right
print( “Swiped right!” )
canSwipe = false
local switchPosition = function()
screenPosition = “left”
local swipeTimer = timer.performWithDelay( 200, function() canSwipe = true; end, 1 )
end
if swipeTween then
transition.cancel( swipeTween )
end
if (event.x - event.xStart) >= 100 then
swipeTween = transition.to( gameGroup, { time=700, x=0, onComplete=switchPosition } )
else
swipeTween = transition.to( gameGroup, { time=100, x=-960, onComplete=function() canSwipe = true; end } )
end
end
if canSwipe == true then
if screenPosition == “left” then
– Swipe left to go right
if event.xStart > 360 then
gameGroup.x = event.x - event.xStart
if gameGroup.x > 0 then
gameGroup.x = 0
canSwipe = true
end
end
elseif screenPosition == “right” then
– Swipe right to go to the left
gameGroup.x = (event.x - event.xStart) - 960
if gameGroup.x < -960 then
gameGroup.x = -960
canSwipe = true
end
end
end
end
print( “Game Init” )
local gameInit = function()
– PHYSICS
physics.start( true )
physics.setDrawMode( “hybrid” ) – set to “debug” or “hybrid” to see collision boundaries
physics.setGravity( 0, 11 ) --> 0, 9.8 = Earth-like gravity
– DRAW GAME OBJECTS
drawBackground()
createGround()
createTargets()
–createGhost()
– CREATE LEVEL
–createLevel()
– DRAW HEADS-UP DISPLAY (score, lives, etc)
–drawHUD()
end
gameInit()
– MUST return a display.newGroup()
return gameGroup
end
end[/code]
I hope this appears okay. I had a bit of trouble with the copy and paste. Also, I have left in some of the stuff that I commented out.
Any input would be helpful. There seems to be an awful lot of code involving swipetween and screenPosition.
Thanks! [import]uid: 93625 topic_id: 16261 reply_id: 61244[/import]