Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
- <title>BJ</title>
- <style>
- html, body {
- margin: 0;
- padding: 0;
- background: #000;
- }
- #game-canvas {
- padding: 0;
- margin: 1px auto;
- display: block;
- width: 640px;
- height: 480px;
- }
- </style>
- <script src="app/phaser.min.js"></script>
- <script type="text/javascript">
- var BasicGame = {};
- String.prototype.toHHMMSS = function () {
- var sec_num = parseInt(this, 10); // don't forget the second param
- var hours = Math.floor(sec_num / 3600);
- var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
- var seconds = sec_num - (hours * 3600) - (minutes * 60);
- if (hours < 10) {hours = "0"+hours;}
- if (minutes < 10) {minutes = "0"+minutes;}
- if (seconds < 10) {seconds = "0"+seconds;}
- var time = minutes+':'+seconds;
- return time;
- };
- BasicGame.Boot = function (game) {
- this.game;
- };
- BasicGame.Boot.prototype = {
- preload: function () {
- this.load.image('preloaderBackground', 'assets/preloader/preloader_back.jpg');
- this.load.image('preloaderBar', 'assets/preloader/progressbar_front.png');
- },
- scaleStage:function(){
- if (this.game.device.desktop) {
- this.scale.pageAlignHorizontally = true;
- } else {
- this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
- this.scale.maxWidth = 640;
- this.scale.maxHeight = 480;
- this.scale.forceLandscape = false;
- this.scale.pageAlignHorizontally = false;
- this.scale.setScreenSize(true);
- }
- },
- create: function () {
- this.input.maxPointers = 1;
- this.stage.disableVisibilityChange = false;
- this.scaleStage();
- this.state.start('Preloader');
- }
- };
- BasicGame.Preloader = function (game) {
- this.background = null;
- this.preloadBar = null;
- this.playButton = null;
- this.ready = false;
- };
- BasicGame.Preloader.prototype = {
- preload: function () {
- this.background = this.add.sprite(0, 0, 'preloaderBackground');
- this.preloadBar = this.add.sprite(this.game.world.centerX-100, this.game.world.centerY+0, 'preloaderBar');
- this.load.setPreloadSprite(this.preloadBar);
- this.load.image('mainMenuBack', 'assets/images/back.png');
- this.load.image('splash', 'assets/images/backback.png');
- this.load.image('gameBack', 'assets/images/back1.png');
- this.load.spritesheet('mainPlayButton', 'assets/images/buttons/button_play.png', 191,76);
- this.load.spritesheet('menuButton1', 'assets/images/buttons/button_menu2.png', 191,76);
- this.load.spritesheet('playButton', 'assets/preloader/zibbo_play.jpg', 287,57);
- },
- create: function () {
- this.preloadBar.cropEnabled = false;
- this.playButton = this.add.button(this.game.world.centerX-100, this.game.world.centerY+0, 'playButton', this.startGame, this, 0, 1, 0); //this.Branding
- this.playButton.inputEnabled = true;
- this.playButton.input.useHandCursor = true;
- },
- update: function () {
- },
- startGame: function (game) {
- splashTop = this.add.sprite(this.game.world.centerX,this.game.world.centerY, "splash");
- splashBottom = this.add.sprite(this.world.x,this.world.y, "splash");
- splashTop.anchor.setTo(.5,.5);
- splashTop.angle = 180;
- topOut = this.add.tween(splashTop);
- bottomOut = this.add.tween(splashBottom);
- topOut.from({x:200, y:-200}, 400, Phaser.Easing.Linear.None, true);
- bottomOut.from({x:this.world.x+200, y:this.world.y+200}, 400, Phaser.Easing.Linear.None, true);
- topOut.onComplete.add(function(){
- var tweenT = this.add.tween(splashTop).to({x:-200, y:-200}, 400, Phaser.Easing.Linear.None, true);
- var tweenB = this.add.tween(splashBottom).to({x:this.world.x+280, y:this.world.y+280}, 400, Phaser.Easing.Linear.None, true);
- tweenB.onComplete.add(function(){this.state.start('MainMenu')}, this);
- },this);
- }
- };
- BasicGame.MainMenu = function (game) {
- };
- BasicGame.MainMenu.prototype = {
- create: function () {
- this.add.sprite(0, 0, 'mainMenuBack');
- this.mainPlayButton = this.add.button(this.game.world.centerX-100, this.game.world.centerY, 'mainPlayButton', this.startPlay, this, 0, 1, 0);
- this.mainPlayButton.inputEnabled = true;
- this.mainPlayButton.input.useHandCursor = true;
- },
- update: function () {
- },
- startPlay: function (pointer) {
- if (this.game.isSound) this.game.sndMenuClick.play();
- splashTop = this.add.sprite(this.game.world.centerX,this.game.world.centerY, "splash");
- splashBottom = this.add.sprite(this.world.x,this.world.y, "splash");
- splashTop.anchor.setTo(.5,.5);
- splashTop.angle = 180;
- topOut = this.add.tween(splashTop);
- bottomOut = this.add.tween(splashBottom);
- topOut.from({x:200, y:-200}, 400, Phaser.Easing.Linear.None, true);
- bottomOut.from({x:this.world.x+200, y:this.world.y+200}, 400, Phaser.Easing.Linear.None, true);
- topOut.onComplete.add(function(){
- var tweenT = this.add.tween(splashTop).to({x:-200, y:-200}, 400, Phaser.Easing.Linear.None, true);
- var tweenB = this.add.tween(splashBottom).to({x:this.world.x+280, y:this.world.y+280}, 400, Phaser.Easing.Linear.None, true);
- tweenB.onComplete.add(function(){this.state.start('Game')}, this);
- },this);
- }
- };
- // переопределяем метод Tween.from - что-бы он возвращал свеже-созданный tween-объект
- var oldPahserTweenFrom = Phaser.Tween.prototype.from;
- Phaser.Tween.prototype.from=function(properties, duration, ease, autoStart, delay, repeat, yoyo) {
- oldPahserTweenFrom.apply(this, arguments);
- return this;
- }
- Phaser.Group.prototype.width=0;
- BasicGame.Game = function (game) {
- this.game;
- this.add;
- this.camera;
- this.cache;
- this.input;
- this.load;
- this.math;
- this.sound;
- this.stage;
- this.time;
- this.tweens;
- this.state;
- this.world;
- this.particles;
- this.physics;
- this.rnd;
- this.background = null;
- this.timer = null;
- };
- BasicGame.Game.prototype = {
- preload : function() {
- this.score = 0;
- this.scores = {'score':0};
- },
- create: function () {
- this.background = this.add.sprite(0, 0, 'gameBack');
- this.menuButton = this.add.button(this.game.world.centerX-100, this.game.world.centerY, 'menuButton1', this.quitGame, this, 0, 1, 0);
- this.menuButton.inputEnabled = true;
- this.menuButton.input.useHandCursor = true;
- },
- update: function () {
- },
- quitGame: function (pointer) {
- splashTop = this.add.sprite(this.game.world.centerX,this.game.world.centerY, "splash");
- console.log(splashTop);
- splashBottom = this.add.sprite(this.world.x,this.world.y, "splash");
- splashTop.anchor.setTo(.5,.5);
- splashTop.angle = 180;
- topOut = this.add.tween(splashTop);
- bottomOut = this.add.tween(splashBottom);
- topOut.from({x:200, y:-200}, 400, Phaser.Easing.Linear.None, true);
- bottomOut.from({x:this.world.x+200, y:this.world.y+200}, 400, Phaser.Easing.Linear.None, true);
- topOut.onComplete.add(function(){
- var tweenT = this.add.tween(splashTop).to({x:-200, y:-200}, 400, Phaser.Easing.Linear.None, true);
- var tweenB = this.add.tween(splashBottom).to({x:this.world.x+280, y:this.world.y+280}, 400, Phaser.Easing.Linear.None, true);
- tweenB.onComplete.add(function(){
- this.state.start('MainMenu', true, false);
- }, this);
- },this);
- }
- };
- </script>
- </head>
- <body>
- <div id="game-canvas"></div>
- <script type="text/javascript">
- (function () {
- var game = new Phaser.Game(640,480, Phaser.AUTO, 'game-canvas');
- game.grav = 400;
- game.speed = 10 ;
- game.state.add('Boot', BasicGame.Boot);
- game.state.add('Preloader', BasicGame.Preloader);
- game.state.add('MainMenu', BasicGame.MainMenu);
- game.state.add('Game', BasicGame.Game);
- game.state.add('Scores', BasicGame.Scores);
- game.state.start('Boot');
- })();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement