-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcollisionTest.html
54 lines (45 loc) · 1.13 KB
/
collisionTest.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
48
49
50
51
52
53
54
<!DOCTYPE HTML>
<html lang = "en">
<head>
<title>Collision test</title>
<meta charset = "UTF-8" />
<script type = "text/javascript"
src = "simpleGame.js"></script>
<script type = "text/javascript">
var game;
var scene;
var head;
var car;
var output;
function init(){
output = document.getElementById("output");
game = document.getElementById("game");
scene = new Scene(game);
head = new Sprite(game, "andyGoofy.gif", 50, 50);
car = new Sprite(game, "car.gif", 50, 30);
car.setAngle(0);
car.setSpeed(5);
scene.start();
} // end init
function update(){
scene.clear();
head.update();
car.update();
//report collisions
if (head.collidesWith(car)){
message = "collision";
} else {
message = "no collision";
} // end if
output.innerHTML = message;
} // end update
</script>
</head>
<body onload = "init()">
<canvas id = "game"
width = "400"
height = "400">
</canvas>
<div id = "output">default</div>
</body>
</html>