Guest User

Untitled

a guest
Aug 4th, 2017
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Phaser from 'phaser-ce';
  2. import Utils from './game/utils';
  3.  
  4. var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload, create, update });
  5. var player;
  6. var cursors;
  7.  
  8. function preload() {
  9.  
  10.     game.load.spritesheet('dude', 'assets/chars/cowboy.png', 129, 129 );
  11. }
  12.  
  13. function create() {
  14.    
  15.    
  16.     player = game.add.sprite(32, game.world.height - 150, 'dude');
  17.  
  18.     game.physics.arcade.enable(player);
  19.  
  20.     player.body.collideWorldBounds = true;
  21.     console.log(Utils.rangeAnimation( (2-1)*14 ,7 ));
  22.     // this display : [14, 15, 16, 17, 18, 19, 20]
  23.     console.log(Utils.rangeAnimation( (1-1)*14 ,7 ));
  24.     // [0, 1, 2, 3, 4, 5, 6]
  25.     console.log(Utils.rangeAnimation( (6-1)*14 ,7 ));
  26.     //[70, 71, 72, 73, 74, 75, 76]
  27.  
  28.     player.animations.add('left', Utils.rangeAnimation((2-1)*14,7) , 14, true);
  29.     player.animations.add('right', Utils.rangeAnimation((1-1)*14 ,7) , 14, true);
  30.     player.animations.add('up',  Utils.rangeAnimation( (6-1)*14 ,7 ) , 14, true);
  31.  
  32.    // player.animations.add('bottom', Utils.rangeAnimation(14*9 ,7), 7, true);
  33.    
  34.     cursors = game.input.keyboard.createCursorKeys();
  35. }
  36.  
  37. function update() {
  38.  
  39.     player.body.velocity.x = 0;
  40.     player.body.velocity.y = 0;
  41.  
  42.  
  43.     if (cursors.left.isDown)
  44.     {
  45.         player.body.velocity.x = -150;
  46.  
  47.         player.animations.play('left');
  48.     }
  49.     else if (cursors.right.isDown)
  50.     {
  51.         player.body.velocity.x = 150;
  52.  
  53.         player.animations.play('right');
  54.     }
  55.     else if (cursors.up.isDown)
  56.     {
  57.         player.body.velocity.y = -50;
  58.  
  59.         player.animations.play('up');
  60.     }
  61.     else if (cursors.down.isDown)
  62.     {
  63.         player.body.velocity.y = 50;
  64.         player.animations.play('bottom');
  65.     }
  66.     else
  67.     {
  68.         player.animations.stop(null,true);
  69.        
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment