Skip to content

Commit f922cc1

Browse files
committed
Updated to make cylinder move
1 parent 4da7e53 commit f922cc1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

www/css/style.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ body {
33
}
44

55
div.clouds {
6-
padding-top: 100px;
6+
padding-top: 0px;
7+
position: absolute;
8+
79
}
810

911
div.cloud {

www/js/jumpy.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
var cylinder;
2+
var screenHeight = screen.height;
3+
var jumpBy = 10;
24

35
function startGame() {
46
cylinder = $("#cylinder");
57
jump(10);
68
}
79

8-
function jump(jumpBy) {
9-
var currentPosition = cylinder.css('top');
10-
alert(currentPosition);
10+
function jump() {
11+
var cylinderDimension = cylinder.offset();
12+
var currentPosition = cylinderDimension.top;
13+
var bottomPosition = 320+currentPosition;
14+
var newPosition = currentPosition+jumpBy;
15+
16+
if(bottomPosition >= screenHeight) {
17+
cylinder.css('top','0px');
18+
} else {
19+
cylinder.css('top', newPosition+"px");
20+
}
21+
setTimeout(jump, 30);
1122
}
1223

1324
startGame();

0 commit comments

Comments
 (0)