Hey.
I saw your post last night but didn’t have time to post anything.
Here is some drag and drop code which does exactly what you asked.
The bit of interest to you is around line 130.
Feel free to ask any questions if you get stuck or anything.
display.setStatusBar(display.HiddenStatusBar)
physics = require("physics")
physics.start()
physics.setGravity(-9.8,0) -- change gravity to control the jump curve.
\_H = display.contentHeight;
\_W = display.contentWidth;
mRand = math.random;
canJump = false
--set up display groups
local background = display.newGroup()
local paralax1 = display.newGroup()
local paralax2 = display.newGroup()
local paralax3 = display.newGroup()
local groundgroup = display.newGroup()
local buttons = display.newGroup()
local enemies = display.newGroup()
local player = display.newGroup()
local player1 = display.newRect (0, 0, 50, 50)
player1.x = \_W / 2 - player1.contentWidth / 2
player1.y = \_H / 4 - player1.contentHeight
--player1:setFillColor(0, 0, 255)
physics.addBody(player1, {density = 1.0, friction = 0, bounce = 0.2})
player1.myName = "player1"
player:insert(player1)
local function jumpPlayer1 (event)
if canJump == true then
player1:applyLinearImpulse( 20, 0, player1.x, player1.y ) -- the first number in brakets is the jump height
end
canJump = false
end
--press red to shoot an arrow
local redButton = display.newCircle (0, 0, 30, 30)
redButton.x = \_W / 6
redButton.y = \_H - \_H / 10
redButton:setFillColor(255, 0, 0)
redButton.alpha = .75
--press blue to shoot an arrow
local blueButton = display.newCircle (0, 0, 30, 30)
blueButton.x = \_W / 6
blueButton.y = redButton.y - blueButton.contentHeight / 2 - \_H / 10
blueButton:setFillColor(0, 0, 255)
blueButton.alpha = .75
blueButton:addEventListener ("touch", jumpPlayer1)
local function shoot (event)
local arrow = display.newRect(0, 0, 5, 20)
arrow.x = player1.x + player1.contentWidth / 3
arrow.y = player1.y + player1.contentHeight / 2 + 3
arrow:setFillColor(255, 0, 0)
physics.addBody(arrow, "kinematic", {density = 10.0, friction = 0, bounce = 0})
arrow:setLinearVelocity( 0, 250)
arrow.myName = "arrow"
player:insert(arrow)
arrow.collision = onLocalCollision
arrow:addEventListener( "collision", arrow )
end
redButton:addEventListener ("tap", shoot)
local function spawnEnemy()
local enemy = display.newRect(0, 0, 50, 50)
enemy.x = \_W / 2 - enemy.contentWidth / 2 - 2
enemy.y = \_H --/ \_H - 50
enemy:setFillColor(255, 0, 0)
physics.addBody(enemy, {density = 0.01, friction = 0, bounce = 0})
enemy.myName = "enemy"
enemy:setLinearVelocity( 0, -100)
enemies:insert(enemy)
enemy.collision = onLocalCollision
enemy:addEventListener( "collision", enemy )
end
local firstground = display.newRect(0, 0, \_W / 3, \_H )
firstground.x = \_W / 3 - firstground.contentWidth / 2
firstground.y = \_H / 2
firstground:setFillColor(0, 255, 0)
physics.addBody(firstground, "kinematic", {density = 1.0, friction = 1, bounce = 0.2})
firstground.myName = "firstground"
firstground:setLinearVelocity( 0, -100)
groundgroup:insert(firstground)
local ground = display.newRect(0, 0, \_W / 3, \_H)
ground.x = \_W / 3 - ground.contentWidth / 2
ground.y = \_H + ground.contentHeight - \_H / 4
ground:setFillColor(0, 230, 0)
physics.addBody(ground, "kinematic", {density = 1.0, friction = 0, bounce = 0.2})
ground.myName = "ground"
ground:setLinearVelocity( 0, -100)
groundgroup:insert(ground)
function onLocalCollision( self, event )
if ( event.phase == "began" ) then
----------------------------------player hits enemy---------------------------------------------------------------------------
if (self.myName == "player1" and event.other.myName == "enemy") then
print("death")
local function deleteSelf()
player1:removeSelf()
end
Timer1 = timer.performWithDelay(1,deleteSelf, 1)
end
---------------------------------arrow hits enemy--------------------------------------------------------------------------
if (self.myName == "arrow" and event.other.myName == "enemy") then
print("ZAP!")
local function deleteBoth()
display.remove(self)
display.remove(event.other)
end
Timer1 = timer.performWithDelay(1,deleteBoth, 1)
end
---------------------------------player hits ground-------------------------------------------------------------------------------
if (self.myName == "player1" and event.other.myName == "ground") then
canJump = true
end
print( self.myName .. ": collision began with " .. event.other.myName )
---------------------------------player hits firsdtground-------------------------------------------------------------------------------
if (self.myName == "player1" and event.other.myName == "firstground") then
canJump = true
end
print( self.myName .. ": collision began with " .. event.other.myName )
-----------------------------------------------------------------------------------------------------------------------------------------
end
end
player1.collision = onLocalCollision
player1:addEventListener( "collision", player1 )
Timer1 = timer.performWithDelay(mRand(3000, 4500),spawnEnemy, 0)
Hope that helps 
Dan [import]uid: 67933 topic_id: 14740 reply_id: 54715[/import]