Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

what's wrong


yaroslav kornilov
 Share

Recommended Posts

what's wrong help please 

 
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });//иницилизация//куча перемменыхvar MainHero;var Zombie;var upKey;var leftKey;var rightKey;var bullet;var bullets;var bulletTime = 0;var backgroundimage;//загрузка спрайтов для последующего использованияfunction preload() {    game.load.spritesheet('MainHero', 'playerwithpistol.png', 17, 17, 24); //главный герой    game.load.spritesheet('Zombie','zombies.png', 11, 15, 6); // враги    game.load.image('bullet', 'bullet.png');  //пуля    game.load.image('backgroundimage','backgroundimage.jpg'); //фон}//инициализация function create() {MainHero = game.add.sprite(30, 400,'MainHero');//добавить гг//MainHero.animations.add('run',10, true);//MainHero.animations.add('left', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], 10, true);//идти влево    //MainHero.animations.add('right', [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], 10, true);//идти в право    //враг    createZombie(600, 300);    //все клавиши    upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);    leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);    rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);    //работа с выстрелом    bullets = game.add.group();    bullets.createMultiple(10, 'bullet');    bullets.callAll('events.onOutOfBounds.add', 'events.onOutOfBounds', resetBullet, this);    platforms = game.add.group();    var ground = platforms.create(0, game.world.height - 64, 'ground');    ground.scale.setTo(2, 2);    ground.body.immovable = true;    var ledge = platforms.create(400, 400, 'ground');    ledge.body.immovable = true;    ledge = platforms.create(-150, 250, 'ground');    player.body.gravity.y = 6;}//отдельный конструктор function createZombie(x,y) {    Zombie = game.add.sprite(x,y,'Zombie');    Zombie.animations.add('walk');    Zombie.animations.play('walk', 15, true);    Zombie.health = 100;    Zombie.speed = 50;    //это на будущее    var zombies = [];}//самое важное//функция взаимодействияfunction update() {sprite.body.velocity.x = 0;    sprite.body.velocity.y = 0;//регистрация ввода            if (leftKey.isDown)    {        MainHero.x--;        //MainHero.animations.play('left', 10, true);    }    else if (rightKey.isDown)    {        MainHero.x++;        //MainHero.animations.play('right', 10, true);    }    if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))    {        fireBullet();    }         if (cursors.up.isDown && MainHero.body.touching.down)    {        //MainHero.body.velocity.y = -350;    }} function fireBullet () {    if (game.time.now > bulletTime)    {        bullet = bullets.getFirstExists(false);        if (bullet)        {            bullet.reset(MainHero.x + 3, MainHero.y - 8);            bullet.body.velocity.x = +300;            bulletTime = game.time.now + 250;        }    }}function resetBullet (bullet) {    bullet.kill();}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...