Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am currently coding a Phaser game. I have made many platforms for my player. Half of my platforms are icy. However, I can not

I am currently coding a Phaser game. I have made many platforms for my player. Half of my platforms are icy. However, I can not figure out how to make it slippery.

Can someone give some direction.

Additionally I have a few functions that are suppose make it slippery. But I can not figure it out. I have commented out the functions that pertain to this desired feature. Thank you ahead of time for your help.

JavaScript

var config = {

type: Phaser.AUTO,

width: 1600,

height: 1200,

physics: {

default: 'arcade',

arcade: {

gravity: { y: 300 },

debug: false

}

},

scene: {

preload: preload,

create: create,

update: update

// wrapPlatform: wrapPlatform,

// setFriction: setFriction

}

};

var player;

var platforms;

var cursors;

var game = new Phaser.Game(config);

function preload ()

{

this.load.image('backround', 'assets/backround.png');

this.load.image('platform', 'assets/platforms.png');

this.load.image('ice-platform', 'assets/ice-platform.png');

this.load.spritesheet('dude', 'assets/dude.png',

{ frameWidth: 32, frameHeight: 48 });

}

function create ()

{

let image = this.add.image(this.cameras.main.width / 2, //set image to fill out the screen

this.cameras.main.height / 2, 'backround')

let scaleX = this.cameras.main.width / image.width

let scaleY = this.cameras.main.height / image.height

let scale = Math.max(scaleX, scaleY)

image.setScale(scale).setScrollFactor(0)

platforms = this.physics.add.staticGroup();

platforms.create(150, 100, 'platform');

platforms.create(400, 100, 'ice-platform');

platforms.create(650, 100, 'platform');

platforms.create(900, 100, 'ice-platform');

platforms.create(300, 200, 'ice-platform');

platforms.create(550, 200, 'ice-platform');

platforms.create(800, 200, 'ice-platform');

platforms.create(150, 300, 'platform');

platforms.create(400, 300, 'platform');

platforms.create(650, 300, 'platform')

platforms.create(900, 300, 'platform')

platforms.create(300, 400, 'ice-platform');

platforms.create(550, 400, 'ice-platform');

platforms.create(800, 400, 'ice-platform');

platforms.create(150, 500, 'ice-platform');

platforms.create(400, 500, 'platform');

platforms.create(650, 500, 'platform')

platforms.create(900, 500, 'ice-platform')

player = this.physics.add.sprite(100, 450, 'dude');

player.setBounce(0.2);

player.setCollideWorldBounds(true);

this.anims.create({

key: 'left',

frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }),

frameRate: 10,

repeat: -1

});

this.anims.create({

key: 'turn',

frames: [ { key: 'dude', frame: 4 } ],

frameRate: 20

});

this.anims.create({

key: 'right',

frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }),

frameRate: 10,

repeat: -1

});

cursors = this.input.keyboard.createCursorKeys();

this.physics.add.collider(player, platforms);

}

// function setFriction (player, platform) {

// if (platform.key === 'ice-platform')

// {

// player.body.x -= platform.body.x - platform.body.prev.x;

// }

// }

// function wrapform (platform) {

// if (platform.body.velocity.x < 0 && platform.x <= -160)

// {

// platform.x = 640;

// }

// else if (platform.body.velocity.x > 0 && platform.x >= 640)

// {

// platform.x = -160;

// }

// }

function update ()

{

if (cursors.left.isDown)

{

player.setVelocityX(-160);

player.anims.play('left', true);

}

else if (cursors.right.isDown)

{

player.setVelocityX(160);

player.anims.play('right', true);

}

else

{

player.setVelocityX(0);

player.anims.play('turn');

}

if (cursors.up.isDown && player.body.touching.down)

{

player.setVelocityY(-330);

}

}

HTML

ClassProject219

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions