vencinachev

Game02

Dec 1st, 2021 (edited)
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2. const Game = new Phaser.Game(1500, 1000, Phaser.AUTO, 'game-canvas', { preload, create, update })
  3.  
  4. let bg, player1, keys, bomba;
  5. let speed = 5;
  6.  
  7. function preload() {
  8.     Game.load.image('background', 'images/grass.jpg');
  9.     Game.load.spritesheet('player', 'images/girl.png', 480 / 8, 240 / 4);
  10.     Game.load.spritesheet('bomba', 'images/bomb.png', 256 /4, 256 / 4);
  11.     keys = Game.input.keyboard.createCursorKeys();
  12. }
  13.  
  14. function create() {
  15.     bg = Game.add.sprite(0, 0, 'background');
  16.     bg.width = Game.width;
  17.     bg.height = Game.height;
  18.  
  19.     player1 = Game.add.sprite(300, 300, 'player');
  20.     player1.scale.setTo(2);
  21.     player1.animations.add('run-left', [8, 9, 10, 11, 12, 13, 14, 15], 10, true);
  22.     player1.animations.add('run-right', [16, 17, 18, 19, 20, 21, 22, 23], 10, true);
  23.     player1.animations.add('run-down', [0, 1, 2, 3, 4, 5, 6, 7], 10, true);
  24.     player1.animations.add('run-up', [24, 25, 26, 27, 28, 29, 30, 31], 10, true);
  25.  
  26.     bomba = Game.add.sprite(200, 400, 'bomba');
  27.     bomba.animations.add('bomba1', [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 50, true);
  28.     bomba.animations.play('bomba1');
  29. }
  30.  
  31. function update() {
  32.     if (keys.up.isDown){
  33.         player1.animations.play('run-up')
  34.         player1.y -= speed;
  35.     } else if (keys.down.isDown){
  36.         player1.animations.play('run-down')
  37.         player1.y += speed;
  38.     } else if (keys.left.isDown){
  39.         player1.animations.play('run-left')
  40.         player1.x -= speed;
  41.     } else if (keys.right.isDown){
  42.         player1.animations.play('run-right')
  43.         player1.x += speed;
  44.     } else {
  45.         player1.frame = 0;
  46.     }
  47. }
Add Comment
Please, Sign In to add comment