Guest User

Untitled

a guest
May 30th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. var loader = {
  2.  
  3. preload : function(){
  4.  
  5. // loading map tiles
  6. game.phaser.load.image('map_t1', '/images/maps/desert1/t1.png');
  7. game.phaser.load.image('map_n1', '/images/maps/desert1/n1.png');
  8. game.phaser.load.image('map_e2', '/images/maps/desert1/e2.png');
  9. game.phaser.load.image('map_o1', '/images/maps/desert1/o1.png');
  10. game.phaser.load.image('map_e3', '/images/maps/desert1/e3.png');
  11. game.phaser.load.image('map_s1', '/images/maps/desert1/s1.png');
  12. game.phaser.load.image('map_e4', '/images/maps/desert1/e4.png');
  13. game.phaser.load.image('map_w1', '/images/maps/desert1/w1.png');
  14. game.phaser.load.image('map_e1', '/images/maps/desert1/e1.png');
  15. game.phaser.load.image('map_i1', '/images/maps/desert1/i1.png');
  16. game.phaser.load.image('map_i2', '/images/maps/desert1/i2.png');
  17. game.phaser.load.image('map_i3', '/images/maps/desert1/i3.png');
  18. game.phaser.load.image('map_i4', '/images/maps/desert1/i4.png');
  19. game.phaser.load.image('map_em', '/images/maps/desert1/empty.png');
  20. //water tiles
  21. game.phaser.load.image('map_wa1', '/images/maps/desert1/wa1.png');
  22. game.phaser.load.image('map_wa2', '/images/maps/desert1/wa2.png');
  23. game.phaser.load.image('map_wa3', '/images/maps/desert1/wa3.png');
  24. game.phaser.load.image('map_wa4', '/images/maps/desert1/wa4.png');
  25. game.phaser.load.image('map_wa5', '/images/maps/desert1/wa5.png');
  26. game.phaser.load.image('map_wa6', '/images/maps/desert1/wa6.png');
  27. game.phaser.load.image('map_wa7', '/images/maps/desert1/wa7.png');
  28.  
  29. }
  30. }
  31.  
  32. var map = {
  33. create : function(){
  34.  
  35. // Creates a blank tilemap
  36. game.phaser.map = game.phaser.add.tilemap();
  37.  
  38. // Add a Tileset image to the map
  39. game.phaser.map.addTilesetImage('map_t1');
  40. game.phaser.map.addTilesetImage('map_n1');
  41. game.phaser.map.addTilesetImage('map_e2');
  42. game.phaser.map.addTilesetImage('map_o1');
  43. game.phaser.map.addTilesetImage('map_e3');
  44. game.phaser.map.addTilesetImage('map_s1');
  45. game.phaser.map.addTilesetImage('map_e4');
  46. game.phaser.map.addTilesetImage('map_w1');
  47. game.phaser.map.addTilesetImage('map_e1');
  48. game.phaser.map.addTilesetImage('map_i1');
  49. game.phaser.map.addTilesetImage('map_i2');
  50. game.phaser.map.addTilesetImage('map_i3');
  51. game.phaser.map.addTilesetImage('map_i4');
  52. game.phaser.map.addTilesetImage('map_wa1');
  53.  
  54. // Creates a new blank layer and sets the map dimensions.
  55. game.phaser.ground = game.phaser.map.create('layer0', map.width, map.height, map.grid);
  56.  
  57. // Resize the world
  58. game.phaser.ground.resizeWorld();
  59.  
  60. game.phaser.ground.layer0 = game.phaser.add.group();
  61. game.phaser.ground.layer1 = game.phaser.add.group();
  62.  
  63. for(var y = 0; y<map.height; y++){
  64. for(var x = 0; x<map.width; x++){
  65. var mapSprite = map.map[y][x];
  66. if (mapSprite.shore){
  67. game.phaser.ground.layer1.create(x*map.grid, y*map.grid,
  68. map.getMapShoreSprite(mapSprite.shore));
  69. game.phaser.ground.layer0.create(x*map.grid, y*map.grid, 'map_wa1');
  70. } else if(mapSprite.land == 1){
  71. game.phaser.ground.layer1.create(x*map.grid, y*map.grid, 'map_t1');
  72. }
  73. else {
  74. game.phaser.ground.layer0.create(x*map.grid, y*map.grid, 'map_wa1');
  75. }
  76.  
  77. }
  78. }
  79.  
  80. },
  81.  
  82. getMapShoreSprite : function() {
  83. //.. just gets the right tilenames
  84. }
Advertisement
Add Comment
Please, Sign In to add comment