December 2017
Beginner
211 pages
3h 24m
English
© Graeme Stuart 2017
Graeme Stuart, Introducing JavaScript Game Development , https://doi.org/10.1007/978-1-4842-3252-1_5
Graeme Stuart1
(1)Market Harborough, Leicestershire, UK
Asteroids, like ships, can be approximated to a circle for the purposes of collision detection. However, they should be irregular shapes, and each one should be unique. To achieve this we’ll make extensive use of the Math.random method to define the shape of our asteroids.
As a first stab, we’ll divide our circle into segments and draw a straight line from each segment to the next. We can do that by rotating the canvas in steps and drawing a line at each step before closing the path. We’ll want some randomness in the distance of the ...
Read now
Unlock full access