Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Scene1 extends Phaser.Scene {
  2.     constructor() {
  3.         super("Scene1");
  4.     }
  5.     _create() {
  6.         this.map = this.add.tilemap("map");
  7.        
  8.         this.tileset = this.map.addTilesetImage("GreyTransperant");
  9.        
  10.         this.rocks = this.map.createStaticLayer("Rock", this.tileset);
  11.         this.collisions = this.map.createDynamicLayer("Collisions", this.tileset);
  12.         this.map.setCollisionByExclusion([-1]);
  13.         this.matter.world.convertTilemapLayer(this.collisions);
  14.  
  15.         this.map.createFromTiles([6, 8], null, this.objects, this, this.cameras.main,"FunnyHitBox");
  16.        
  17.         this.player = this.matter.add.image(350, 250, "player");
  18.         this.cameras.main.centerOn(this.player.x, this.player.y);
  19.        
  20.         this.space_bar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
  21.         this.left = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
  22.         this.right = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
  23.         this.up = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
  24.         this.down = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
  25.             }
  26.     create() {
  27.         this._create();
  28.     }
  29.     update() {
  30.         this.cameras.main.centerOn(this.player.x, this.player.y, this.setCollisions);
  31.        
  32.         if (this.left.isDown) {
  33.                 this.player.setVelocityX(-2);
  34.             } else if (this.right.isDown) {
  35.                 this.player.setVelocityX(2);
  36.             } else {
  37.                 this.player.setVelocityX(0);
  38.             }
  39.  
  40.         if (this.up.isDown) {
  41.                 this.player.setVelocityY(-5);
  42.         }
  43.     } //update end
  44. } //scene1 end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement