pop.base.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. window.requestAnimFrame = (function(){
  2. return window.requestAnimationFrame ||
  3. window.webkitRequestAnimationFrame ||
  4. window.mozRequestAnimationFrame ||
  5. window.oRequestAnimationFrame ||
  6. window.msRequestAnimationFrame ||
  7. function(/* function */ callback, /* DOMElement */ element){
  8. window.setTimeout(callback, 1000 / 60);
  9. };
  10. }());
  11. var POP = {
  12. canvas: null, // html canvas object
  13. ctx: null, // context for interacting with canvas
  14. W: 320, // shortcut for canvas width
  15. H: 480, // shortcut for canvas height
  16. offset: null, // offset from edge of screen to canvas
  17. debug: false,
  18. delay: 0,
  19. touches: [], // array to hold instances of Touch object
  20. explosions: [],
  21. bubbles: [], // array to hold instances of Bubbles object
  22. nextBubble: 100, // timelapse until next bubble released
  23. // track score
  24. score: { taps: 0, burst: 0, escapees: 0, accuracy: 0, seconds: 0, total: 0, name: '' },
  25. hiScore: localStorage.POP_hiScore || 0,
  26. newHiscore: false,
  27. lives: null,
  28. level: 1,
  29. MAX_LIVES: 3,
  30. state: 'splash',
  31. timer: null,
  32. gameStart: 0,
  33. secsElapsed: 0,
  34. bonus: null,
  35. wave: { r: 50, x: -25, y: -40, total: null },
  36. ua: { mobile: null, browser: null, version: null, platform: null, scale: 1 },
  37. // store mouse / click coordinates
  38. m: {
  39. x: null,
  40. y: null,
  41. r: 10,
  42. click: null,
  43. set: function(x, y) {
  44. this.x = x;
  45. this.y = y;
  46. this.click = true;
  47. },
  48. reset: function() {
  49. this.x = this.y = this.click = null;
  50. }
  51. },
  52. /**
  53. * generate a random integer
  54. *
  55. * @param integer range - generate number between 0 and range
  56. * @param integer offset - added onto random number
  57. * @return integer
  58. *
  59. */
  60. rnd: function(range, offset) {
  61. offset = offset || 0;
  62. return ~~( (Math.random() * range) + offset );
  63. }
  64. }