Hi Peach,
Thank you for your quick answer. Infact is my characters shape not a circle, instead I have defined my characters shape with a Physics Editor. This can not be seen because of my plug and play code above
I will try to post the “real” code.
[lua]function new()
local Level1 = display.newGroup()
display.setStatusBar( display.HiddenStatusBar ) – Hide Status Bar
– REQUIRED EXTERNAL LIBRARIES
local radlib = require “radlib”
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 ground
local leftWall
local rightWall
local Player
local topWall
– HUD OBJECTS
local Background
local HudBar
local tryAgainBtn
local menuBtn
local menuBtn1
local PauseOverlay
local ResetLevelBtn
–Background
Background = display.newImageRect(“Level1BGK.png”, 480, 320 )
Background.x = 240
Background.y = 160
Level1:insert(Background)
–Platform 1
Platform1 = display.newImageRect(“PFinal.png”, 205, 36)
physics.addBody(Platform1, “static”, physicsData:get(“PFinal”))
Platform1.x = 363
Platform1.y = 220
Platform1.myName = “Platform1”
–HUD BAR
HudBar = display.newImageRect(“HBar.png”, 480, 25 )
HudBar.x = 240
HudBar.y = 12
Level1:insert(HudBar)
–Ground
ground = display.newImageRect(“Ground.png”, 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 = 1, bounce = 1, isSensor = false})
physics.addBody(leftWall, “static”, {density = 1.0, friction = 1, bounce = 1, isSensor = false})
physics.addBody(rightWall, “static”, {density = 1.0, friction = 1, bounce = 1, isSensor = false})
–Pause Screen
local touchPause = function( event )
if event.phase == “began” then
if gameIsActive then
– Pause the game
gameIsActive = false
system.setIdleTimer( true ) – turn on device sleeping
– START PAUSE SCREEN
– Pause Overlay
pauseOverlay = display.newImageRect(“pauseoverlay.png”, 440, 277 )
pauseOverlay.x = 240; pauseOverlay.y = 170
pauseOverlay.isVisible = true
Level1:insert(pauseOverlay)
ResetLevelBtn = ui.newButton{
defaultSrc = “ResetLevel.png”,
defaultX = 170,
defaultY = 70,
overSrc = “ResetLevelPressed.png”,
overX = 170,
overY = 70,
onEvent = touchResetLevel,
id = “ResetLevelButton”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
ResetLevelBtn .xOrigin =350; ResetLevelBtn .yOrigin =248
ResetLevelBtn .isVisible = true
ResetLevelBtn.isActive = true
Level1:insert(ResetLevelBtn )
local touchResetLevel = function( event )
if event.phase == “release” and ResetLevelBtn.isActive == true then
print(“Button Was pressed”)
–main menu call
director:changeScene( “Level1”, “fade” )
end
end
menuBtn1 = ui.newButton{
defaultSrc = “MainMenu.png”,
defaultX = 170,
defaultY = 70,
overSrc = “MainMenuPressed.png”,
overX = 170,
overY = 70,
onEvent = touchMenuBtn1,
id = “menuButton1”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
menuBtn1.xOrigin =130; menuBtn1.yOrigin =248
menuBtn1.isVisible = true
menuBtn1.isActive = true
Level1:insert( menuBtn1 )
local touchMenuBtn1 = function( event )
if event.phase == “release” and menuBtn1.isActive == true then
print(“Button Was pressed”)
–main menu call
director:changeScene( “GotoMainMenu”, “fade” )
end
end
physics.pause()
else
– Unpause the game
system.setIdleTimer( false ) – turn off device sleeping
gameIsActive = true
if pauseOverlay then
pauseOverlay.isVisible = false;
display.remove( pauseOverlay )
pauseOverlay = nil
end
if menuBtn1 then
menuBtn1.isVisible = false
menuBtn1.isActive = false
menuBtn = nil
display.remove( menuBtn1 )
end
if ResetLevelBtn then
ResetLevelBtn.isVisible = false
ResetLevelBtn.isActive = false
ResetLevelBtn = nil
display.remove(ResetLevelBtn)
end
physics.start()
end
end
end
Runtime:addEventListener( “touch”, touchPause )
Player = display.newImageRect(“Player.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)
if event.other.myName == “ground” then
gameIsActive = false
physics.pause()
Runtime:removeEventListener( “touch”, touchPause )
Player:removeSelf()
print(“GameOver!”)
end
end
end
Player:addEventListener(“collision”, Player)
function onTilt( event )
physics.setGravity( ( 9.8 * remote.xGravity ), 0 )
end
Runtime:addEventListener( “accelerometer”, onTilt )
–Corns 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”
physics.addBody(coin[1],“static”, {isSensor = true})
physics.addBody(coin[2],“static”, {isSensor = true})
physics.addBody(coin[3],“static”,{isSensor = true})
local function onCollision( event )
if ( event.phase == “began” ) then
if event.object2.myName == “coin” and event.object1.myName == “Player” then
event.object2.alpha = 0.001
end
elseif ( event.phase == “ended” ) then
if event.object2.myName == “coin” and event.object1.myName == “Player” then
event.object2:removeSelf()
event.object2 = nil
end
end
Runtime:addEventListener( “collision”, onCollision )
– MUST return a display.newGroup()
return Level1
end [import]uid: 122802 topic_id: 22117 reply_id: 91224[/import]