Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var config = {
- type: Phaser.AUTO,
- width: 1024,
- height: 768,
- backgroundColor: 0x000000,
- physics: {
- default: 'arcade',
- arcade: {
- gravity: { y: 300 },
- debug: true
- }
- },
- scene: {
- preload: preload,
- create: create,
- update: update
- }
- }
- var layoutSize = { 'width': 1024, 'height': 768 };
- var X_POSITION;
- var Y_POSITION;
- var player_control;
- var player2_control;
- var player;
- var player2;
- const moveVelocity = 500;
- const jumpVelocity = 1050;
- const gravityY = 3000;
- var platforms_normal;
- function preload() {
- this.load.image('Img_bg', 'assets/Gamelab_Map.png');
- this.load.spritesheet('charaBase_jump', 'assets/Player_Jump.png', { frameWidth: 48, frameHeight: 48 });
- this.load.spritesheet('charaBase_walk', 'assets/Player_Walk.png', { frameWidth: 48, frameHeight: 48 });
- this.load.spritesheet('switch', 'assets/Switch.png', { frameWidth: 48, frameHeight: 48 });
- this.load.image('nPlatform_1x4', 'assets/Platform_1x4.png');
- this.load.image('nPlatform_1x2', 'assets/Platform_1x2.png');
- this.load.image('cPlatformHorizontal_1x4', 'assets/PlatformC_1x4.png');
- this.load.image('cPlatformHorizontal_1x2', 'assets/PlatformC_1x2.png');
- this.load.image('cPlatformVertical_1x4', 'assets/PlatformCVer_1x4.png');
- this.load.image('cPlatformVertical_1x2', 'assets/PlatformCVer_1x2.png');
- this.load.spritesheet('portal', 'assets/Portal_100x100px-sheet.png', { frameWidth: 100, frameHeight: 100 })
- }
- function create() {
- X_POSITION =
- {
- 'LEFT': 0,
- 'CENTER': game.canvas.width / 2,
- 'RIGHT': game.canvas.width
- };
- Y_POSITION =
- {
- 'TOP': 0,
- 'CENTER': game.canvas.height / 2,
- 'BOTTOM': game.canvas.height
- };
- this.physics.world.setBounds(X_POSITION.CENTER - (1024 / 2), Y_POSITION.TOP, 1024, 768, true, true, true, false);
- /* Background */
- let background = this.add.image(X_POSITION.CENTER, Y_POSITION.CENTER, 'Img_bg');
- background.setScale(4);
- background.setDepth(-1);
- /* Player */
- player = this.physics.add.sprite(X_POSITION.CENTER - 48, Y_POSITION.CENTER, 'charaBase_jump');
- player.setTint(0x42f5e9);
- player.setDepth(5);
- player.setData('color', 0x42f5e9);
- player.setData('isJumping', false);
- player.body.setCollideWorldBounds(true);
- player.setSize(28, 40);
- player.setOffset(10, 8);
- player.body.gravity.y = gravityY;
- player2 = this.physics.add.sprite(X_POSITION.CENTER + 48, Y_POSITION.CENTER, 'charaBase_jump');
- player2.setTint(0xf54242);
- player2.setDepth(5);
- player2.setData('color', 0xf54242);
- player2.setData('isJumping', false);
- player2.body.setCollideWorldBounds(true);
- player2.setSize(28, 40);
- player2.setOffset(10, 8);
- player2.body.gravity.y = gravityY;
- /* Input */
- player_control = this.input.keyboard.addKeys({
- 'up': 'up',
- 'down': 'down',
- 'left': 'left',
- 'right': 'right'
- });
- player2_control = this.input.keyboard.addKeys({
- 'up': Phaser.Input.Keyboard.KeyCodes.W,
- 'down': Phaser.Input.Keyboard.KeyCodes.S,
- 'left': Phaser.Input.Keyboard.KeyCodes.A,
- 'right': Phaser.Input.Keyboard.KeyCodes.D
- });
- /* Platform */
- platforms_normal = this.physics.add.staticGroup();
- platforms_normal.create(X_POSITION.CENTER - 192, 650, 'nPlatform_1x4').setData('horizontal', true);
- platforms_normal.create(X_POSITION.CENTER, 650, 'nPlatform_1x4');
- platforms_normal.create(X_POSITION.CENTER + 192, 650, 'nPlatform_1x4').setData('horizontal', true);
- this.physics.add.collider(player, platforms_normal);
- this.physics.add.collider(player2, platforms_normal);
- }
- function update() {
- if (player.y > layoutSize.height + 192 || player2.y > layoutSize.height + 192) {
- this.scene.restart();
- }
- if (player_control == null || player2_control == null) { return; }
- /* Player 1 Control */
- if (player_control.left.isDown) {
- player.body.velocity.x = -moveVelocity;
- player.flipX = true;
- }
- else if (player_control.right.isDown) {
- player.body.velocity.x = moveVelocity;
- player.flipX = false;
- }
- else {
- player.body.velocity.x = 0;
- }
- if (player_control.up.isDown && player.body.touching.down && !player.getData('isJumping')) {
- player.setData('isJumping', true);
- player.body.velocity.y = -jumpVelocity;
- }
- else if (player_control.up.isUp && player.getData('isJumping')) {
- player.setData('isJumping', false);
- }
- /* Player 2 Control */
- if (player2_control.left.isDown) {
- player2.body.velocity.x = -moveVelocity;
- player2.flipX = true;
- }
- else if (player2_control.right.isDown) {
- player2.body.velocity.x = moveVelocity;
- player2.flipX = false;
- }
- else {
- player2.body.velocity.x = 0;
- }
- if (player2_control.up.isDown && player2.body.touching.down && !player2.getData('isJumping')) {
- player2.setData('isJumping', true);
- player2.body.velocity.y = -jumpVelocity;
- }
- else if (player2_control.up.isUp && player2.getData('isJumping')) {
- player2.setData('isJumping', false);
- }
- }
- var game = new Phaser.Game(config);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement