HTML and CSS Reference
In-Depth Information
colDelta
=
1
;
}
else
else iif
(
nextNode
.
x
<
currentNode
.
x
) {
colDelta
=-
1
}
else
else
{
colDelta
=
0
}
iif
(
nextNode
.
y
>
currentNode
.
y
) {
rowDelta
=
1
;
}
else
else iif
(
nextNode
.
y
<
currentNode
.
y
) {
rowDelta
=-
1
}
else
else
{
rowDelta
=
0
}
angleInRadians
=
Math
.
atan2
(
colDelta
,
rowDelta
);
tankMoving
=
true
true
;
}
tankX
+=
colDelta
;
tankY
+=
rowDelta
;
}
var
var
tankSourceX
=
Math
.
floor
(
3
%
5
)
*
32
;
var
var
tankSourceY
=
Math
.
floor
(
3
/
5
)
*
32
;
context
.
save
();
//save current state in stack
context
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
);
// reset to identity
context
.
translate
((
tankY
)
+
16
,(
tankX
)
+
16
);
context
.
rotate
(
angleInRadians
);
context
.
drawImage
(
tileSheet
,
tankSourceX
,
tankSourceY
,
32
,
32
,
-
16
,
-
16
,
32
,
32
);
context
.
restore
();
}
}
<
/script>
</head>
</head>
<body>
<body>
<div
<div style=
"position: absolute; top: 50px; left: 50px;"
>
<canvas
<canvas id=
"canvas"
width=
"500"
height=
"500"
>
Your browser does not support the HTML5 Canvas.
</canvas>
</canvas>
</div>
</div>