Learn by Building Workshop Skills GitHub Türkçe Workshop › Asteroids › Step 2 of 41
Where the ship is What we are doing The ship is an object: its position, the angle it faces and its velocity. resetShip puts it in the middle, facing
up. Angles in JavaScript are in radians : a full turn is 2 * Math.PI.
```js
let ship
function resetShip() {
ship = { x: canvas.width / 2, y: canvas.height / 2, angle: -Math.PI / 2, vx: 0, vy: 0 }
}
resetShip()
```What it means
The ship starts in the middle of the canvas (300, 225).
Angle 0 points right; because y grows downwards, Math.PI / 2 points down and -Math.PI / 2 points up.
vx and vy are its speed to the right and downwards, 0 for now.
Your turn
Above function draw() { write let ship and resetShip, followed by an empty line.
Above the draw() call at the bottom write resetShip().
Skills: Game states, Velocity and gravity
← Black space Which way it points →
All steps Black space Where the ship is Which way it points A triangle ship Which keys are down? Turning The game loop Thrust and drift A little friction A speed limit Around the screen Making a bullet Fire! Bullets fly A lifetime for bullets Making a rock Four big rocks Drawing the rocks Jagged rocks Drifting rocks When do two circles touch? Breaking a rock Bullets hit rocks Points Show the score Losing a life A rock hits the ship Show the lives What time is it? A moment of safety Blink while safe Waves of rocks The next wave Faster every wave One function to start Playing or over Game over Best score GAME OVER Play again Build it yourself: hyperspace