@@ -81,11 +81,11 @@ overlaid on top of that, using absolutely positioned elements.
8181
8282(((performance)))In games and other programs that have to animate
8383((graphics)) and respond to user ((input)) without noticeable delay,
84- ((efficiency)) is important. Though the ((DOM)) was not originally
84+ ((efficiency)) is important. Although the ((DOM)) was not originally
8585designed for high-performance graphics, it is actually better at this
8686than you would expect. You saw some ((animation))s in
8787link:13_dom.html#animation[Chapter 13]. On a modern machine, a simple
88- game like this performs well even if we don't think about
88+ game like this performs well, even if we don't think about
8989((optimization)) much.
9090
9191(((canvas)))In the link:16_canvas.html#canvas[next chapter], we will
@@ -120,17 +120,17 @@ var simpleLevelPlan = [
120120----
121121
122122Both the fixed ((grid)) and the moving elements are included in the
123- plan. The _x_ characters stand for ((wall))s, the space characters are for empty
123+ plan. The `x` characters stand for ((wall))s, the space characters for empty
124124space, and the exclamation marks represent fixed, nonmoving lava tiles.
125125
126- (((level)))The @ defines the place where the ((player)) starts. Every _o_ is a
127- ((coin)), and the equal sign (= ) stands for a block of ((lava))
126+ (((level)))The `@` defines the place where the ((player)) starts. Every `o` is a
127+ ((coin)), and the equal sign (`=` ) stands for a block of ((lava))
128128that moves back and forth horizontally. Note that the ((grid)) for
129129these positions will be set to contain empty space, and another data
130130structure is used to track the position of such moving elements.
131131
132132(((bouncing)))We'll support two other kinds of moving ((lava)): the
133- pipe character (| ) for vertically moving blobs, and _v_ for
133+ pipe character (`|` ) for vertically moving blobs, and `v` for
134134_dripping_ lava—vertically moving lava that doesn't bounce back and
135135forth but only moves down, jumping back to its start position when it
136136hits the floor.
@@ -194,8 +194,8 @@ type of the square—`"wall"` or `"lava"`.
194194
195195The ((actor))s array holds objects that track the current position and
196196((state)) of the dynamic elements in the ((level)). Each of these is
197- expected to have a `pos` property giving its position (the
198- ((coordinates)) of its top-left corner), a `size` property giving its
197+ expected to have a `pos` property that gives its position (the
198+ ((coordinates)) of its top-left corner), a `size` property that gives its
199199size, and a `type` property that holds a string identifying the
200200element (`"lava"`, `"coin"`, or `"player"`).
201201
@@ -219,10 +219,9 @@ Level.prototype.isFinished = function() {
219219
220220== Actors ==
221221
222- [[vector]]
223- (((Vector type)))(((coordinates)))To store the position and size of an
224- actor, we will return to our trusty `Vector` type, which groups an x
225- coordinate and a y-coordinate into an object.
222+ [[vector]] (((Vector type)))(((coordinates)))To store the position and
223+ size of an actor, we will return to our trusty `Vector` type, which
224+ groups an x-coordinate and a y-coordinate into an object.
226225
227226// include_code
228227
@@ -281,7 +280,7 @@ Player.prototype.type = "player";
281280----
282281
283282Because a player is one-and-a-half squares high, its initial position
284- is set to be half a square above the position where the @ character
283+ is set to be half a square above the position where the `@` character
285284appeared. This way, its bottom aligns with the bottom of the square
286285it appeared in.
287286
@@ -364,7 +363,7 @@ time and motion inside them.
364363== Encapsulation as a burden ==
365364
366365(((programming style)))(((program size)))(((complexity)))Most of the
367- code in this chapter does not worry about ((encapsulation)). This has
366+ code in this chapter does not worry about ((encapsulation)) for
368367two reasons. First, encapsulation takes extra effort. It makes
369368programs bigger and requires additional concepts and interfaces to be
370369introduced. Since there is only so much code you can throw at a reader
@@ -599,7 +598,7 @@ left and one to the top right, to create a white halo effect.
599598(CSS))))(((max-height (CSS))))(((viewport)))We can't assume that
600599levels always fit in the viewport. That is why the
601600`scrollPlayerIntoView` call is needed—it ensures that if the level is
602- sticking out outside the viewport, we scroll that viewport to make
601+ protruding outside the viewport, we scroll that viewport to make
603602sure the player is near its center. The following ((CSS)) gives the
604603game's wrapping ((DOM)) element a maximum size and ensures that
605604anything that sticks out of the element's box is not visible. We also give the outer element a relative
@@ -772,7 +771,7 @@ Level.prototype.obstacleAt = function(pos, size) {
772771(((Math.floor function)))(((Math.ceil function)))This method computes the set
773772of grid squares that the body ((overlap))s with by using `Math.floor`
774773and `Math.ceil` on the body's ((coordinates)). Remember that ((grid)) squares
775- are 1-by- 1 units in size. By ((rounding)) the sides of a box up and
774+ are 1× 1 units in size. By ((rounding)) the sides of a box up and
776775down, we get the range of ((background)) squares that the box touches.
777776
778777image::img/game-grid.svg[alt="Finding collisions on a grid",width="3cm"]
@@ -927,8 +926,8 @@ Player.prototype.moveX = function(step, level, keys) {
927926};
928927----
929928
930- (((animation)))(((keyboard)))The motion is computed based on the state
931- of the left and right arrow keys. When a motion would cause the player to
929+ (((animation)))(((keyboard)))The horizontal motion is computed based on the state
930+ of the left and right arrow keys. When a motion causes the player to
932931hit something, the level's `playerTouched` method, which handles
933932things like dying in ((lava)) and collecting ((coin))s, is called.
934933Otherwise, the object updates its position.
@@ -966,7 +965,7 @@ is accelerated vertically to account for ((gravity)). The gravity,
966965game have been set by ((trial and error)). I tested various values
967966until I found a combination I liked.
968967
969- (((collision detection)))(((keyboard)))(((jumping)))Next we check for
968+ (((collision detection)))(((keyboard)))(((jumping)))Next, we check for
970969obstacles again. If we hit an obstacle, there are two possible
971970outcomes. When the up arrow is pressed _and_ we are moving down
972971(meaning the thing we hit is below us), the speed is set to a
@@ -1055,7 +1054,7 @@ an object with key codes as property names and key names as values,
10551054will return an object that tracks the current position of those keys.
10561055It registers event handlers for `"keydown"` and `"keyup"` events and,
10571056when the key code in the event is present in the set of codes that it
1058- is tracking, update the object.
1057+ is tracking, updates the object.
10591058
10601059// include_code
10611060
@@ -1302,7 +1301,7 @@ handler and interrupting or resuming the animation whenever the
13021301Esc key is hit.
13031302
13041303(((runAnimation function)))The `runAnimation` interface may not look
1305- like it is suitable for this, at first glance, but it is, if you
1304+ like it is suitable for this at first glance, but it is, if you
13061305rearrange the way `runLevel` calls it.
13071306
13081307(((variable,global)))(((trackKeys function)))When you have that
@@ -1311,7 +1310,7 @@ registering keyboard event handlers is somewhat problematic. The
13111310`arrows` object is currently a global variable, and its event handlers
13121311are kept around even when no game is running. You could say they _((leak))_ out of
13131312our system. Extend `trackKeys` to provide a way to
1314- unregister its handlers and then change `runLevel` to register its
1313+ unregister its handlers, and then change `runLevel` to register its
13151314handlers when it starts and unregister them again when it is
13161315finished.
13171316
0 commit comments