-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbolle.html
265 lines (253 loc) · 11.2 KB
/
bolle.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
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
262
263
264
265
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Bolle - pompi maaliin!</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<!-- <script type="text/javascript" src="soundmanager2.js"></script>-->
<script type="text/javascript" src="jquery.easing.1.3.js"></script>
<script type="text/javascript" src="jquery.gamequery-0.4.0.js"></script>
<script type="text/javascript" src="jquery.gamequery.soundwrapper.html5-0.4.0.js"></script>
<!-- <script type="text/javascript" src="jquery.gamequery.soundwrapper.soundmanager2-0.4.0.js"></script>-->
<script type="text/javascript" src="jquery.collisioncheck-1.1.min.js"></script>
<script type="text/javascript" src="bolle.js"></script>
<script type="text/javascript">
$(function(){
var PLAYGROUND_HEIGHT = 250;
var PLAYGROUND_WIDTH = 700;
var playground = $("#playground").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH});
playground.addGroup("background", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
playground.addGroup("ground", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
playground.addGroup("foreground", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
playground.addGroup("ball", {width: 50, height: 50});
var background1 = new $.gameQuery.Animation({imageURL: "cave-background.png", type: 1});
$("#background").addSprite("background1", {animation: background1, width: PLAYGROUND_WIDTH*10, height: 250});
var ground1 = new $.gameQuery.Animation({imageURL: "cave-ground.png", type: 1});
$("#ground").addSprite("ground1", {animation: ground1, width: PLAYGROUND_WIDTH*30, height: 50, posy: PLAYGROUND_HEIGHT - 50});
var ball1 = new $.gameQuery.Animation({imageURL: "red_ball.png"});
var ball_collapse_animation = new $.gameQuery.Animation({imageURL: "ball_collapse.png", numberOfFrame: 8, delta: 50, rate: 100, type: 5});
$("#ball").addSprite("ball1", {animation: ball1, width: 50, height: 50, posy: PLAYGROUND_HEIGHT - 75, posx: PLAYGROUND_WIDTH/2 - 12});
var foreground1 = new $.gameQuery.Animation({imageURL: "rocks.png", type: 1});
$("#foreground").addSprite("foreground1", {animation: foreground1, width: PLAYGROUND_WIDTH*2, height: 25, posy: PLAYGROUND_HEIGHT - 25});
$("#ground").addSprite("arrow_right", {animation: new $.gameQuery.Animation({imageURL: "arrow_right.png"}), width: 150, height: 142, posy: PLAYGROUND_HEIGHT - 200, posx: 100});
$("#ground").addSprite("arrow_left", {animation: new $.gameQuery.Animation({imageURL: "arrow_left.png"}), width: 150, height: 142, posy: PLAYGROUND_HEIGHT - 200, posx: 6500});
var smaragds = [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000];
var smaragdAnimation = new $.gameQuery.Animation({imageURL: "smaragd_bling.png", numberOfFrame: 6, delta: 32, rate: 200, type: 1});
for(var i in smaragds){
addSmaragd(smaragds[i], 100);
}
var finalSmaragds = [[201, 90], [150, 140], [120, 190], [157, 220], [200, 190], [243, 220], [280, 190], [251, 140]];
for(var j in finalSmaragds){
addSmaragd(6000+finalSmaragds[j][0], PLAYGROUND_HEIGHT - finalSmaragds[j][1]);
}
var originalSmaragdCount = $(".smaragd").length;
var bugAnimation = new $.gameQuery.Animation({imageURL: "auto.png", numberOfFrame: 8, delta: 32, rate: 100, type: 1});
var bugs = [730, 1350, 2350, 3150, 3900, 4600, 5100, 5600, 6000];
for(var b in bugs){
var bxpos = bugs[b];
$("#ground").addSprite("bug_" + bxpos, {animation: bugAnimation, width: 42, height: 32, posy: PLAYGROUND_HEIGHT - 64, posx: bxpos});
$("#bug_" + bxpos).addClass("bug");
}
function Sound(src){
new Audio(src).load();
this.play = function(){
try{
var a = new Audio(src);
a.play();
}catch(error){}
}
}
var collect_smaragd = new Sound("./bell.ogg");
var blast = new Sound("./liquidblast.ogg");
var boink = new Sound("./boink.ogg");
var balle = new function(){
this.x = 0;
this.offsetX = function(){
return balle.movingLeft ? -1 : balle.movingRight ? 1 : 0;
};
this.onTheFloor = true;
this.movingLeft = false;
this.movingRight = false;
this.jump = function(){
if(this.onTheFloor){
boink.play();
this.onTheFloor = false;
$("#ball").animate({top: "-=150"}, 1000, "easeOutCirc", function(){
$("#ball").animate({top: "+=150"}, 1000, "easeInCirc", function(){
balle.onTheFloor = true;
})
})
}
}
};
var keyDownActions = function(e){
switch(e.keyCode){
case 37: //this is left! (a)
balle.movingLeft = true;
break;
case 39: //this is right (d)
balle.movingRight = true;
break;
}
};
var keyUpActions = function(e){
switch(e.keyCode){
case 37: //this is left! (a)
balle.movingLeft = false;
break;
case 39: //this is right (d)
balle.movingRight = false;
break;
case 32: //space
balle.jump();
break;
}
};
$(document).keydown(function(e){
keyDownActions(e);
});
$(document).keyup(function(e){
keyUpActions(e);
});
function addSmaragd(x, y){
$("#ground").addSprite("smaragd_" + x, {animation: smaragdAnimation, width: 32, height: 32, posy: y, posx: x});
$("#smaragd_" + x).addClass("smaragd");
}
function moveLayers(){
balle.x += balle.offsetX();
if(balle.x<0)balle.x=0;
if(balle.x>2015)balle.x=2015;
$("#background").css("left", -balle.x);
$("#ground").css("left", -balle.x*3);
$("#foreground").css("left", -balle.x*9 % PLAYGROUND_WIDTH);
}
function smaragdCollisionDetection(){
$("#ball1").collidesWith("#ground .smaragd").each(function(){
collect_smaragd.play();
$(this).remove();
});
}
function moveBugs(){
$("#playground").collidesWith("#ground .bug").each(function(){
var ele = $(this);
ele.css("left", parseFloat(ele.css("left"))-2.5);
})
}
function bugCollisionDetection(){
if($("#ball1").collidesWith("#ground .bug").length>0){
blast.play();
$("#ball1").setAnimation(ball_collapse_animation);
stopGame();
}
}
function currentPoints(){
return originalSmaragdCount - $(".smaragd").length;
}
function updatePoints(){
var oldPoints = $("#points").html();
var newPoints = currentPoints();
if(oldPoints!=newPoints){
$("#points").html(newPoints);
$("#points").animate({"font-size": "64px"}, 200, function(){
$("#points").animate({"font-size": "32px"}, 200);
});
}
}
function checkGameEnd(){
if(currentPoints()==originalSmaragdCount){
$("#endReason").html("Pääsit Pelin Läpi!!! ");
stopGame();
}
}
function advanceTheWorld(){
if(balle.offsetX()!=0){
moveLayers();
}
smaragdCollisionDetection();
moveBugs();
bugCollisionDetection();
updatePoints();
checkGameEnd();
}
function stopGame(){
clearInterval(worldInterval);
keyDownActions = function(){};
keyUpActions = function(){};
$("#endResult").html(currentPoints());
$("#endScreen").fadeTo(1000,1);
}
var worldInterval;
$().setLoadBar("loadingBar", 400);
$("#startbutton").click(function(){
$.playground().startGame(function(){
$("#welcomeScreen").fadeTo(1000,0,function(){$(this).hide();});
worldInterval = setInterval(advanceTheWorld, 30);
});
return false;
})
});
</script>
</head>
<body>
<style>
#welcomeScreen, #endScreen{
padding: 10px;
width: 700px;
height: 250px;
position: absolute;
z-index: 100;
color: white;
font-family: sans-serif;
}
#endScreen{
font-size: 32px;
display: none;
}
#endResult{
font-size: 42px;
color: green;
}
#startbutton{
font-size: 32px;
}
#points{
color: green;
float: right;
padding: 5px;
font-size: 32px;
position: absolute;
right: 0;
z-index: 2;
}
#playground{
width: 700px;
height: 250px;
background: black;
}
#playground .control_link{
text-align: center;
margin-top: 2em;
}
</style>
<div id="playground">
<div id="endScreen"><span id="endReason">Peli Loppui!</span> Sait <span id="endResult"></span> pistettä ☺<div class="control_link"><a href="#" onclick="location.reload();">Pelaa uudelleen!</a></div></div>
<div id="welcomeScreen">
Pompi ja vieri pallolla! Poimi smaragdit ja väistä piikittäjiä!!!
<div>
Ohjaus: <br />
← ja → näppäimet liikuttaa palloa. <br />
Välilyönnillä pallo pomppaa.
</div>
<div style="position: absolute; top: 120px; width: 700px; color: white;">
<div id="loadingBar" style="position: relative; left: 100px; height: 15px; width: 0; background: red;"></div>
<div class="control_link">
<a href="#" id="startbutton">Aloita tästä!</a>
</div>
</div>
</div>
<div id="points">0</div>
</div>
</body>
</html>