Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
  7. <title>BJ</title>
  8.     <style>
  9.         html, body {
  10.             margin: 0;
  11.             padding: 0;
  12.             background: #000;
  13.         }
  14.         #game-canvas {
  15.             padding: 0;
  16.             margin: 1px auto;
  17.             display: block;
  18.             width: 640px;
  19.             height: 480px;
  20.         }
  21.     </style>
  22.     <script src="app/phaser.min.js"></script>
  23. <script type="text/javascript">
  24. var BasicGame = {};
  25. String.prototype.toHHMMSS = function () {
  26.     var sec_num = parseInt(this, 10); // don't forget the second param
  27.     var hours   = Math.floor(sec_num / 3600);
  28.     var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
  29.     var seconds = sec_num - (hours * 3600) - (minutes * 60);
  30.  
  31.     if (hours   < 10) {hours   = "0"+hours;}
  32.     if (minutes < 10) {minutes = "0"+minutes;}
  33.     if (seconds < 10) {seconds = "0"+seconds;}
  34.     var time    = minutes+':'+seconds;
  35.  
  36.     return time;
  37. };
  38.  
  39. BasicGame.Boot = function (game) {
  40.     this.game;
  41. };
  42.  
  43. BasicGame.Boot.prototype = {
  44.     preload: function () {
  45.     this.load.image('preloaderBackground', 'assets/preloader/preloader_back.jpg');
  46.     this.load.image('preloaderBar', 'assets/preloader/progressbar_front.png');
  47.     },
  48.  
  49.     scaleStage:function(){
  50.         if (this.game.device.desktop) {
  51.             this.scale.pageAlignHorizontally = true;
  52.         } else {
  53.             this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
  54.             this.scale.maxWidth = 640;
  55.             this.scale.maxHeight = 480;
  56.             this.scale.forceLandscape = false;
  57.             this.scale.pageAlignHorizontally = false;
  58.             this.scale.setScreenSize(true);
  59.         }
  60.     },
  61.  
  62.     create: function () {
  63.     this.input.maxPointers = 1;
  64.     this.stage.disableVisibilityChange = false;
  65.     this.scaleStage();
  66.     this.state.start('Preloader');
  67.     }
  68. };
  69.  
  70. BasicGame.Preloader = function (game) {
  71.  
  72.     this.background = null;
  73.     this.preloadBar = null;
  74.     this.playButton = null;
  75.     this.ready = false;
  76. };
  77.  
  78. BasicGame.Preloader.prototype = {
  79.  
  80.     preload: function () {
  81.         this.background = this.add.sprite(0, 0, 'preloaderBackground');
  82.         this.preloadBar = this.add.sprite(this.game.world.centerX-100, this.game.world.centerY+0, 'preloaderBar');
  83.         this.load.setPreloadSprite(this.preloadBar);
  84.  
  85.         this.load.image('mainMenuBack', 'assets/images/back.png');
  86.         this.load.image('splash', 'assets/images/backback.png');
  87.         this.load.image('gameBack', 'assets/images/back1.png');
  88.  
  89.         this.load.spritesheet('mainPlayButton', 'assets/images/buttons/button_play.png', 191,76);
  90.         this.load.spritesheet('menuButton1', 'assets/images/buttons/button_menu2.png', 191,76);
  91.         this.load.spritesheet('playButton', 'assets/preloader/zibbo_play.jpg', 287,57);
  92.     },
  93.  
  94.     create: function () {
  95.         this.preloadBar.cropEnabled = false;
  96.         this.playButton = this.add.button(this.game.world.centerX-100, this.game.world.centerY+0, 'playButton', this.startGame, this, 0, 1, 0); //this.Branding
  97.         this.playButton.inputEnabled = true;
  98.         this.playButton.input.useHandCursor = true;
  99.     },
  100.  
  101.     update: function () {
  102.     },
  103.  
  104.     startGame: function (game) {
  105.         splashTop = this.add.sprite(this.game.world.centerX,this.game.world.centerY, "splash");
  106.         splashBottom = this.add.sprite(this.world.x,this.world.y, "splash");
  107.         splashTop.anchor.setTo(.5,.5);
  108.         splashTop.angle = 180;
  109.         topOut = this.add.tween(splashTop);
  110.         bottomOut = this.add.tween(splashBottom);
  111.         topOut.from({x:200, y:-200}, 400, Phaser.Easing.Linear.None, true);
  112.         bottomOut.from({x:this.world.x+200, y:this.world.y+200}, 400, Phaser.Easing.Linear.None, true);
  113.         topOut.onComplete.add(function(){
  114.             var tweenT = this.add.tween(splashTop).to({x:-200, y:-200}, 400, Phaser.Easing.Linear.None, true);
  115.             var tweenB = this.add.tween(splashBottom).to({x:this.world.x+280, y:this.world.y+280}, 400, Phaser.Easing.Linear.None, true);
  116.             tweenB.onComplete.add(function(){this.state.start('MainMenu')}, this);
  117.         },this);
  118.     }
  119.  
  120. };
  121.  
  122.  
  123. BasicGame.MainMenu = function (game) {
  124. };
  125.  
  126. BasicGame.MainMenu.prototype = {
  127.  
  128.     create: function () {
  129.         this.add.sprite(0, 0, 'mainMenuBack');
  130.         this.mainPlayButton = this.add.button(this.game.world.centerX-100, this.game.world.centerY, 'mainPlayButton', this.startPlay, this, 0, 1, 0);
  131.         this.mainPlayButton.inputEnabled = true;
  132.         this.mainPlayButton.input.useHandCursor = true;
  133.     },
  134.  
  135.     update: function () {
  136.     },
  137.  
  138.     startPlay: function (pointer) {
  139.         if (this.game.isSound) this.game.sndMenuClick.play();
  140.         splashTop = this.add.sprite(this.game.world.centerX,this.game.world.centerY, "splash");
  141.         splashBottom = this.add.sprite(this.world.x,this.world.y, "splash");
  142.         splashTop.anchor.setTo(.5,.5);
  143.         splashTop.angle = 180;
  144.         topOut = this.add.tween(splashTop);
  145.         bottomOut = this.add.tween(splashBottom);
  146.         topOut.from({x:200, y:-200}, 400, Phaser.Easing.Linear.None, true);
  147.         bottomOut.from({x:this.world.x+200, y:this.world.y+200}, 400, Phaser.Easing.Linear.None, true);
  148.         topOut.onComplete.add(function(){
  149.             var tweenT = this.add.tween(splashTop).to({x:-200, y:-200}, 400, Phaser.Easing.Linear.None, true);
  150.             var tweenB = this.add.tween(splashBottom).to({x:this.world.x+280, y:this.world.y+280}, 400, Phaser.Easing.Linear.None, true);
  151.             tweenB.onComplete.add(function(){this.state.start('Game')}, this);
  152.         },this);
  153.     }
  154. };
  155.  
  156. // переопределяем метод Tween.from - что-бы он возвращал свеже-созданный tween-объект
  157. var oldPahserTweenFrom = Phaser.Tween.prototype.from;
  158. Phaser.Tween.prototype.from=function(properties, duration, ease, autoStart, delay, repeat, yoyo) {
  159.     oldPahserTweenFrom.apply(this, arguments);
  160.     return this;
  161. }
  162. Phaser.Group.prototype.width=0;
  163.  
  164. BasicGame.Game = function (game) {
  165.     this.game;
  166.     this.add;
  167.     this.camera;
  168.     this.cache;
  169.     this.input;
  170.     this.load;
  171.     this.math;
  172.     this.sound;
  173.     this.stage;
  174.     this.time;
  175.     this.tweens;
  176.     this.state;
  177.     this.world;
  178.     this.particles;
  179.     this.physics;
  180.     this.rnd;
  181.     this.background = null;
  182.     this.timer = null;
  183. };
  184.  
  185. BasicGame.Game.prototype = {
  186.  
  187.     preload : function() {
  188.         this.score = 0;
  189.         this.scores = {'score':0};
  190.     },
  191.  
  192.     create: function () {
  193.         this.background = this.add.sprite(0, 0, 'gameBack');
  194.         this.menuButton = this.add.button(this.game.world.centerX-100, this.game.world.centerY, 'menuButton1', this.quitGame, this, 0, 1, 0);
  195.         this.menuButton.inputEnabled = true;
  196.         this.menuButton.input.useHandCursor = true;
  197.     },
  198.  
  199.     update: function () {
  200.     },
  201.  
  202.     quitGame: function (pointer) {
  203.        
  204.         splashTop = this.add.sprite(this.game.world.centerX,this.game.world.centerY, "splash");
  205.         console.log(splashTop);
  206.         splashBottom = this.add.sprite(this.world.x,this.world.y, "splash");
  207.         splashTop.anchor.setTo(.5,.5);
  208.         splashTop.angle = 180;
  209.         topOut = this.add.tween(splashTop);
  210.         bottomOut = this.add.tween(splashBottom);
  211.         topOut.from({x:200, y:-200}, 400, Phaser.Easing.Linear.None, true);
  212.         bottomOut.from({x:this.world.x+200, y:this.world.y+200}, 400, Phaser.Easing.Linear.None, true);
  213.         topOut.onComplete.add(function(){
  214.             var tweenT = this.add.tween(splashTop).to({x:-200, y:-200}, 400, Phaser.Easing.Linear.None, true);
  215.             var tweenB = this.add.tween(splashBottom).to({x:this.world.x+280, y:this.world.y+280}, 400, Phaser.Easing.Linear.None, true);
  216.             tweenB.onComplete.add(function(){
  217.                     this.state.start('MainMenu', true, false);
  218.  
  219.             }, this);
  220.         },this);
  221.  
  222.     }
  223. };
  224. </script>
  225.  
  226. </head>
  227. <body>
  228.     <div id="game-canvas"></div>
  229. <script type="text/javascript">
  230. (function () {
  231.     var game = new Phaser.Game(640,480, Phaser.AUTO, 'game-canvas');
  232.     game.grav = 400;
  233.     game.speed = 10 ;
  234.     game.state.add('Boot', BasicGame.Boot);
  235.     game.state.add('Preloader', BasicGame.Preloader);
  236.     game.state.add('MainMenu', BasicGame.MainMenu);
  237.     game.state.add('Game', BasicGame.Game);
  238.     game.state.add('Scores', BasicGame.Scores);
  239.     game.state.start('Boot');
  240.  
  241. })();
  242. </script>
  243. </body>
  244. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement