Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var config = {
- type: Phaser.AUTO,
- width: 800,
- height: 600,
- scene: {
- preload: preload,
- create: create,
- update: update,
- },
- physics: {
- default: "arcade",
- arcade: { debug: true },
- },
- };
- var game = new Phaser.Game(config);
- function preload() {
- this.load.image("background", "assets/background.png");
- this.load.image("ground", "assets/Ground.png");
- this.load.image("platform", "assets/Platform.png");
- this.load.image("spikeSM", "assets/Spike.png");
- this.load.image("spikeLG", "assets/LongSpike.png");
- this.load.spritesheet("bob", "assets/Bob.png", {
- frameWidth: 50,
- frameHeight: 50,
- });
- } //variables
- var player;
- //
- function create() {
- this.add.image(400, 300, "background");
- keys = this.input.keyboard.addKeys("W,A,D");
- //Ground
- var platforms = this.physics.add.staticGroup();
- //Spikes
- var spikeSM = this.physics.add.staticGroup();
- spikeSM.create(400, 442, "spikeSM").setScale(1).refreshBody();
- //Platforms
- platforms.create(400, 568, "ground").setScale(2).refreshBody();
- //Player
- player = this.physics.add.sprite(100, 400, "bob");
- player.setBounce(0.2);
- player.setCollideWorldBounds(true);
- player.body.setGravityY(1300);
- //Collision mesh
- this.physics.add.collider(player, platforms);
- this.physics.collider.add(
- player,
- spikesSM,
- function () {
- this.physics.pause();
- player.setTint(0xff0000);
- this.gameOverText = this.add.text(400, 300, "GAME OVER", {
- fontSize: "50px",
- fill: "#000",
- });
- }.bind(this)
- );
- }
- //Keys
- var keys;
- //
- function update() {
- if (keys.A.isDown) {
- player.setVelocityX(-500);
- console.log("Left");
- } else if (keys.D.isDown) {
- player.setVelocityX(500);
- console.log("Right");
- } else {
- player.setVelocityX(0);
- }
- if (keys.W.isDown && player.body.touching.down) {
- player.setVelocityY(-500);
- console.log("Jump");
- }
- /* if (player.body.collide.spikeSM) {
- console.log("TOUCH")
- }*/
- }
Add Comment
Please, Sign In to add comment