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