Code Asteroids Game

The line in my black box is supposed to be longer and leaning obliquely to the right. Why isn’t it cooperating?

To make it longer, increase the SHIP_SIZE, and to rotate it, change the angle.
Right now it’s 90 / 180 * Math.PI which rotates it by 90deg, so it’s standing vertically.

I’m not sure what’s supposed to happen, but if you want to let it grow, you’ll need to update the ship size in your update function, like ship.r = ship.r * 1.01.

1 Like

I have a new problem now. When my ship disappears at the top, it should reappear at the bottom and vice versa. Why isn’t it doing that? It is just completely disappearing. Please help!

There’s something wrong with your conditionals where you set the new position of the ship, this for example:

      if (ship.x < 0 - ship.r) {
        ship.x - canv.width + ship.r;

This doesn’t set a new position, you just do a calculation:
ship.x - canv.width + ship.r,
but don’t assign it to anything, so nothing happens. What you’d rather write is
ship.x = canv.width + ship.r

(same for all other conditions).

1 Like