Guest User

Untitled

a guest
Jun 24th, 2016
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var game = new Phaser.Game(640, 640, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
  2.  
  3. function preload() {
  4.  
  5.     game.load.tilemap('map', 'Assets/Tilemaps/newSnow.json', null, Phaser.Tilemap.TILED_JSON);
  6.  
  7.     game.load.image('tileset', 'Assets/Tilemaps/snowTiles.png');
  8.  
  9.     game.load.image('penguin', 'Assets/penguin.jpg');
  10.  
  11.  
  12.     var map;
  13.     var tileset;
  14.     var penguin;
  15.     var Background;
  16.     var Foreground;
  17.  
  18.  
  19.  
  20. }
  21. function create() {
  22.  
  23.    map = game.add.tilemap('map');
  24.  
  25.  
  26.    map.addTilesetImage('Snow1', 'tileset');
  27.   //  map.addTilesetImage('Foreground', 'tileset');
  28.  
  29.   //  map.setCollision([29], true);
  30.  
  31.    Background = map.createLayer('Background');
  32.    Foreground = map.createLayer('Foreground');
  33.  
  34.    map.setCollisionBetween(1, 100, true, Foreground);
  35.  
  36.  
  37.    Background.resizeWorld();
  38.  
  39.  
  40.     //game.add.sprite(0, 0, 'background');
  41.     game.stage.backgroundColor = '#71c5cf';
  42.  
  43.     player = game.add.sprite(0, 0, 'penguin');
  44.  
  45.     player.anchor.setTo(0.5, 0.5);
  46.  
  47.  
  48.  
  49.     game.physics.enable(player, Phaser.Physics.ARCADE);
  50.  
  51.     player.body.collideWorldBounds = true;
  52.  
  53.     cursors = game.input.keyboard.createCursorKeys();
  54.  
  55.  
  56.  
  57. }
  58.  
  59. function update() {
  60.  
  61.  
  62.     var dirMove = 3;
  63.  
  64.     if (cursors.left.isDown)
  65.     {
  66.         player.body.x -= dirMove;
  67.         }
  68.     else if (cursors.right.isDown)
  69.     {
  70.         player.body.x += dirMove;
  71.  
  72.     }
  73.     else if (cursors.up.isDown)
  74.     {
  75.         player.body.y -= dirMove;
  76.  
  77.     }
  78.     else if (cursors.down.isDown)
  79.     {
  80.        //ycoord += 50;
  81.        player.body.y += dirMove;
  82.  
  83.     }
  84.     else
  85.     {
  86.         player.animations.stop();
  87.     }
  88.     game.physics.arcade.collide(player, Foreground);
  89.  
  90. }
RAW Paste Data