-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdriveCarArray.html
47 lines (44 loc) · 920 Bytes
/
driveCarArray.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>driveCarArray.html</title>
<script type = "text/javascript"
src = "simpleGame.js"></script>
<script type = "text/javascript">
var canv;
var scene;
var car;
function init(){
canv = document.getElementById("game");
scene = new Scene(canv);
car = new Sprite(canv, "car.gif", 50, 30);
car.setSpeed(1);
car.setAngle(0);
scene.start();
} // end init
function update(){
scene.clear()
if (keysDown[K_LEFT]){
car.changeAngleBy(-5);
}
if (keysDown[K_RIGHT]){
car.changeAngleBy(5);
}
if (keysDown[K_UP]){
car.changeSpeedBy(1);
}
if (keysDown[K_DOWN]){
car.changeSpeedBy(-1);
}
car.update();
} // end update
</script>
</head>
<body onload = "init()">
<h1>Drive car with array-based key input</h1>
<canvas id = "game"
height = "300"
width = "300"></canvas>
</body>
</html>