Select Page
After much thought, and coding, I decided I didn’t want the ship to move around in space, I wanted space to move around the ship.

In other words, the player’s ship will have a constant screen x,y of width/2 and height/2, respectively. What will move are the player ship’s universe x,y coordinates. That poses a number of challenges, specifically:

  • Moving space around behind the ship, with parallaxing layers
  • Moving objects into the scene whenever they’re within a specific universe x,y range of the player’s ship, converting their universe x,y to screen x,y. This is actually pretty easy to do. Just take the difference between the planet’s ux,uy and the player’s ux,uy, and if their within visible range, set the planet’s screen x,y to the player’s screen x,y +/- the difference.
    • So if you have a player ux,uy of 500,500 and a planet ux,uy of 800,500 (just to keep it easy), you would see that the difference is only on the x-axis, and it’s +300 compared to the player’s ship.
    • Now, since the player’s screen x,y is fixed (say a screen of 1920×1080) at 960,540, you would just add 300 (from above) to 960 and your planet would appear at 1260,540.
    • Wait, why wouldn’t it show at 1260,500??? Because the 500 is the UNIVERSE’s y coordinate, not the screen’s. Remember you’re comparing ux,uy to ux,uy and then converting it to sx,sy. Since the player’s uy = 500 and the planet’s uy also = 500, the result is 0. So when you go to subtract or add the difference between the player’s sy and the objects sy, it will be a 0 difference.

Progress

  • Recoded the base system to be player-ship-centric, making everything move around the player’s ship when in space game mode.