HTML and CSS Reference
In-Depth Information
iif
(
keyPressList
[
39
]
==
true
true
) {
//rotate clockwise
rotation
+=
rotationalVelocity
;;
}
}
function
function
update
() {
x
=
x
+
movingX
;
y
=
y
+
movingY
;
}
function
function
render
() {
//draw background and text
context
.
fillStyle
=
'#000000'
;
context
.
fillRect
(
0
,
0
,
200
,
200
);
context
.
fillStyle
=
'#ffffff'
;
context
.
font
=
'20px sans-serif'
;
context
.
textBaseline
=
'top'
;
context
.
fillText
(
"render/update"
,
0
,
180
);
//transformation
var
var
angleInRadians
=
rotation
*
Math
.
PI
/
180
;
context
.
save
();
//save current state in stack
context
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
);
// reset to identity
//translate the canvas origin to the center of the player
context
.
translate
(
x
+
.
5
*
width
,
y
+
.
5
*
height
);
context
.
rotate
(
angleInRadians
);
//drawShip
context
.
strokeStyle
=
'#ffffff'
;
context
.
beginPath
();
//hardcoding in locations
//facing right
context
.
moveTo
(
−
10
,
−
10
);
context
.
lineTo
(
10
,
0
);
context
.
moveTo
(
10
,
1
);
context
.
lineTo
(
−
10
,
10
);
context
.
lineTo
(
1
,
1
);
context
.
moveTo
(
1
,
−
1
);
context
.
lineTo
(
−
10
,
−
10
);
context
.
stroke
();