@@ -39,7 +39,20 @@ function runStart(elem) {
3939 setTimeout ( startGame , 500 )
4040}
4141
42+ let epilepsy = null ;
43+
4244function startGame ( ) {
45+ {
46+ let data = localStorage . getItem ( "epilepsy" )
47+ if ( data ) {
48+ epilepsy = Boolean ( Number ( data ) )
49+ }
50+ }
51+ if ( epilepsy === null ) {
52+ epilepsy = confirm ( "Before we start, just one question. (This wont be asked again). Do you have epilepsy? OK for yes. Cancel for NO" )
53+ localStorage . setItem ( "epilepsy" , epilepsy ?"1" :"0" )
54+ }
55+
4356 setupGame ( ) ;
4457 startAnimation1 ( )
4558}
@@ -48,6 +61,7 @@ let runner = document.getElementById("runner_running");
4861let ground = document . getElementById ( "ground" ) ;
4962
5063let gameIsOver = false ;
64+ let gameRunning = false ;
5165
5266function onFullScreenChange ( ) {
5367 if ( gameIsOver ) {
@@ -105,6 +119,7 @@ function setupGame(){
105119 ground . hidden = false ;
106120 runner . style . top = "-10px"
107121 runner . hidden = false ;
122+ gameRunning = true ;
108123 game . focus ( ) ;
109124}
110125
@@ -148,26 +163,38 @@ function gameLoop() {
148163function onFrame ( ) {
149164 manageKeys ( ) ;
150165 shiftLeft ( ) ;
151- checkCollisions ( ) ;
152166 manageObstacles ( ) ;
153167 manageJump ( ) ;
168+ checkCollisions ( ) ;
154169
155- // Rerequest the frame
156- lastFrameRequest = window . requestAnimationFrame ( onFrame ) ;
170+ if ( ! gameIsOver ) {
171+ // Rerequest the frame
172+ lastFrameRequest = window . requestAnimationFrame ( onFrame ) ;
173+ }
157174}
158175
159176function gameOver ( ) {
160177 let GO = document . getElementById ( "gameOver" ) ;
178+ function evil ( ) {
179+ GO . style . backgroundColor = "#" + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 )
180+ }
161181
162182 gameIsOver = true ;
183+ gameRunning = false ;
163184
164185 for ( const toClear of clearOnGameOver ) {
165186 clearInterval ( toClear ) ;
166187 }
167188
168189 window . cancelAnimationFrame ( lastFrameRequest ) ;
190+ document . getElementById ( "fs" ) . hidden = true ;
191+ document . getElementById ( "ng" ) . hidden = false ;
169192 game . hidden = true ;
170193 GO . hidden = false ;
194+ if ( ! epilepsy ) {
195+ setInterval ( evil , 10 ) ;
196+ }
197+
171198}
172199
173200function manageKeys ( ) {
@@ -220,6 +247,7 @@ function checkCollisions() {
220247 for ( const obstacle of obstacles ) {
221248 if ( collisionCheck ( runner , obstacle ) ) {
222249 gameOver ( ) ;
250+ return
223251 }
224252 }
225253}
@@ -275,4 +303,10 @@ function manageJump() {
275303 jumpStatus = - 1 ;
276304 }
277305 jumpStatus ++ ;
306+ }
307+
308+ function doTouchscreenStuff ( ) {
309+ if ( gameRunning ) {
310+ jump ( ) ;
311+ }
278312}
0 commit comments