瀏覽代碼

test commit

Ivan Morozov 7 年之前
當前提交
1f12f06d29
共有 4 個文件被更改,包括 432 次插入0 次删除
  1. 322 0
      game4/game2.js
  2. 22 0
      game4/index2.html
  3. 86 0
      game4/monsterspawn.js
  4. 2 0
      game4/phaser.min.js

+ 322 - 0
game4/game2.js

@@ -0,0 +1,322 @@
+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 () {
+  
+}

+ 22 - 0
game4/index2.html

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+    <title>Stupid Arena</title>
+    <style type="text/css">
+    body {
+    font-family: Arial, Verdana,  sans-serif;
+    font-size: 12pt;
+    color: #333;
+    }
+  </style>    
+</head>
+<body>
+    <p>
+    Alpha v0.36
+    <script src="phaser.min.js"></script>
+    <script src="game2.js"></script>
+    <script src="monsterspawn.js"></script>
+    </p>
+</body>
+</html>

+ 86 - 0
game4/monsterspawn.js

@@ -0,0 +1,86 @@
+function monsterspawn() {
+  skeleton11.spawn();
+  skeleton11.move();
+  skeleton11.death();
+  skeleton12.spawn();
+  skeleton12.move();
+  skeleton12.death();
+  skeleton13.spawn();
+  skeleton13.move();
+  skeleton13.death();
+  skeleton14.spawn();
+  skeleton14.move();
+  skeleton14.death();
+  skeleton15.spawn();
+  skeleton15.move();
+  skeleton15.death();
+  skeleton16.spawn();
+  skeleton16.move();
+  skeleton16.death();
+  skeleton17.spawn();
+  skeleton17.move();
+  skeleton17.death();
+  skeleton18.spawn();
+  skeleton18.move();
+  skeleton18.death();
+  skeleton19.spawn();
+  skeleton19.move();
+  skeleton19.death();
+  skeleton10.spawn();
+  skeleton10.move();
+  skeleton10.death();
+  skeleton111.spawn();
+  skeleton111.move();
+  skeleton111.death();
+  skeleton112.spawn();
+  skeleton112.move();
+  skeleton112.death();
+  skeleton113.spawn();
+  skeleton113.move();
+  skeleton113.death();
+  skeleton114.spawn();
+  skeleton114.move();
+  skeleton114.death();
+  skeleton21.spawn();
+  skeleton21.move();
+  skeleton21.death();
+  skeleton22.spawn();
+  skeleton22.move();
+  skeleton22.death();
+  skeleton23.spawn();
+  skeleton23.move();
+  skeleton23.death();
+  skeleton24.spawn();
+  skeleton24.move();
+  skeleton24.death();
+  skeleton25.spawn();
+  skeleton25.move();
+  skeleton25.death();
+  skeleton26.spawn();
+  skeleton26.move();
+  skeleton26.death();
+  skeleton27.spawn();
+  skeleton27.move();
+  skeleton27.death();
+  skeleton28.spawn();
+  skeleton28.move();
+  skeleton28.death();
+  skeleton29.spawn();
+  skeleton29.move();
+  skeleton29.death();
+  skeleton20.spawn();
+  skeleton20.move();
+  skeleton20.death();
+  skeleton211.spawn();
+  skeleton211.move();
+  skeleton211.death();
+  skeleton212.spawn();
+  skeleton212.move();
+  skeleton212.death();
+  skeleton213.spawn();
+  skeleton213.move();
+  skeleton213.death();
+  skeleton214.spawn();
+  skeleton214.move();
+  skeleton214.death();
+}

文件差異過大導致無法顯示
+ 2 - 0
game4/phaser.min.js


部分文件因文件數量過多而無法顯示