Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. var Game = {};
  2.  
  3. Game.Boot = function(){};
  4.  
  5. //Loading the loading screen
  6.  
  7. Game.Boot.prototype = {
  8.  
  9. init: function() {
  10. this.input.maxPointers = 1;
  11.  
  12. this.stage.disableVisibilityChange = true;
  13. },
  14.  
  15. //Assets we need for the loading screen
  16. preload: function() {
  17. this.load.image('logo', 'assets/diamond.png');
  18. this.load.image('preloader', 'assets/redblock.png');
  19. },
  20.  
  21. create: function() {
  22. //Pass the torch to preload
  23. this.state.start('Preload');
  24. }
  25. };
  26.  
  27. // ----PRELOAD.JS----
  28.  
  29.  
  30. Game.Preload = function(){
  31. this.preloadBar = null;
  32. };
  33.  
  34. Game.Preload.prototype = {
  35. preload: function() {
  36. //Logo rendering
  37. //this.splash = this.add.sprite(this.game.world.centerX, this.game.world.centerY, 'logo');
  38. //this.splash.anchor.setTo(0.5);
  39.  
  40. //Preload bar rendering
  41. this.preloadBar = this.add.sprite(this.world.centerX, this.world.centerY + 25, 'preloader');
  42. this.preloadBar.anchor.setTo(0.5);
  43. this.time.advancedTiming = true;
  44. this.load.setPreloadSprite(this.preloadBar);
  45.  
  46. //Asset loading
  47. this.load.tilemap('map', 'assets/maps/level1.csv');
  48. this.load.image('tileset', 'assets/brownblock.png');
  49. this.load.image('player', 'assets/blackblock.png');
  50. this.load.spritesheet('buttons', 'assets/button_sprite_sheet.png', 193, 71);
  51. },
  52.  
  53. create: function() {
  54. //Pass the torch to MainMenu
  55. this.game.state.start('MainMenu');
  56. }
  57. };
  58.  
  59.  
  60. // ----MAINMENU.JS-----
  61.  
  62.  
  63.  
  64. Game.MainMenu = function(){};
  65.  
  66. var map;
  67. var layer;
  68.  
  69. var player;
  70. var controls = {};
  71. var playerSpeed = 350;
  72. var jumpTimer = 0;
  73.  
  74. ///var button;
  75.  
  76. Game.MainMenu = {
  77. preload: function() {
  78.  
  79. },
  80.  
  81. create: function() {
  82. //Background color definition
  83. this.stage.backgroundColor = '#d3d3d3';
  84.  
  85. //Map initialization
  86. map = this.add.tilemap('map', 50, 50)
  87. map.addTilesetImage('tileset');
  88. layer = map.createLayer(0);
  89. layer.resizeWorld();
  90.  
  91. //Collision/Physics
  92. this.physics.arcade.gravity.y = 1400;
  93. map.setCollisionBetween(0,0);
  94.  
  95. //Set player
  96. player = this.add.sprite(100,560, 'player');
  97. player.anchor.setTo(0.5,0.5);
  98. //player.animations.add('runRight',[6, 7, 8, 9], 5, true);
  99. //player.animations.add('runLeft',[0, 1, 2, 3], 5, true);
  100. this.physics.arcade.enable(player);
  101. this.camera.follow(player);
  102. player.body.collideWorldBounds = true;
  103.  
  104. //Set controls
  105. controls = {
  106. right: this.input.keyboard.addKey(Phaser.Keyboard.A),
  107. left: this.input.keyboard.addKey(Phaser.Keyboard.D),
  108. up: this.input.keyboard.addKey(Phaser.Keyboard.W),
  109. down: this.input.keyboard.addKey(Phaser.Keyboard.S),
  110. }
  111.  
  112. //button = this.add.button(this.world.centerX - 95, this.world.centerY + 200,
  113. // 'buttons', function(){
  114. // console.log("ay");
  115. // },this,2,1,0);
  116.  
  117. },
  118. update: function() {
  119. //Collision
  120. this.physics.arcade.collide(player,layer);
  121.  
  122. //player.body.velocity.x = 0;
  123. //player.body.velocity.y = 0;
  124. if(Math.abs(player.body.velocity.x) >= playerSpeed*2){
  125. player.body.velocity.x = playerSpeed*2*(player.body.velocity.x/Math.abs(player.body.velocity.x));
  126. }
  127. if(Math.abs(player.body.velocity.y) >= playerSpeed*2){
  128. player.body.velocity.y = playerSpeed*2*(player.body.velocity.y/Math.abs(player.body.velocity.y));
  129. }
  130. player.body.allowGravity = false;
  131. player.body.bounce.set(0.)
  132.  
  133. if(controls.right.isDown){
  134. // player.animations.play('runRight');
  135. player.body.velocity.x -= playerSpeed;
  136. }
  137.  
  138. if(controls.left.isDown){
  139. // player.animations.play('runLeft');
  140. player.body.velocity.x += playerSpeed;
  141. }
  142.  
  143. if(controls.up.isDown){
  144. player.body.velocity.y -= playerSpeed;
  145. }
  146.  
  147. if(controls.down.isDown){
  148. player.body.velocity.y += playerSpeed;
  149. }
  150. }
  151. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement