File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,6 +124,14 @@ img#ninja {
124124 position : absolute;
125125}
126126
127+ div # score {
128+ position : absolute;
129+ right : 5% ;
130+ top : 10% ;
131+ color : yellow;
132+ font-size : 50px ;
133+ }
134+
127135
128136
129137
Original file line number Diff line number Diff line change 1717 < div class ="cloud c4 "> </ div >
1818 </ div >
1919
20+ < div id ="score ">
21+ </ div >
22+
2023 < div id ="cylinder " class ="cylinder ">
2124 < div class ="top "> </ div >
2225 < div class ="middle "> </ div >
Original file line number Diff line number Diff line change @@ -4,14 +4,15 @@ var jumpBy = 10;
44var ninja ;
55var screenWidth = screen . width ;
66var runBy = 10 ;
7-
7+ var score ;
88
99function startGame ( ) {
1010 cylinder = $ ( "#cylinder" ) ;
1111 ninja = $ ( "#ninja" ) ;
1212 ninja . click ( function ( ) {
1313 run ( ) ;
1414 } ) ;
15+ score = 10 ;
1516 jump ( 10 ) ;
1617}
1718
@@ -48,6 +49,8 @@ function run() {
4849 }
4950 else if ( newLeftPosition < 0 ) {
5051 stop ( ) ;
52+ score = score * 2 ;
53+ updateScore ( ) ;
5154 }
5255 else {
5356 if ( isCollision ( ) ) {
@@ -57,7 +60,26 @@ function run() {
5760 setTimeout ( run , 20 ) ;
5861 }
5962 }
63+ }
6064
65+ function isCollision ( ) {
66+ var ninjaPosition = ninja . offset ( ) ;
67+ var cylinderPosition = cylinder . offset ( ) ;
68+ var ninjaLeft = ninjaPosition . left ;
69+ var ninjaRight = ninjaLeft + 80 ;
70+
71+ var cylinderLeft = cylinderPosition . left ;
72+ var cylinderRight = cylinderLeft + 50 ;
73+ var cylinderGap = screenHeight - ( cylinderPosition . top + 350 ) ;
74+
75+ if ( ninjaRight > cylinderLeft
76+ && ninjaLeft < cylinderRight
77+ && cylinderGap < 150 ) {
78+ return true ;
79+ } else {
80+ return false ;
81+ }
82+
6183}
6284
6385
@@ -73,4 +95,8 @@ function stop() {
7395
7496}
7597
98+ function updateScore ( ) {
99+ $ ( "#score" ) . html ( score ) ;
100+ }
101+
76102startGame ( ) ;
You can’t perform that action at this time.
0 commit comments