File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,12 @@ div.cylinder .bottom {
116
116
box-shadow : 0px 0px 10px rdba (0 , 0 , 0 , 0.75 );
117
117
}
118
118
119
+ img # ninja {
120
+ width : 80px ;
121
+ margin-top : -120px ;
122
+ position : absolute;
123
+ }
124
+
119
125
120
126
121
127
Original file line number Diff line number Diff line change 24
24
</ div >
25
25
26
26
< div class ="ground ">
27
+ < img src ="img/ninjas-green.png " id ="ninja "> </ img >
27
28
</ div >
28
29
29
30
< script type ="text/javascript " src ="js/jquery.js ">
Original file line number Diff line number Diff line change 1
1
var cylinder ;
2
2
var screenHeight = screen . height ;
3
3
var jumpBy = 10 ;
4
+ var ninja ;
5
+ var screenWidth = screen . width ;
6
+ var runBy = 10 ;
4
7
5
8
function startGame ( ) {
6
9
cylinder = $ ( "#cylinder" ) ;
10
+ ninja = $ ( "#ninja" ) ;
11
+ ninja . click ( function ( ) {
12
+ run ( ) ;
13
+ } ) ;
7
14
jump ( 10 ) ;
8
15
}
9
16
@@ -15,10 +22,27 @@ function jump() {
15
22
16
23
if ( bottomPosition >= screenHeight ) {
17
24
cylinder . css ( 'top' , '0px' ) ;
25
+ setRandomLeft ( ) ;
18
26
} else {
19
27
cylinder . css ( 'top' , newPosition + "px" ) ;
20
28
}
21
29
setTimeout ( jump , 30 ) ;
22
30
}
23
31
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
+
24
48
startGame ( ) ;
You can’t perform that action at this time.
0 commit comments