bounding "goodie" player within small area of screen

HI

I’m trying to understand the best way to stop the “goodie” player from leaving an area within the main area of the screen. I have  a second question on making movement more spaceship-like?

First Question

I’ve got a scrolling image which my “goodie” player is flying over. The goodie can fire a bullet and hit the “baddie”

To stop the goodie leaving the top and bottom of the screen I use something (nicked from Falkland’s youtube videoes) like:

 ceiling= display.newRect(  0, 0, 500, border )
    ceiling:setReferencePoint(display.BottomLeftReferencePoint)
    ceiling:setFillColor(255, 255, 255)
    ceiling.alpha = 0.0  – make invisible once happy.
    
    ceiling.x = 0 – done above but hopefully clearer here
    ceiling.y =   0
    physics.addBody(ceiling, “static”, {density=.1, bounce=0.1, friction=.2})

The above stops the goodie leaving the top of the screen.

Is it possible to do the same at the sides of the screen while still allowing the bullets to leave the area and the baddie to fly through. I’ve put similar at the side to stop the goodie leaving the screen but the same occurs with the bullets; I actually get quite a nice effect of bullets floating about but not really desired here.

Should I restrict side (x axis) movement with similar to above or use some kind of limit in the movement event? e.g.

          – joystick.joyX position of joystick on X axis between 0 and 1

          – local screenW = display.contentWidth

          – change = 10

          if ship.x > screenW then
             ship.x = screenW  – stop going too far right
          elseif (ship.x<100) then
              ship.x = 100  – stop going too far left
          else
              ship.x= ship.x + (change * joystick.joyX)
          end

This does work but you get a kangaroo/hopping effect.

Second question

Does anyone have any good tips on making movement more spaceship-like i.e. some acceleration at start and stop. As my view on the game is overhead, the gravity is neither X or Y based. If I move the joystick then I’d like to see a little bit of acceleration. On removing the joystick then I’d like to see a little deceleration then stop. In the above you can see:

ship.x= ship.x+(change * joystick.joyX)

This does work but in a way I’d like to movement to be not a function of joystick value (between 0 and 1). Not sure if I’ve explained this well.

I’m not sure addIMpulse or addForce works here as there is effectively no gravity.

Thanks

Jason