i need help
–
– level1.lua
–
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “physics” library
local physics = require (“physics”)
physics.start()
– forward declarations and other locals
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5
– BEGINNING OF YOUR IMPLEMENTATION
–
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
–
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
----------------------------------------------------
– CREATE STUFF HERE
----------------------------------------------------
– create a grey rectangle as the backdrop
local background = display.newRect( 0, 0, screenW, screenH )
background.anchorX = 0
background.anchorY = 0
background:setFillColor( .5 )
– make a car (off-screen), position it, and rotate slighly
local car = display.newImageRect( “images.png”, 90, 40 )
car.x, car.y = 160, 225
car.rotation = 0
local flag_pole = display.newLine( 450, 225, 450, 0 )
flag_pole.class = “flag”
– create a grass object and add physics (with custom shape)
local grass = display.newImageRect( “grass.png”, screenW, 82 )
grass.anchorX = 0
grass.anchorY = 1
grass.x, grass.y = 0, display.contentHeight
local ramp = display.newLine( 300, 242, 350, 200 )
local touch_axelerate = display.newRect( 400, 100, 100, 100 )
touch_axelerate:setFillColor(10/255, 10/255, 10/255)
touch_axelerate.alpha = 0.05
– makes a rectangle/button
local touch_axelerate2 = display.newRect( 100, 100, 100, 100 )
touch_axelerate2:setFillColor(10/255, 10/255, 10/255)
touch_axelerate2.alpha = 0.05
– define a shape that’s slightly shorter than image bounds (set draw mode to “hybrid” or “debug” to see)
--local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
----------------------------------------------------
– INSERT INTO GROUP HERE
----------------------------------------------------
– all display objects must be inserted into group
group:insert( background )
group:insert( ramp )
group:insert( grass )
group:insert( touch_axelerate )
group:insert( touch_axelerate2 )
group:insert( flag_pole )
group:insert( car )
----------------------------------------------------
– PHYSICS
----------------------------------------------------
– add physics to the car
physics.addBody( car, { density=1, friction=0.3, bounce=1 } )
physics.addBody( grass, “static”, { friction=0, } )
physics.addBody( ramp, “static”, { density=100, friction=0, bounce=.1 } )
physics.addBody( flag_pole, “static”)
flag_pole.isSensor = true
car:setLinearVelocity( 0, 0 )
function car:collision(e)
– only performs logic when the block is coliding with a wall
if (e.other.class == “flag”) then
– cannot remove objects during a collision, so wait a short moment for it to end
timer.performWithDelay(1000, function()
– gose to next level
--car:removeSelf()
storyboard.gotoScene( “level2” )
end, 1)
--storyboard.gotoScene( “level2” )
end
return true
end
--makes the car have reaction to wall
car:addEventListener(“collision”, car )
----------------------------------------------------
– MAKE BUTTONS
----------------------------------------------------
local function go()
– get current velocity then add some to the velocity
local vx, vy = car:getLinearVelocity( )
car:setLinearVelocity( vx+20, 0.0001 )
end
– turns rec into button
touch_axelerate:addEventListener( “touch”, go )
local function brake()
car:setLinearVelocity( -50, 0 )
end
touch_axelerate2:addEventListener( “touch”, brake )
end – end of createScene NO CODE BELOW HERE!!!
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
physics.start()
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
--local group = self.view
--car:removeEventListener( “collision”, car )
physics.stop()
--car:removeEventListener( “collision”, car )
package.loaded[physics] = nil
physics = nil
print( “exitScene” )
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
print( “destroyScene” )
end
– makes a rectangle/button
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene