spawning object on section of the screen ?

I have been messing around with the flight path code found here : https://github.com/ansca/Flight-Path I have picked it apart but a few questions have came to mind which I cannot solve.

The method to spawn a plane looks like this:

  
-- Will Spawn a random plane outside the screen, that will be traveling towards the center of the screen  
function spawnRandomPlane()  
  
 local angle = math.random(1, 360)-- Generate a random angle for this plane to be positioned relative to the center of the screen  
 local lengthFromCenter = display.contentHeight \* (3/4) -- How far the planes will spawn from the center  
  
 local plane = getRandomPlane(lengthFromCenter \* math.cos(math.rad(angle)) + display.contentWidth / 2, lengthFromCenter \* math.sin(math.rad(angle)) \* -1 + display.contentHeight / 2)  
  
 plane.rotation = -90 - angle -- Calcualte the rotation of the plane (so it faces towards the center)  
  
 plane.touch = onPlaneTouched  
 plane:addEventListener("touch", plane)  
  
 plane.collision = onPlaneCollision  
 plane:addEventListener("collision", plane)  
  
 -- Set the plane speed  
 plane:setLinearVelocity( math.cos(math.rad(angle)) \* planeSpeed \* -1, math.sin(math.rad(angle)) \* planeSpeed )  
end  
  
function getRandomPlane(posX, posY)  
  
 local planeIndex = math.random(1, #planeImages)  
  
 local planeImage = planeImages[planeIndex]  
 local plane = display.newImage( planeImage.body)  
  
 plane.x = posX  
 plane.y = posY  
  
 local physicsData = (require "planeShape").physicsData(1)  
 physics.addBody(plane, "dynamic", physicsData:get("plane"))  
  
 plane.type = planeIndex  
  
 return plane  
end  
  

Is there anyway to edit this code so that I can specify a set of coordinates on the screen for planes to spawn from?

how would the coordinates of say:

  
x-------x  
| |  
| |  
| |  
x-------x  
  

be listed?

Thanks in advance, Lewis.
[import]uid: 68741 topic_id: 11518 reply_id: 311518[/import]

the code you posted was was randomizing location in polar coordinates and then while passing them to getRandomPlane function, converting it in cartesian coordinates

[lua]-- Will Spawn a random plane outside the screen, that will be traveling towards the center of the screen
function spawnRandomPlane()

– suppose you want the plane to start within following rectangle
– (100,200) (200,200)
– x-------x

-------
-------

– x-------x
– (100,300) (200,300)

– here your startx = 100, starty = 200, endx = 200, endy = 300

local startx = 100, starty = 200, endx = 200, endy = 300

local randomx = math.random(startx,endx)
local randomy = math.random(starty,endy)

local plane = getRandomPlane(randomx, randomy)

plane.touch = onPlaneTouched
plane:addEventListener(“touch”, plane)

plane.collision = onPlaneCollision
plane:addEventListener(“collision”, plane)

– Set the plane speed
plane:setLinearVelocity( math.cos(math.rad(angle)) * planeSpeed * -1, math.sin(math.rad(angle)) * planeSpeed )
end
function getRandomPlane(posX, posY)

local planeIndex = math.random(1, #planeImages)

local planeImage = planeImages[planeIndex]
local plane = display.newImage( planeImage.body)

plane.x = posX
plane.y = posY

local physicsData = (require “planeShape”).physicsData(1)
physics.addBody(plane, “dynamic”, physicsData:get(“plane”))

plane.type = planeIndex

return plane
end[/lua] [import]uid: 48521 topic_id: 11518 reply_id: 41812[/import]