Skip to content

Commit 1551d62

Browse files
committed
Week 7 added the running ninja
1 parent f922cc1 commit 1551d62

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

www/css/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ div.cylinder .bottom {
116116
box-shadow: 0px 0px 10px rdba(0,0,0,0.75);
117117
}
118118

119+
img#ninja {
120+
width: 80px;
121+
margin-top: -120px;
122+
position: absolute;
123+
}
124+
119125

120126

121127

www/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</div>
2525

2626
<div class="ground">
27+
<img src="img/ninjas-green.png" id="ninja"></img>
2728
</div>
2829

2930
<script type="text/javascript" src="js/jquery.js">

www/js/jumpy.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
var cylinder;
22
var screenHeight = screen.height;
33
var jumpBy = 10;
4+
var ninja;
5+
var screenWidth = screen.width;
6+
var runBy = 10;
47

58
function startGame() {
69
cylinder = $("#cylinder");
10+
ninja = $("#ninja");
11+
ninja.click(function() {
12+
run();
13+
});
714
jump(10);
815
}
916

@@ -15,10 +22,27 @@ function jump() {
1522

1623
if(bottomPosition >= screenHeight) {
1724
cylinder.css('top','0px');
25+
setRandomLeft();
1826
} else {
1927
cylinder.css('top', newPosition+"px");
2028
}
2129
setTimeout(jump, 30);
2230
}
2331

32+
function setRandomLeft() {
33+
var leftPosition = Math.floor(Math.random() * 50) + 20;
34+
cylinder.css('margin-left', leftPosition + "%");
35+
}
36+
37+
function run() {
38+
var ninjaDimension = ninja.offset();
39+
var ninjaLeft = ninjaDimension.left;
40+
var newLeftPosition = ninjaLeft+runBy;
41+
console.log(newLeftPosition);
42+
ninja.css('left', newLeftPosition+"px");
43+
44+
run();
45+
46+
}
47+
2448
startGame();

0 commit comments

Comments
 (0)