Guest User

Untitled

a guest
Dec 11th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. var player, map, mapObjs;
  2.  
  3. map = [['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  4. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  5. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  6. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  7. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  8. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  9. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'],
  10. ['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b']];
  11. mapObjs = new Array(map[0].length);
  12.  
  13. var game = new Phaser.Game(768, 768, Phaser.AUTO, 'Unnamed Game');
  14. game.state.add('main', {
  15. preload: function(e) {
  16. game.load.image('background', '{{ file:background.png }}');
  17. game.load.image('player', '{{ file:download.jpeg }}');
  18. game.load.image('block', '{{ file:Brick_Block.png }}');
  19. },
  20. create: function(e) {
  21. if (navigator.userAgent == 'CwC sandbox') {game.time.desiredFps = 30;}
  22. var backgroundImage = game.add.image(0, 0, 'background');
  23. backgroundImage.width = 768;
  24. backgroundImage.height = 768;
  25.  
  26. player = game.add.sprite(50, 100, 'player');
  27. game.physics.startSystem(Phaser.Physics.ARCADE);
  28. game.physics.arcade.enable(player);
  29. player.body.gravity.y = 9;
  30. player.body.bounce.y = 0.1;
  31. player.width = 100;
  32. player.height = 100;
  33. player.body.collideWorldBounds = true;
  34.  
  35. for(var i = 0; i < map[0].length; i++) {
  36. mapObjs[i] = [];
  37. for(var j = 0; j < map.length; j++) {
  38. mapObjs[i][j] = game.add.sprite(32*i, 300+32*j, 'block');
  39. mapObjs[i][j].width = 32;
  40. mapObjs[i][j].height = 32;
  41. }
  42. }
  43. },
  44. input_: function(e) {
  45. },
  46. update: function(e) {
  47. this.input_(e);
  48. for(var i = 0; i < mapObjs.length; i++) {
  49. for(var j = 0; j < mapObjs[i].length; j++) {
  50. game.physics.arcade.overlap(player, mapObjs[i][j], function(object1, object2) {
  51. console.log('hi'); // This never happens for some reason even thought the objects are visibly overlapping
  52. player.body.gravity.y = 0;
  53. player.body.accelerationY = 20;
  54. }, null, this);
  55. }
  56. }
  57. },
  58. render: function(e) {
  59. },
  60. }, true);
  61. game.state.start('main');
Add Comment
Please, Sign In to add comment