Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const Game = new Phaser.Game(1000, 800, Phaser.AUTO, 'game-canvas', { preload, create, update })
- let player;
- let speed = 2;
- let dir = 'right';
- let player2;
- let speed2 = 3;
- let dir2 = 'down';
- function preload() {
- Game.load.image('bg', 'images/bg.jpg');
- Game.load.spritesheet('playerSH', 'images/playerss.png', 576 / 9, 256/ 4);
- }
- function create() {
- let background = Game.add.sprite(0, 0, 'bg');
- background.width = Game.width;
- background.height = Game.height;
- player2 = Game.add.sprite(300, 500, 'playerSH')
- player2.width = 80;
- player2.height = 100;
- player2.animations.add('walk-up', [0, 1, 2, 3, 4, 5, 6, 7, 8], 10, true)
- player2.animations.add('walk-down', [18, 19, 20, 21, 22, 23, 24, 25, 26], 10, true)
- player2.animations.add('walk-left', [9, 10, 11, 12, 13, 14, 15, 16, 17], 10, true)
- player2.animations.add('walk-right', [27, 28, 29, 30, 31, 32, 33, 34, 35], 10, true)
- player = Game.add.sprite(0, 0, 'playerSH')
- player.width = 80;
- player.height = 100;
- player.animations.add('walk-up', [0, 1, 2, 3, 4, 5, 6, 7, 8], 10, true)
- player.animations.add('walk-down', [18, 19, 20, 21, 22, 23, 24, 25, 26], 10, true)
- player.animations.add('walk-left', [9, 10, 11, 12, 13, 14, 15, 16, 17], 10, true)
- player.animations.add('walk-right', [27, 28, 29, 30, 31, 32, 33, 34, 35], 10, true)
- }
- function update() {
- if (dir == 'right'){
- player.x += speed;
- player.animations.play('walk-right')
- if (player.x > (Game.width - player.width)){
- dir = 'left'
- }
- } else if (dir == 'left'){
- player.x -= speed;
- player.animations.play('walk-left')
- if (player.x < 0){
- dir = 'right'
- }
- }
- if (dir2 == 'up'){
- player2.y -= speed2;
- player2.animations.play('walk-up');
- if (player2.y < 0){
- dir2 = 'down';
- }
- } else if (dir2 == 'down'){
- player2.y += speed2;
- player2.animations.play('walk-down');
- if (player2.y > (Game.height - player2.height)){
- dir2 = 'up';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement