-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenprog.html
More file actions
101 lines (90 loc) · 2.42 KB
/
genprog.html
File metadata and controls
101 lines (90 loc) · 2.42 KB
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
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#block
{
box-sizing:border-box;
position:absolute;
display:block;
height:30px;
width:30px;
background-color:red;
outline:2px solid #AA0000;
}
</style>
</head>
<body>
<span id="block" style=""></span>
<span class="object" style="width:100%;background-color:rebeccapurple;height:20px;display:block;position:absolute;bottom:0px;left:0px;"></span>
<span class="object" style="height:100%;background-color:rebeccapurple;width:20px;display:block;position:absolute;bottom:0px;left:0px;"></span>
</body>
<script type="text/javascript">
var objList = [];
document.getElementsByClassName("object").prototype.foreach(function(element, index, array) {objList.push(String.concat(element.getBoundingClientRect().top.toString(),",",element.getBoundingClientRect().left.toString(),",",element.getBoundingClientRect().bottom.toString(),",",element.getBoundingClientRect().right.toString()));});
console.debug(objList);
var block={
jump:0,
element:document.getElementById("block"),
gravity:"1",
x:0,
y:0,
velX:0,
velY:0,
move: function () {
if (this.y>0)
{
this.velY -= this.gravity;
}
else
{
this.velY = 0;
this.y=0;
this.jump = 0;
}
if(this.velX>0)
{
this.velX = (Math.round(10*(this.velX -.1 ))/10);
this.element.innerText=this.velX;
}
else if(this.velX<0)
{
this.velX = (Math.round(10*(this.velX +.1 ))/10);
this.element.innerText=this.velX;
}
},
collide: function () {
}
};
var charStr;
var keyState = {};
window.addEventListener('keydown',function(e){keyState[e.keyCode || e.which] = true;},true);
window.addEventListener('keyup',function(e){keyState[e.keyCode || e.which] = false;},true);
var renderWorld = setInterval(function(){
block.element.style.bottom=block.y.toString().concat("px");
block.element.style.left=block.x.toString().concat("px");
},1);
var velocity = setInterval(function(){
block.move();
},10);
setInterval(function(){
if (keyState[87] && block.jump != 1)
{
block.velY = 20;
block.jump = 1;
charStr="";
}
if (keyState[65])
{
block.velX = -5;
}
if (keyState[68])
{
block.velX = 5;
}
block.y += block.velY;
block.x += block.velX;
}, 10);
</script>
</html>