Drunkmonkey

Untitled

Oct 29th, 2021 (edited)
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var config = {
  2.   type: Phaser.AUTO,
  3.   width: 800,
  4.   height: 600,
  5.   scene: {
  6.     preload: preload,
  7.     create: create,
  8.     update: update,
  9.   },
  10.   physics: {
  11.     default: "arcade",
  12.     arcade: { debug: true },
  13.   },
  14. };
  15.  
  16. var game = new Phaser.Game(config);
  17.  
  18. function preload() {
  19.   this.load.image("background", "assets/background.png");
  20.   this.load.image("ground", "assets/Ground.png");
  21.   this.load.image("platform", "assets/Platform.png");
  22.   this.load.image("spikeSM", "assets/Spike.png");
  23.   this.load.image("spikeLG", "assets/LongSpike.png");
  24.  
  25.   this.load.spritesheet("bob", "assets/Bob.png", {
  26.     frameWidth: 50,
  27.     frameHeight: 50,
  28.   });
  29. } //variables
  30.  
  31. var player;
  32.  
  33. //
  34. function create() {
  35.   this.add.image(400, 300, "background");
  36.   keys = this.input.keyboard.addKeys("W,A,D");
  37.   //Ground
  38.   var platforms = this.physics.add.staticGroup();
  39.   //Spikes
  40.   var spikeSM = this.physics.add.staticGroup();
  41.   spikeSM.create(400, 442, "spikeSM").setScale(1).refreshBody();
  42.   //Platforms
  43.   platforms.create(400, 568, "ground").setScale(2).refreshBody();
  44.   //Player
  45.   player = this.physics.add.sprite(100, 400, "bob");
  46.   player.setBounce(0.2);
  47.   player.setCollideWorldBounds(true);
  48.   player.body.setGravityY(1300);
  49.   //Collision mesh
  50.   this.physics.add.collider(player, platforms);
  51.   this.physics.collider.add(
  52.     player,
  53.     spikesSM,
  54.     function () {
  55.       this.physics.pause();
  56.       player.setTint(0xff0000);
  57.       this.gameOverText = this.add.text(400, 300, "GAME OVER", {
  58.         fontSize: "50px",
  59.         fill: "#000",
  60.       });
  61.     }.bind(this)
  62.   );
  63. }
  64.  
  65. //Keys
  66. var keys;
  67. //
  68. function update() {
  69.   if (keys.A.isDown) {
  70.     player.setVelocityX(-500);
  71.     console.log("Left");
  72.   } else if (keys.D.isDown) {
  73.     player.setVelocityX(500);
  74.     console.log("Right");
  75.   } else {
  76.     player.setVelocityX(0);
  77.   }
  78.  
  79.   if (keys.W.isDown && player.body.touching.down) {
  80.     player.setVelocityY(-500);
  81.     console.log("Jump");
  82.   }
  83.  
  84.   /*  if (player.body.collide.spikeSM) {
  85.     console.log("TOUCH")
  86.   }*/
  87. }
  88.  
Add Comment
Please, Sign In to add comment