Guest User

Untitled

a guest
Jun 13th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var game = new Phaser.Game
  3. (
  4.     window.innerWidth  * 1 ,
  5.     window.innerHeight * 1 ,
  6.     Phaser.AUTO,
  7.     'phaser-example', { preload: preload, create: create, update: update, render: render }
  8. );
  9.  
  10. function preload() {
  11.  
  12.     game.stage.smoothed = false;
  13.  
  14.     game.load.tilemap('map', 'maps/mapaaa.json', null, Phaser.Tilemap.TILED_JSON);
  15.     game.load.image(  'gardening_ground', 'maps/smaller.png');
  16.     game.load.image(  'spr_fieltro', 'img/fieltro.png');
  17.  
  18. }
  19.  
  20. var map;
  21. var layer;
  22. var cursors;
  23. var sprite;
  24. var gameWorld;
  25. var jumpTimer = 0;
  26. var jumpButton;
  27.  
  28. function create()
  29. {
  30.  
  31.     game.stage.backgroundColor = "#4488AA";
  32.  
  33.     map = game.add.tilemap('map');
  34.     map.addTilesetImage('gardening_ground');
  35.     layer = map.createLayer('Tile Layer 1');
  36.     map.setCollisionBetween(0, 50);
  37.     layer.fixedToCamera = false;
  38.     layer.position.set(0, 0);
  39.     layer.setScale(5);
  40.     layer.debug  = true;
  41.  
  42.  
  43.     sprite = game.add.sprite(0, -50, 'spr_fieltro');
  44.     sprite.scale.setTo(5, 5);
  45.     game.physics.enable(sprite);    
  46.     game.physics.arcade.gravity.y = 1000;
  47.     sprite.body.collideWorldBounds = true;
  48.  
  49.  
  50.     cursors    = game.input.keyboard.createCursorKeys();
  51.     jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
  52.  
  53.     game.camera.follow(sprite);
  54.     game.world.setBounds(0, 0, 20000, 20000);
  55.  
  56. }
  57.  
  58. function update()
  59. {
  60.  
  61.     game.physics.arcade.collide(sprite, layer);
  62.     sprite.body.velocity.x = 0;
  63.  
  64.     if (cursors.left.isDown){      sprite.body.velocity.x = -250;}
  65.     else if (cursors.right.isDown){sprite.body.velocity.x = 250;}
  66.    
  67.     if (jumpButton.isDown && sprite.body.onFloor() && game.time.now > jumpTimer)
  68.     {sprite.body.velocity.y = -750;jumpTimer = game.time.now + 750;}
  69.  
  70. }
  71.  
  72. function render()
  73. {
  74.     game.debug.body(sprite);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment