-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
179 lines (111 loc) · 3.45 KB
/
script.js
File metadata and controls
179 lines (111 loc) · 3.45 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function idle2() {
alert("Please Press ENTER Key To Run.");
if (idleworkerId == 0) {
idleworkerId = setInterval(idle, 110);
}
}
//Key Check----------------------------------------------------------------
function keyCheck(event) {
//Run Control--------------------------------------------------------------
if (event.which == 13) {
if(creatBlockWorkerId==0){
creatBlockWorkerId=setInterval(createBlock,100);
}
if (runworkerId == 0) {
clearInterval(idleworkerId);
runworkerId = setInterval(run, 90);
}
}
if (bgMoveId == 0) {
bgMoveId = setInterval(movebg, 100);
}
// if(event.which==16){
// if(idleworkerId==0){
// idleworkerId=setInterval(idle,110);
// }
// }
//Jump Control------------------------------------------------------------
if (event.which == 32) {
if (jumpWorkerId == 0) {
clearInterval(idleworkerId);
clearInterval(runworkerId);
jumpWorkerId = setInterval(jump, 100);
}
}
}
//--------------------------------IDLE-------------------------------------//
//idle
idleImageId = 1;
idleworkerId = 0;
function idle() {
idleImageId++;
if (idleImageId == 11) {
idleImageId = 1;
}
robotId.src = "Idle (" + idleImageId + ").png";
}
//---------------------------------RUN------------------------------------//
//run
var robotId = document.getElementById("robot");
var runImageId = 1;
var runworkerId = 0;
function run() {
runImageId++;
if (runImageId == 9) {
runImageId = 1;
}
robotId.src = "Run (" + runImageId + ").png";
}
//----------------------------------JUMP---------------------------------//
//jump
var jumpImageID = 1;
var jumpWorkerId = 0;
var marginTopValue = 350;
function jump() {
if (jumpImageID <= 5) {
marginTopValue = marginTopValue - 30;
robotId.style.marginTop = marginTopValue + "px";
}
if (jumpImageID >= 6) {
marginTopValue = marginTopValue + 30;
robotId.style.marginTop = marginTopValue + "px";
}
jumpImageID++;
if (jumpImageID == 11) {
jumpImageID = 1;
clearInterval(jumpWorkerId);
jumpWorkerId = 0;
runworkerId = setInterval(run, 100);
}
robotId.src = "Jump (" + jumpImageID + ").png";
}
//-------------------------------BACKGROUND MOVE-------------------------------//
var bgImagePosision = 0;
var bgMoveId = 0;
function movebg() {
bgImagePosision = bgImagePosision - 30;
document.getElementById("background").style.backgroundPositionX = bgImagePosision + "px";
}
//create block
var blockMarginLeft = 200;
var creatBlockWorkerId = 0;
var blockId = 1;
function createBlock() {
var block = document.createElement("div");
block.className = "block";
block.id = "block" + blockId;
blockId++;
var gap = Math.random() * (1000 - 400) + 400;
blockMarginLeft = blockMarginLeft + gap;
block.style.marginLeft = blockMarginLeft + "px";
document.getElementById("background").appendChild(block);
}
var moveBlockWorkerId = 0;
function moveBlock() {
for (var i = 1; i <= blockId; i++) {
var curruntBlock = document.getElementById("block" + i);
var curruntBlockMarginLeft = curruntBlock.style.marginLeft;
var newBlockMarginLeft = parseInt(curruntBlockMarginLeft) - 20;
curruntBlock.style.marginLeft = newBlockMarginLeft + "px";
}
}