Thank you for your support, I tried it but unfortunately it is not working. Did I miss something - here is my code:
[lua]module(…, package.seeall)
display.setStatusBar( display.HiddenStatusBar ) – Hide Status Bar
function new()
local Level1 = display.newGroup()
– REQUIRED EXTERNAL LIBRARIES
local ui = require(“ui”)
local scaleFactor = 1
local physicsData = (require “Physics”).physicsData(scaleFactor)
– REQUIRED PHYSICS
local physics = require( “physics” )
physics.start()
physics.setGravity( 0, 9.5 )
physics.setDrawMode( “hybrid” )
–physics.setDrawMode( “debug” )
–GAME SEETTINGS
local gameIsActive = false
local levelCompleted = false
–OBJECTS
local Platform1
local Platform2
local ground
local leftWall
local rightWall
local Player
local topWall
– HUD OBJECTS
local Background
local GameOverDisplay
local tryAgainBtn
local menuBtn
local menuBtn1
local GameOverImage
local PauseOverlay
local ResetLevelBtn
–==*********************************************************************==–
–==*********************************************************************==–
–==*********************************************************************==–
–==*********************************************************************==–
–Background
Background = display.newImageRect(“Background.png”, 480, 320 )
Background.x = 240
Background.y = 160
Level1:insert(Background)
–Platform 2
Platform2 = display.newImageRect(“PFinal.png”, 205, 36)
physics.addBody(Platform2, “static”, physicsData:get(“PFinal”))
Platform2.x = 363
Platform2.y = 220
Platform2.myName = “Platform2”
Level1:insert(Platform2)
–Platform 1
Platform1 = display.newImageRect(“PFinalS.png”, 205, 36)
Platform1.x = 111
Platform1.y = 265
Platform1.myName = “Platform1”
physics.addBody(Platform1, “static”, physicsData:get(“PFinalS”))
Level1:insert(Platform1)
–Ground
ground = display.newRect( 0, 0, 479, 1 )
ground.x = 240
ground.y = 321
physics.addBody(ground, “static”, {bounce=0})
ground.myName = “ground”
Level1:insert(ground)
– create wall objects
topWall = display.newRect( 0, 0, display.contentWidth, 1)
topWall.alpha = 0
topWall.myName = “topWall”
leftWall = display.newRect( 0, 0, 1, display.contentHeight )
leftWall.alpha = 0
leftWall.myName = “leftWall”
rightWall = display.newRect( display.contentWidth - 1, 0, 1, display.contentHeight )
rightWall.myName = “rightWall”
rightWall.alpha = 0
– make them physics bodies
physics.addBody(topWall, “static”, {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})
physics.addBody(leftWall, “static”, {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})
physics.addBody(rightWall, “static”, {density = 1.0, friction = 0.3, bounce = 1, isSensor = false})
Level1:insert(topWall)
Level1:insert(leftWall)
Level1:insert(rightWall)
Player = display.newImageRect(“Player1.png”, 40, 40 )
physics.addBody( Player, “dynamic”, physicsData:get(“Player1”))
Player.x = 40
Player.y = 100
Player.myName = “Player”
Player.isFixedRotation = true
Player.iAwake = true
Player.isBullet = true
Level1:insert(Player)
function Player:collision (event)
if event.phase == “ended” and event.other.myName ~= “coin” and event.other.myName ~= “leftWall” and event.other.myName ~= “rightWall” and event.other.myName ~= “topWall” then
Player:applyForce(0,-40, Player.x, Player.y)
print(“Player Collided With Platform”)
end
end
Player:addEventListener(“collision”, Player)
local function doGameCompleted()
levelCompleted = true
print(“Level 1 was completed”)
end
– Moves the player along the x-axis
function onTilt( event )
physics.setGravity( ( 9.2 * event.xGravity ), 0 )
end
Runtime:addEventListener( “accelerometer”, onTilt )
–Coins to collect - total - 5
local coin = {}
coin[1] = display.newImageRect(“coin.png”, 20, 20)
coin[1].x = 160
coin[1].y = 238
coin[1].myName = “coin”
coin[2] = display.newImageRect(“coin.png”, 20, 20)
coin[2].x = 180
coin[2].y = 238
coin[2].myName = “coin”
coin[3] = display.newImageRect(“coin.png”, 20, 20)
coin[3].x = 200
coin[3].y = 238
coin[3].myName = “coin”
coin[4] = display.newImageRect(“coin.png”, 20, 20)
coin[4].x = 370
coin[4].y = 192
coin[4].myName = “coin”
coin[5] = display.newImageRect(“coin.png”, 20, 20)
coin[5].x = 390
coin[5].y = 192
coin[5].myName = “coin”
for i = 1, #coin do
physics.addBody(coin[i], “static”, {isSensor = true})
Level1:insert(coin[i])
end
local function onCollision( event )
if ( event.phase == “began” ) then
if event.object1.myName == “Player” and event.object2.myName == “coin” then
event.object2.alpha = 0.001
end
elseif ( event.phase == “ended” ) then
if event.object1.myName == “Player” and event.object2.myName == “coin” then
event.object2:removeSelf()
event.object2 = nil
CoinCollected = CoinCollected + 1
if (CoinCollected == CoinsToCollect) then
levelCompleted = true
doGameCompleted()
end
quotaText.text = " " … tostring(CoinCollected) …" / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 55
quotaText.y = 10
quotaText.size = 50
end
end
end
Runtime:addEventListener( “collision”, onCollision )
– Coin Collect Count
local CoinCollected = CoinsToCollect
quotaText = display.newText( “0 / 5”, 50, 309, “Arial”, 28 )
quotaText.text = " 0 / " … tostring(CoinsToCollect)
quotaText.xScale = 0.5; quotaText.yScale = 0.5
quotaText.x = 30
quotaText.y = 10
quotaText.size = 50
Level1:insert( quotaText )
–Level 1 StartModule
local levelNum = levelNumber
local levelDisplay = display.newText( “Level”, 240, 95, “Arial”, 84 )
levelDisplay:setTextColor( 220, 294, 220, 220 )
levelDisplay.text = "LEVEL " … tostring(levelNum)
levelDisplay.xScale = 0.05; levelDisplay.yScale = 0.05
levelDisplay.alpha = 0.75
levelDisplay.size = 180
levelDisplay.x = 240; levelDisplay.y = 100
Level1:insert( levelDisplay)
local hideLevelDisplay = function()
local removeIt = function()
levelDisplay:removeSelf()
levelDisplay = nil
end
local newY = levelDisplay.y - 50
transition.to( levelDisplay, { time=2000, alpha=0, y=newY, onComplete=removeIt } )
end
transition.to( levelDisplay, { time=500, xScale=0.5, yScale=0.5, onComplete=hideLevelDisplay } )
unloadMe = function()
physics.stop()
– STOP Timers, Runtime Listeners, Transitions, etc.
Player:addEventListener(“collision”, Player)
Runtime:removeEventListener( “collision”, onCollision )
Runtime:removeEventListener( “system”, onSystem )
hideLevelDisplay = nil
removeIt = nil
[/lua] Thank you very much in advance, I really appreciate it. [import]uid: 122802 topic_id: 22117 reply_id: 91988[/import]