HTML and CSS Reference
In-Depth Information
keyPressList
=
[];
gameLoop
()
}
function
function
runGame
() {
camera
.
dx
=
0
;
camera
.
dy
=
0
;
//check input
iif
(
keyPressList
[
38
]){
console
.
log
(
"up"
);
camera
.
dy
=-
world
.
tileHeight
;
}
iif
(
keyPressList
[
40
]){
console
.
log
(
"down"
);
camera
.
dy
=
world
.
tileHeight
;
}
iif
(
keyPressList
[
37
]){
console
.
log
(
"left"
);
camera
.
dx
=-
world
.
tileWidth
;
}
iif
(
keyPressList
[
39
]){
console
.
log
(
"right"
);
camera
.
dx
=
world
.
tileWidth
;
}
camera
.
x
+=
camera
.
dx
;
camera
.
y
+=
camera
.
dy
;
iif
(
camera
.
x
<
0
) {
camera
.
x
=
0
;
}
else
else iif
(
camera
.
x
>
(
world
.
width
-
camera
.
width
)
-
world
.
tileWidth
) {
camera
.
x
=
world
.
width
-
camera
.
width
;
}
iif
(
camera
.
y
<
0
) {
camera
.
y
=
0
;
}
else
else iif
(
camera
.
y
>
(
world
.
height
-
camera
.
height
)
-
world
.
tileHeight
) {
camera
.
y
=
world
.
height
-
camera
.
height
;
}
context
.
fillStyle
=
'#000000'
;
context
.
fillRect
(
0
,
0
,
theCanvas
.
width
,
theCanvas
.
height
);