HTML and CSS Reference
In-Depth Information
getBBox() on the SVG flock element <g id="flock"> . It will do all the heavy lift-
ing of calculating a box around the UFOs and return it to you as an object similar to { x:
20, y: 20, width: 325, height: 120 } .
To summarize, the logic flows like this:
1 . Get the bounding box of the UFO flock.
2 . Check if they've hit a wall (if so increment their positions differently).
3 . Increment each x/y as appropriate and check if the player lost.
4 . Toggle animations.
5 . Potentially shoot.
Now, create your update() method to move UFOs in the flock with this code.
Listing 7.23. game.js—UFO movement AI
Search WWH ::

Custom Search