HTML and CSS Reference
In-Depth Information
var
Paddle
= {
move
:
function
() {
if
(
Ctrl
.
left
&& (
this
.
x
<
Game
.
width
- (
this
.
w
/
2
))) {
this
.
x
+=
this
.
speed
;
}
else if
(
Ctrl
.
right
&&
this
.
x
> -
this
.
w
/
2
) {
this
.
x
+= -
this
.
speed
;
}
}
};
More key codes!
If you'd like to know more about the state of keyboard detection and get a complete list
of key codes, please see Jan Wolter's article “JavaScript Madness: Keyboard Events” (
ht-
Step 2: Add mouse control
Monitoring for mouse movement is similar to keyboard monitoring, except you need
to take into account the Canvas's position on the page and cross-reference it with the
mouse. To get the current mouse location, update
Ctrl.init()
and add a new
movePaddle()
method with the following listing.