123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- var game = new Phaser.Game (
- 1024, 768,
- Phaser.AUTO,
- 'game',
- {
- preload: preload,
- create: create,
- update: update,
- render: render
- }
- );
- //тест для гита
- /*-----ПРОТОТИП ИГРОКА-----*/
- function Player(name) {
- this.name = name;
- this.hp = 100;
- };
- Player.prototype.spawn = function() {
- /*-----СОЗДАНИЕ АНИМАЦИИ-----*/
- this.name = game.add.sprite(480, 350, 'humantile');
- this.name.animations.add('left', [14, 15, 16], 10, true);
- this.name.animations.add('right', [17, 18, 19], 10, true);
- this.name.animations.add('up', [20, 21, 22], 10, true);
- this.name.animations.add('down', [23, 24, 25], 10, true);
- this.name.animations.add('attack', [1, 2, 3], 10, true);
- game.physics.enable(this.name);
- };
- Player.prototype.animation = function() {
- game.physics.arcade.collide(this.name, platforms);
- this.name.body.velocity.x = 0;
- this.name.body.velocity.y = 0;
- this.name.body.angularVelocity = 0;
- /*-----ДВИЖЕНИЕ ИГРОКА-----*/
- if (cursors.left.isDown)
- {
- // Движение влево
- this.name.body.velocity.x = -250;
- if (!attackbut.isDown){this.name.animations.play('left');}
- // Движение влево вверх
- if (cursors.up.isDown){
- this.name.body.velocity.x = -175;
- this.name.body.velocity.y = -175;
- if (!attackbut.isDown){this.name.animations.play('left');}
- }
- // Движение влево вниз
- if (cursors.down.isDown){
- this.name.body.velocity.x = -175;
- this.name.body.velocity.y = 175;
- if (!attackbut.isDown){this.name.animations.play('left');}
- }
- }
- else if (cursors.right.isDown)
- {
- // Движение вправо
- this.name.body.velocity.x = 250;
- if (!attackbut.isDown){this.name.animations.play('right');}
- // Движение вправо вниз
- if (cursors.up.isDown){
- this.name.body.velocity.x = 175;
- this.name.body.velocity.y = -175;
- if (!attackbut.isDown){this.name.animations.play('right');}
- }
- // Движение вправо вверх
- if (cursors.down.isDown){
- this.name.body.velocity.x = 175;
- this.name.body.velocity.y = 175;
- if (!attackbut.isDown){this.name.animations.play('right');}
- }
- }
- else if (cursors.up.isDown)
- {
- // Движение вверх
- this.name.body.velocity.y = -250;
- if (!attackbut.isDown){this.name.animations.play('up');}
- }
- else if (cursors.down.isDown)
- {
- // Движение вниз
- this.name.body.velocity.y = 250;
- if (!attackbut.isDown){this.name.animations.play('down');}
- }
- else
- {
- // Неподвижно
- if (!attackbut.isDown){this.name.animations.stop();}
- this.name.frame = 0;
- }
- if (attackbut.isDown){
- this.name.animations.play('attack');
- }
- };
- /*-----ПРОТОТИП МОНСТРОВ-----*/
- function Monster(name, line, timespawn) {
- this.name = name;
- this.monsterhp = 50; //количество жизней
- this.damage = 2; //наносимый им урон
- this.range = 50; //радиус атаки игрока
- this.arange = -50;
- this.monster_count = 0; //счетчик кадров (60 в секунду)
- this.line = line; //сторона появления (35 или 940)
- this.timespawn = timespawn; //время появления, указывается в секундах
- this.ymelee = 200; //расстояние от игрока до врага
- this.xmelee = 200;
- };
- /*-----СПАВН МОНСТРОВ-----*/
- Monster.prototype.spawn = function() {
- this.monster_count++;
- if(this.monster_count == (this.timespawn * 60)) {
- this.name = game.add.sprite(this.line, game.world.randomY, 'monsterstile');
- this.name.animations.add('left', [4, 5, 6], 10, true);
- this.name.animations.add('right', [1, 2, 3], 10, true);
- this.name.animations.add('up', [7, 8, 9], 10, true);
- this.name.animations.add('down', [10, 11, 12], 10, true);
- this.name.animations.add('dmg', [13, 14, 15], 10, true);
- }
- };
- Monster.prototype.move = function() {
- /*-----ДВИЖЕНИЕ МОНСТРОВ-----*/
- game.physics.enable(this.name);
-
- if (this.name.x > poz.name.x)
- {
- // Движение влево
- this.name.body.velocity.x = -80;
- this.name.animations.play('left');
- // Движение влево вверх
- if (this.name.y > poz.name.y){
- this.name.body.velocity.x = -50;
- this.name.body.velocity.y = -50;
- this.name.animations.play('left');
- }
- // Движение влево вниз
- if (this.name.y < poz.name.y){
- this.name.body.velocity.x = -50;
- this.name.body.velocity.y = 50;
- this.name.animations.play('left');
- }
- }
- else if (this.name.x < poz.name.x)
- {
- // Движение вправо
- this.name.body.velocity.x = 80;
- this.name.animations.play('right');
- // Движение вправо вниз
- if (this.name.y > poz.name.y){
- this.name.body.velocity.x = 50;
- this.name.body.velocity.y = -50;
- this.name.animations.play('right');
- }
- // Движение вправо вверх
- if (this.name.y < poz.name.y){
- this.name.body.velocity.x = 50;
- this.name.body.velocity.y = 50;
- this.name.animations.play('right');
- }
- }
- else if (this.name.y < poz.name.y)
- {
- // Движение вверх
- this.name.body.velocity.y = -80;
- this.name.animations.play('up');
- }
- else if (this.name.y > poz.name.y)
- {
- // Движение вниз
- this.name.body.velocity.y = 80;
- this.name.animations.play('down');
- }
-
- };
- /*-----БОЙ МОНСТРОВ-----*/
- Monster.prototype.death = function() {
- this.ymelee = this.name.y - poz.name.y;
- this.xmelee = this.name.x - poz.name.x;
- if (this.ymelee < this.range && this.ymelee > this.arange && this.xmelee < this.range && this.xmelee > this.arange && attackbut.isDown) {
- this.monsterhp -= this.damage;
- }
- if (this.monsterhp <= 0) {
- if (poz.hp > 0) {
- xp += 5;
- }
- this.monsterhp = 50;
- if (this.line == 35) {
- this.name.x = this.line - 300;
- this.name.y = game.world.randomY;
- }
- if (this.line == 940) {
- this.name.x = this.line + 300;
- this.name.y = game.world.randomY;
- }
- }
- if (this.ymelee < this.range - 20 && this.ymelee > this.arange + 20 && this.xmelee < this.range - 20 && this.xmelee > this.arange + 20) {
- this.name.animations.play('dmg');
- poz.hp -= 1;
- }
- return poz.hp;
- };
- function gameover() {
- if (poz.hp <= 0) {
- endString = 'Game Over. Your Score - ';
- endText = game.add.text(320, 200, endString + xp, { font: '34px Arial', fill: '#fff' });
- poz.name.kill();
- }
- }
- function preload() {
- game.load.image('map', 'assets/mapp2.png');
- game.load.spritesheet('humantile', 'assets/humantile.png', 64, 64);
- game.load.spritesheet('monsterstile', 'assets/monsterstile.png', 64, 64);
- game.load.image('board_left', 'assets/board_left.png');
- game.load.image('board_right', 'assets/board_right.png');
- game.load.image('board_up', 'assets/board_up.png');
- game.load.image('board_down', 'assets/board_down.png');
- }
- var cursors;
- var attackbut;
- var layer;
- var map;
- var boardl, boardr, boardd, boardu;
- var platforms;
- var xp = 0;
- var skeleton11 = new Monster('sk11', 35, 1);
- var skeleton12 = new Monster('sk12', 35, 1);
- var skeleton13 = new Monster('sk13', 35, 5);
- var skeleton14 = new Monster('sk14', 35, 5);
- var skeleton15 = new Monster('sk15', 35, 5);
- var skeleton16 = new Monster('sk16', 35, 12);
- var skeleton17 = new Monster('sk17', 35, 12);
- var skeleton18 = new Monster('sk18', 35, 12);
- var skeleton19 = new Monster('sk19', 35, 12);
- var skeleton10 = new Monster('sk10', 35, 25);
- var skeleton111 = new Monster('sk111', 35, 25);
- var skeleton112 = new Monster('sk112', 35, 25);
- var skeleton113 = new Monster('sk113', 35, 25);
- var skeleton114 = new Monster('sk114', 35, 25);
- var skeleton21 = new Monster('sk21', 940, 1);
- var skeleton22 = new Monster('sk22', 940, 1);
- var skeleton23 = new Monster('sk23', 940, 5);
- var skeleton24 = new Monster('sk24', 940, 5);
- var skeleton25 = new Monster('sk25', 940, 5);
- var skeleton26 = new Monster('sk26', 940, 12);
- var skeleton27 = new Monster('sk27', 940, 12);
- var skeleton28 = new Monster('sk28', 940, 12);
- var skeleton29 = new Monster('sk29', 940, 12);
- var skeleton20 = new Monster('sk20', 940, 25);
- var skeleton211 = new Monster('sk211', 940, 25);
- var skeleton212 = new Monster('sk212', 940, 25);
- var skeleton213 = new Monster('sk213', 940, 25);
- var skeleton214 = new Monster('sk214', 940, 25);
- var poz = new Player('pozh');
- function create() {
- game.physics.startSystem(Phaser.Physics.ARCADE);
-
- /*-----ГЕНЕРАЦИЯ УРОВНЯ-----*/
- platforms = game.add.group();
- platforms.enableBody = true;
- boardl = platforms.create(0, 0, 'board_left');
- boardr = platforms.create(1000, 0, 'board_right');
- boardd = platforms.create(0, 750, 'board_down');
- boardu = platforms.create(0, 0, 'board_up');
- boardl.body.immovable = true;
- boardr.body.immovable = true;
- boardd.body.immovable = true;
- boardu.body.immovable = true;
- game.add.sprite(0, 0, 'map');
-
- poz.spawn();
- hpString = 'Health: '; //Здоровье
- hpText = game.add.text(10, 10, hpString + poz.hp, { font: '24px Arial', fill: '#fff' });
- xpString = 'Score: '; //Очки
- xpText = game.add.text(850, 10, xpString + xp, { font: '24px Arial', fill: '#fff' });
- cursors = game.input.keyboard.createCursorKeys();
- attackbut = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
- }
- /*-----ИГРОВОЙ ПРОЦЕСС-----*/
- function update() {
- poz.animation();
- gameover();
- if (poz.hp >= 0) {
- hpText.text = hpString + poz.hp;
- }
- xpText.text = xpString + xp;
- monsterspawn();
- }
- function render () {
-
- }
|