-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·261 lines (194 loc) · 5.4 KB
/
script.js
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
$(function() {
var housePost,
upKeyPressed = false;
$(window).keydown(sthMove);
function sthMove(event) {
//vars for character animation
var cSPost = $("#charAnime").position().left;
var imgsF = [-875, 0, -125, -250, -375, -500, -625, -750],
imgsB = [-1875, -1000, -1125, -1250, -1375, -1500, -1625, -1750],
numOfImgs = imgsF.length,
charSpeed = 3,
distance = numOfImgs * charSpeed,
changeMod = cSPost % distance;
//end of vars for character animation
function characterFaceForward() {
$("#charAnime").css({"left":"+=1"});
var i;
for (i = 0; i < numOfImgs; i++) {
var remainN = charSpeed * i;
if (changeMod == remainN) {
$("#character").css({"background-position":imgsF[i]+"px"});
}
}
}
function characterFaceBack() {
$("#charAnime").css({"left":"+=1"});
var i;
for (i = 0; i < numOfImgs; i++) {
var remainN = charSpeed * i;
if (changeMod == remainN) {
$("#character").css({"background-position":imgsB[i]+"px"});
}
}
}
function characterJump() {
if (!upKeyPressed) {
$("#character").stop(true).animate({bottom:"140px"}, 160, fallDown);
upKeyPressed = true;
}
}
function fallDown() {
$("#character").stop(true, true).animate({bottom:"50px"}, 150);
setTimeout(function() {
upKeyPressed = false;
}, 600);
}
var characterPost = $("#character").position().left;
if (characterPost <= -125 || characterPost < -64) {
$("#character").css({"left":"-64px"});
} else if (characterPost >= -64 && characterPost < 400) {
switch (event.which) {
case 39:
$("#character").css({"left":"+=4"});
characterFaceForward();
break;
case 37:
$("#character").css({"left":"-=4"});
characterFaceBack();
break;
case 38:
characterJump();
break;
}
} else {
var vidBgPost = $("#vidBg").position().left;
var mountPost = $("#mountains").position().left;
housePost = $("#houses").position().left;
var treePost = $("#trees").position().left;
var grassPost = $("#grass").position().left;
var groundPost = $("#ground").position().left;
function moveForward() {
$("#vidBg").css({"left":"-=0.3"});
$("#mountains").css({"left":"-=1"});
$("#houses").css({"left":"-=3"});
$("#trees").css({"left":"-=5"});
$("#grass").css({"left":"-=6"});
$("#ground").css({"left":"-=7"});
}
function moveBack() {
$("#vidBg").css({"left":"+=0.3"});
$("#mountains").css({"left":"+=1"});
$("#houses").css({"left":"+=3"});
$("#trees").css({"left":"+=5"});
$("#grass").css({"left":"+=6"});
$("#ground").css({"left":"+=7"});
}
if (housePost > -960 && housePost < 0) {
switch (event.which) {
case 39:
moveForward();
characterFaceForward();
break;
case 37:
moveBack();
characterFaceBack();
break;
case 38:
characterJump();
break;
}
} else if (housePost <= -960) {
switch (event.which) {
case 39:
$("#vidBg").css({"left":"-96"});
$("#mountains").css({"left":"-411"});
$("#houses").css({"left":"-960"});
$("#trees").css({"left":"-1600"});
$("#grass").css({"left":"-1920"});
$("#ground").css({"left":"-2240"});
//character
$("#character").css({"background-position":"-750px"});
if (housePost == -960) {
$("#panel").fadeIn(200);
}
break;
case 37:
moveBack();
characterFaceBack();
$("#panel").stop().fadeOut();
break;
case 38:
characterJump();
break;
}
} else if (housePost >= 0) {
switch (event.which) {
case 39:
moveForward();
characterFaceForward();
break;
case 37:
$("#vidBg").css({"left":"0"});
$("#mountains").css({"left":"-91"});
$("#houses").css({"left":"0"});
$("#trees").css({"left":"0"});
$("#grass").css({"left":"0"});
$("#ground").css({"left":"0"});
$("#character").css({"left":"-=4"});
characterFaceBack();
break;
case 38:
characterJump();
break;
}
}
}
console.log(characterPost, housePost, groundPost, mountPost, changeMod, vidBgPost);
} //end of sthMove function
//fortune panel starts
var howOpt;
$("button#butNext").click(
function(){
$("#preHappen").css({"display":"none"});
$("#happen").css({"display":"block"});
}
);
$("button#fortune").click(fortuneCheck);
function fortuneCheck() {
//get value
howOpt = document.getElementById("howOpt").value;
//end of get value
$("#result").text("");
setTimeout(randomChance, 150);
}
function randomChance() {
var n = Math.floor((Math.random() * 100) + 1);
if (howOpt < 34) {
if (n>=80) {
$("#result").text("Yes.");
} else if (n<80 && n>=60) {
$("#result").text("Maybe (50% chance yes and 50% chance no).");
} else {
$("#result").text("No.");
}
} else if (howOpt >= 34 && howOpt <= 68) {
if (n>=70) {
$("#result").text("Yes.");
} else if (n<70 && n>30) {
$("#result").text("Maybe (50% chance yes and 50% chance no).");
} else {
$("#result").text("No.");
}
} else {
if (n>=50) {
$("#result").text("Yes.");
} else if (n<50 && n>=25) {
$("#result").text("Maybe (50% chance yes and 50% chance no).");
} else {
$("#result").text("No.");
}
}
}
// ends of fortune panel
});