Guest User

Untitled

a guest
May 2nd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. //Globals
  2. var width = 900;
  3. var height = 700;
  4. var renderer = PIXI.autoDetectRenderer(width,height,{backgroundColor : 0x1099bb});
  5. var stage = new PIXI.Container();
  6. var animationStages = {menu:0, highscores:1, shop:2, options:3,exit:4,play:5};
  7. var animationStage = animationStages.menu;
  8. var entArray = [];
  9.  
  10.  
  11.  
  12. function start(){
  13. document.body.appendChild(renderer.view);
  14. showMenu(stage);
  15. requestAnimationFrame(animate);
  16. }
  17.  
  18. function animate(){
  19.  
  20. if(animationStage == animationStages.menu){
  21. //TODO: load player information
  22. }else if(animationStage == animationStages.highscores){
  23. //TODO: highscores display/refresh every x seconds
  24. }else if(animationStage == animationStages.shop){
  25. //TODO: modify player data securely
  26. }else if(animationStage == animationStages.options){
  27. //TODO: modify config file
  28. }else if(animationStage == animationStage.play){
  29. animateMainLoop();
  30. }
  31. renderer.render(stage);
  32. requestAnimationFrame(animate);
  33.  
  34. }
  35.  
  36. function startPress(eventData){
  37. console.log("starting game");
  38. animationStage = animationStages.play;
  39. cleanMenu();
  40. test();
  41.  
  42. }
  43.  
  44. function test(){
  45. for(var i = 0; i < 50; i++){
  46. var ballEnt = new PIXI.Sprite.fromImage("assets/mettalic_ball.png");
  47. ballEnt.tint = Math.random() * 0xFFFFFF;
  48. ballEnt.anchor.set(0.5);
  49. ballEnt.position.x = Math.random() * renderer.width;
  50. ballEnt.position.y = Math.random() * renderer.height;
  51.  
  52. ballEnt.direction = Math.random() * Math.PI * 2;
  53. ballEnt.speed = 2 + Math.random() * 2;
  54. entArray.push(ballEnt);
  55. stage.addChild(ballEnt);
  56. }
  57. }
  58. //Modified from code examples
  59. function animateMainLoop(){
  60. // create a bounding box for the little ballEnts
  61. var ballBoundingBoxPadding = 20;
  62. var ballBoundingBox = new PIXI.Rectangle(-ballBoundingBoxPadding,-ballBoundingBoxPadding,renderer.width + ballBoundingBoxPadding * 2, renderer.height + ballBoundingBoxPadding * 2);
  63.  
  64. for (var i = 0; i < entArray.length; i++)
  65. {
  66. var ballEnt = entArray[i];
  67.  
  68. ballEnt.position.x += Math.sin(ballEnt.direction) * ballEnt.speed;
  69. ballEnt.position.y += Math.cos(ballEnt.direction) * ballEnt.speed;
  70.  
  71.  
  72. // wrap the ballEnts by testing their bounds...
  73. if (ballEnt.position.x < ballBoundingBox.x)
  74. {
  75. ballEnt.position.x += ballBoundingBox.width;
  76. }
  77. else if (ballEnt.position.x > ballBoundingBox.x + ballBoundingBox.width)
  78. {
  79. ballEnt.position.x -= ballBoundingBox.width;
  80. }
  81.  
  82. if (ballEnt.position.y < ballBoundingBox.y)
  83. {
  84. ballEnt.position.y += ballBoundingBox.height;
  85. }
  86. else if (ballEnt.position.y > ballBoundingBox.y + ballBoundingBox.height)
  87. {
  88. ballEnt.position.y -= ballBoundingBox.height;
  89. }
  90. }
  91. }
Add Comment
Please, Sign In to add comment