@@ -241,38 +241,53 @@ Phaser.Math = {
241241 * set an angle within the bounds of -PI to PI
242242 */
243243 normalizeAngle : function ( angle , radians ) {
244+
244245 if ( typeof radians === "undefined" ) { radians = true ; }
246+
245247 var rd = ( radians ) ? GameMath . PI : 180 ;
246248 return this . wrap ( angle , rd , - rd ) ;
249+
247250 } ,
248251
249252 /**
250253 * closest angle between two angles from a1 to a2
251254 * absolute value the return for exact angle
252255 */
253256 nearestAngleBetween : function ( a1 , a2 , radians ) {
257+
254258 if ( typeof radians === "undefined" ) { radians = true ; }
259+
255260 var rd = ( radians ) ? GameMath . PI : 180 ;
256261 a1 = this . normalizeAngle ( a1 , radians ) ;
257262 a2 = this . normalizeAngle ( a2 , radians ) ;
258- if ( a1 < - rd / 2 && a2 > rd / 2 ) {
263+
264+ if ( a1 < - rd / 2 && a2 > rd / 2 )
265+ {
259266 a1 += rd * 2 ;
260267 }
261- if ( a2 < - rd / 2 && a1 > rd / 2 ) {
268+
269+ if ( a2 < - rd / 2 && a1 > rd / 2 )
270+ {
262271 a2 += rd * 2 ;
263272 }
273+
264274 return a2 - a1 ;
275+
265276 } ,
266277
267278 /**
268279 * interpolate across the shortest arc between two angles
269280 */
270281 interpolateAngles : function ( a1 , a2 , weight , radians , ease ) {
282+
271283 if ( typeof radians === "undefined" ) { radians = true ; }
272284 if ( typeof ease === "undefined" ) { ease = null ; }
285+
273286 a1 = this . normalizeAngle ( a1 , radians ) ;
274287 a2 = this . normalizeAngleToAnother ( a2 , a1 , radians ) ;
288+
275289 return ( typeof ease === 'function' ) ? ease ( weight , a1 , a2 - a1 , 1 ) : this . interpolateFloat ( a1 , a2 , weight ) ;
290+
276291 } ,
277292
278293 /**
@@ -285,18 +300,29 @@ Phaser.Math = {
285300 * @return true if the roll passed, or false
286301 */
287302 chanceRoll : function ( chance ) {
303+
288304 if ( typeof chance === "undefined" ) { chance = 50 ; }
289- if ( chance <= 0 ) {
305+
306+ if ( chance <= 0 )
307+ {
290308 return false ;
291- } else if ( chance >= 100 ) {
309+ }
310+ else if ( chance >= 100 )
311+ {
292312 return true ;
293- } else {
294- if ( Math . random ( ) * 100 >= chance ) {
313+ }
314+ else
315+ {
316+ if ( Math . random ( ) * 100 >= chance )
317+ {
295318 return false ;
296- } else {
319+ }
320+ else
321+ {
297322 return true ;
298323 }
299324 }
325+
300326 } ,
301327
302328 /**
@@ -308,11 +334,16 @@ Phaser.Math = {
308334 * @return The new value
309335 */
310336 maxAdd : function ( value , amount , max ) {
337+
311338 value += amount ;
312- if ( value > max ) {
339+
340+ if ( value > max )
341+ {
313342 value = max ;
314343 }
344+
315345 return value ;
346+
316347 } ,
317348
318349 /**
@@ -324,11 +355,16 @@ Phaser.Math = {
324355 * @return The new value
325356 */
326357 minSub : function ( value , amount , min ) {
358+
327359 value -= amount ;
328- if ( value < min ) {
360+
361+ if ( value < min )
362+ {
329363 value = min ;
330364 }
365+
331366 return value ;
367+
332368 } ,
333369
334370 /**
@@ -341,12 +377,15 @@ Phaser.Math = {
341377 * @return The wrapped value
342378 */
343379 wrapValue : function ( value , amount , max ) {
380+
344381 var diff ;
345382 value = Math . abs ( value ) ;
346383 amount = Math . abs ( amount ) ;
347384 max = Math . abs ( max ) ;
348385 diff = ( value + amount ) % max ;
386+
349387 return diff ;
388+
350389 } ,
351390
352391 /**
@@ -366,11 +405,9 @@ Phaser.Math = {
366405 * @return True if the given number is odd. False if the given number is even.
367406 */
368407 isOdd : function ( n ) {
369- if ( n & 1 ) {
370- return true ;
371- } else {
372- return false ;
373- }
408+
409+ return ( n & 1 ) ;
410+
374411 } ,
375412
376413 /**
@@ -381,11 +418,16 @@ Phaser.Math = {
381418 * @return True if the given number is even. False if the given number is odd.
382419 */
383420 isEven : function ( n ) {
384- if ( n & 1 ) {
421+
422+ if ( n & 1 )
423+ {
385424 return false ;
386- } else {
425+ }
426+ else
427+ {
387428 return true ;
388429 }
430+
389431 } ,
390432
391433 /**
@@ -397,17 +439,25 @@ Phaser.Math = {
397439 * @return The new angle value, returns the same as the input angle if it was within bounds
398440 */
399441 wrapAngle : function ( angle ) {
442+
400443 var result = angle ;
444+
401445 // Nothing needs to change
402- if ( angle >= - 180 && angle <= 180 ) {
446+ if ( angle >= - 180 && angle <= 180 )
447+ {
403448 return angle ;
404449 }
450+
405451 // Else normalise it to -180, 180
406452 result = ( angle + 180 ) % 360 ;
407- if ( result < 0 ) {
453+
454+ if ( result < 0 )
455+ {
408456 result += 360 ;
409457 }
458+
410459 return result - 180 ;
460+
411461 } ,
412462
413463 /**
@@ -541,18 +591,27 @@ Phaser.Math = {
541591 * @return The random object that was selected.
542592 */
543593 getRandom : function ( objects , startIndex , length ) {
594+
544595 if ( typeof startIndex === "undefined" ) { startIndex = 0 ; }
545596 if ( typeof length === "undefined" ) { length = 0 ; }
546- if ( objects != null ) {
597+
598+ if ( objects != null ) {
599+
547600 var l = length ;
548- if ( ( l == 0 ) || ( l > objects . length - startIndex ) ) {
601+
602+ if ( ( l == 0 ) || ( l > objects . length - startIndex ) )
603+ {
549604 l = objects . length - startIndex ;
550605 }
551- if ( l > 0 ) {
606+
607+ if ( l > 0 )
608+ {
552609 return objects [ startIndex + Math . floor ( Math . random ( ) * l ) ] ;
553610 }
554611 }
612+
555613 return null ;
614+
556615 } ,
557616
558617 /**
@@ -563,8 +622,11 @@ Phaser.Math = {
563622 * @return The rounded value of that number.
564623 */
565624 floor : function ( value ) {
625+
566626 var n = value | 0 ;
627+
567628 return ( value > 0 ) ? ( n ) : ( ( n != value ) ? ( n - 1 ) : ( n ) ) ;
629+
568630 } ,
569631
570632 /**
0 commit comments