-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
101 lines (73 loc) · 2.2 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<body bgcolor="gray">
<img src="board.png" id='board' style='position:absolute; background-color: black; top:0; left:0; width:500; height:500; z-index:1;'>
<img src="index.jpeg" height="50" width="50" id='dude' style='position:absolute; top:0; left:0; z-index:3'>
<img src="51qc-TrpT-L.png" height="50" width="50" id='ball' style='position:absolute; top:200; left:0; z-index:2'>
<div id='scoreId' align="centre" style='position:absolute; top:500; z-index:4'><h1>DODGEBALL <i>Use the Arrow Keys</i></h1></div>
<script>
var dudeObj = document.getElementById('dude').style;
var xDude = 0;
var yDude = 0;
var ballObj = document.getElementById('ball').style;
var xBall = 0;
var yBall = 200;
var xSpeed = 10;
var ySpeed = 10;
var timerA;
moveTimer();
var score = 0;
var speedInc = 0;
document.onkeydown = KeyDownMoveIt;
function KeyDownMoveIt(e)
{
if (e.keyCode == 37)
xDude = xDude - 10 - speedInc*10;
if (e.keyCode == 39)
xDude = xDude + 10 + speedInc*10;
if (e.keyCode == 38)
yDude = yDude - 10 - speedInc*10;
if (e.keyCode == 40)
yDude = yDude + 10 + speedInc*10;
if (xDude > 500 - 50)
xDude = 500 - 50;
if (yDude > 500 - 50)
yDude = 500 - 50;
if (xDude < 0)
xDude = 0;
if (yDude < 0)
yDude = 0;
dudeObj.left = xDude;
dudeObj.top = yDude;
}
function moveTimer()
{
if (xBall + xSpeed > 500 - 50)
xSpeed = -5 * Math.random() - 5 - speedInc;
if (xBall + xSpeed < 0)
xSpeed = 5 * Math.random() + 5 + speedInc;
if (yBall + ySpeed > 500 - 50)
ySpeed = -5 * Math.random() - 5 - speedInc;
if (yBall + ySpeed < 0)
ySpeed = 5 * Math.random() + 5 + speedInc;
xBall = xBall + xSpeed;
yBall = yBall + ySpeed;
ballObj.left = xBall;
ballObj.top = yBall;
timerA = setTimeout('moveTimer()',40);
if ((xDude < xBall+50) && (xDude+50 > xBall) && (yDude < yBall+50) && (yDude+50 > yBall))
{
clearTimeout(timerA);
document.body.style.backgroundColor="red";
document.getElementById("scoreId").innerHTML = "Score: " + score;
timeRefresh(3000) ;
}
score++;
speedInc = score * 0.01;
function timeRefresh(timeoutPeriod)
{
setTimeout("location.reload(true);",timeoutPeriod);
}
}
</script>
</body>
</html>