Guest User

Untitled

a guest
Aug 7th, 2015
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>WeWork Game</title>
  6. <!--<script src="//cdn.jsdelivr.net/phaser/2.2.2/phaser.min.js"></script>-->
  7. <script src="//cdn.jsdelivr.net/phaser/2.2.2/phaser.js"></script>
  8. <style type="text/css">
  9. body {
  10. margin: 0;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15.  
  16. <script type="text/javascript">
  17.  
  18. var game = new Phaser.Game(/*2084, 1989*/1200, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update});
  19.  
  20.  
  21. function preload() {
  22.  
  23. //game.load.image('platform', './objects/platform.png')
  24. //game.load.image('background', './background/background.gif');
  25. //game.load.image('ground', './objects/platform.png');
  26. game.load.image('block', './objects/block.png');
  27. game.load.tilemap('level', './background/tilemaps/level1.json', null, Phaser.Tilemap.TILED_JSON);
  28. game.load.image('tiles', './background/tilemaps/tiles.png');
  29. game.load.spritesheet('zero', './characters/megaman.png', 50, 50);
  30. game.load.image('stars', './objects/energy.png');
  31.  
  32.  
  33.  
  34.  
  35. }
  36.  
  37. var map;
  38. var backgroundLayer;
  39. var blockLayer;
  40. var patches;
  41. var player;
  42. var cursors;
  43. var block;
  44. //var platform;
  45.  
  46. var stars;
  47. var score = 0;
  48. var scoreText;
  49.  
  50. function create() {
  51.  
  52. map = game.add.tilemap("level");
  53. map.addTilesetImage('tiles', 'tiles');
  54.  
  55. blockLayer = map.createLayer('solids');
  56. blockLayer.reziseWorld();
  57.  
  58. backgroundLayer = map.createLayer('cosmetics');
  59. backgroundLayer.resizeWorld();
  60.  
  61. patches = map.createLayer('backing');
  62. patches.resizeWorld();
  63.  
  64.  
  65. // We're going to be using physics, so enable the Arcade Physics system
  66. game.physics.startSystem(Phaser.Physics.ARCADE);
  67.  
  68. // A simple background for our game
  69. // game.add.sprite(0, 0, 'bg');
  70.  
  71. block = game.add.group();
  72. block.enableBody = true;
  73. var blockA = block.create(20, 550, 'block');
  74. blockA.body.immovable = true;
  75.  
  76. // The player and its settings
  77. player = game.add.sprite(50, game.world.height - 150, 'zero');
  78.  
  79. // We need to enable physics on the player
  80. game.physics.arcade.enable(player);
  81.  
  82. // Player physics properties.
  83. player.body.gravity.y = 1000;
  84. player.body.collideWorldBounds = true;
  85.  
  86. // Our two animations, walking left and right.
  87. player.animations.add('stand', [0, 0, 0, 1, 0, 2], 5, true);
  88. player.animations.add('left', [3, 4, 5, 4], 5, true);
  89. player.animations.add('right', [3, 4, 5, 4], 5, true);
  90. player.animations.add('jump', [6], 30, true);
  91.  
  92.  
  93. //player.animations.add('jump', [6], true);
  94.  
  95.  
  96. // Finally some stars to collect
  97. stars = game.add.group();
  98.  
  99. // We will enable physics for any stars that is created in this group
  100. stars.enableBody = true;
  101.  
  102. // Here we'll create 12 of them evenly spaced apart
  103. for (var i = 0; i < 12; i++)
  104. {
  105. // Create a stars inside of the 'stars' group
  106. var star = stars.create(i * 70, 0, 'stars');
  107.  
  108. // Let gravity do its thing
  109. star.body.gravity.y = 150;
  110.  
  111. star.body.collideWorldBounds = true;
  112.  
  113. // This just gives each stars a slightly random bounce value
  114. star.body.bounce.y = 0.7 + Math.random() * 0.2;
  115. }
  116.  
  117. // The score
  118. scoreText = game.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#FFFFFF' });
  119.  
  120.  
  121. // Our controls.
  122. cursors = game.input.keyboard.createCursorKeys();
  123.  
  124. //Command that uses camera to follow player
  125. game.camera.follow(player);
  126.  
  127. }
  128.  
  129.  
  130. function update() {
  131.  
  132. // Checks to see if the player overlaps with any of the stars, if he does call the collectstars function
  133. game.physics.arcade.overlap(player, stars, collectstars, null, this);
  134.  
  135. game.physics.arcade.collide(player, block);
  136.  
  137. // Reset the players velocity (movement)
  138. player.body.velocity.x = 0;
  139.  
  140. if (cursors.left.isDown)
  141. {
  142. // Move to the left
  143. player.body.velocity.x = -150;
  144.  
  145. player.animations.play('left');
  146. }
  147. else if (cursors.right.isDown)
  148. {
  149. // Move to the right
  150. player.body.velocity.x = 150;
  151.  
  152. player.animations.play('right');
  153. }
  154. else
  155. {
  156. // Stand still
  157. player.animations.stop();
  158. player.animations.play('stand');
  159. }
  160.  
  161. // Allow the player to jump if they are touching the ground.
  162. if (cursors.up.isDown && player.body.touching.down)
  163. {
  164. player.body.velocity.y = -450;
  165. player.animations.play('jump');
  166. }
  167.  
  168. if (scoreText.text == 'Score: ' + 120) {
  169. game.add.text(50, 50, 'CONGRATULATIONS!!! You have collected ALL the Energy Orbs!', { fontSize: '32px', fill: '#FFFFFF' });
  170. }
  171.  
  172. }
  173.  
  174.  
  175.  
  176. function collectstars (player, stars) {
  177.  
  178. // Removes the stars from the screen
  179. stars.kill();
  180.  
  181. // Add and update the score
  182. score += 10;
  183. scoreText.text = 'Score: ' + score;
  184.  
  185. }
  186. </script>
  187.  
  188. </body>
  189. </html>
Advertisement
Add Comment
Please, Sign In to add comment