Commit 26b34a99 authored by Grigoriy Tretyakov's avatar Grigoriy Tretyakov

Now I can play

parent c7ee4ced
# Deathworld - Kill them all!
Ну, я не придумал ничего луче, чем создать небольшой агрессивный мир, который будет мне напоминать одноимённую книгу Гаррисона.
Ну, я не придумал ничего лучше, чем создать небольшой агрессивный мир, который будет мне напоминать одноимённую книгу Гаррисона.
This source diff could not be displayed because it is too large. You can view the blob instead.
assets/enemy.png

2.46 KB | W: | H:

assets/enemy.png

6.97 KB | W: | H:

assets/enemy.png
assets/enemy.png
assets/enemy.png
assets/enemy.png
  • 2-up
  • Swipe
  • Onion skin
This source diff could not be displayed because it is too large. You can view the blob instead.
webpackJsonp([0],{434:function(e,t,s){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var n=function(){function e(e,t){for(var s=0;s<t.length;s++){var i=t[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,s,i){return s&&e(t.prototype,s),i&&e(t,i),t}}();s(210);var o=function(e){function t(){i(this,t);var e=r(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,{key:"Game"}));return e.assets={bg:"bg",hero:"hero",bullet:"bullet",enemy:"enemy"},e.tick=0,e.fire=!1,e.mx=0,e.my=0,e.bullets=[],e.enemies=[],e}return a(t,e),n(t,[{key:"preload",value:function(){this.load.spritesheet(this.assets.hero,"assets/hero.png",{frameWidth:41,frameHeight:47}),this.load.image(this.assets.bullet,"assets/bullet.png"),this.load.image(this.assets.bg,"assets/bg.png"),this.load.spritesheet(this.assets.enemy,"assets/enemy.png",{frameWidth:32,frameHeight:32})}},{key:"create",value:function(){var e=this;this.add.image(350,300,this.assets.bg),this.anims.create({key:this.assets.hero,frames:this.anims.generateFrameNumbers(this.assets.hero,{start:0,end:2}),frameRate:8,repeat:-1}),this.anims.create({key:this.assets.enemy,frames:this.anims.generateFrameNumbers(this.assets.enemy,{start:0,end:2}),frameRate:8,repeat:-1}),this.hero=this.physics.add.sprite(350,300,this.assets.hero),this.hero.play(this.assets.hero,!0),this.input.on("pointerdown",function(t){e.fire=!0,e.mx=t.x,e.my=t.y},this),this.input.on("pointermove",function(t){e.mx=t.x,e.my=t.y},this),this.input.on("pointerup",function(t){e.fire=!1},this),this.time.addEvent({delay:500,callback:this.createEnemy,callbackScope:this,loop:!0}),this.createEnemy()}},{key:"createEnemy",value:function(){var e=this,t=Phaser.Math.Between(-50,750),s=t>0&&t<750?Phaser.Math.RND.pick([-25,625]):Phaser.Math.Between(0,600),i=this.physics.add.sprite(t,s,this.assets.enemy);i.play(this.assets.enemy,!0),i.rotation=Phaser.Math.Angle.Between(i.x,i.y,this.hero.x,this.hero.y),i.body.velocity.x=100*Math.cos(i.rotation),i.body.velocity.y=100*Math.sin(i.rotation),this.physics.add.collider(this.hero,i,function(t,s){return e.killHero(t,s)});var r=!0,a=!1,n=void 0;try{for(var o,h=this.bullets[Symbol.iterator]();!(r=(o=h.next()).done);r=!0){var l=o.value;this.physics.add.collider(i,l,function(t,s){return e.killEnemy(t,s)})}}catch(e){a=!0,n=e}finally{try{!r&&h.return&&h.return()}finally{if(a)throw n}}this.enemies.push(i)}},{key:"killHero",value:function(e,t){this.scene.start("Menu")}},{key:"killEnemy",value:function(e,t){e.destroy(),t.destroy()}},{key:"update",value:function(e,t){var s=this,i=Phaser.Math.Angle.Between(this.hero.x,this.hero.y,this.mx,this.my);this.hero.rotation=i,Math.abs(this.hero.x-this.mx)<1&&Math.abs(this.hero.y-this.my)<1?(this.hero.body.velocity.x=0,this.hero.body.velocity.y=0):(this.hero.body.velocity.x=130*Math.cos(i),this.hero.body.velocity.y=130*Math.sin(i)),this.tick+=t;var r=Math.sqrt(672.25),a=Math.atan(.825)+i;if(this.tick>500&&(this.tick=501,this.fire)){this.tick=0;var n=this.physics.add.sprite(this.hero.x+r*Math.cos(a),this.hero.y+r*Math.sin(a),this.assets.bullet),o=!0,h=!1,l=void 0;try{for(var y,c=this.enemies[Symbol.iterator]();!(o=(y=c.next()).done);o=!0){var u=y.value;this.physics.add.collider(u,n,function(e,t){return s.killEnemy(e,t)})}}catch(e){h=!0,l=e}finally{try{!o&&c.return&&c.return()}finally{if(h)throw l}}this.bullets.push(n),n.rotation=i,n.body.velocity.x=400*Math.cos(i),n.body.velocity.y=400*Math.sin(i)}var f=[],p=!0,d=!1,m=void 0;try{for(var b,v=this.bullets[Symbol.iterator]();!(p=(b=v.next()).done);p=!0){var g=b.value;g.x>-10&&g.x<710&g.y>-10&&g.y<610?f.push(g):g.destroy()}}catch(e){d=!0,m=e}finally{try{!p&&v.return&&v.return()}finally{if(d)throw m}}this.bullets=f;var k=[],x=!0,w=!1,M=void 0;try{for(var P,_=this.enemies[Symbol.iterator]();!(x=(P=_.next()).done);x=!0){var O=P.value;O.x>-50&&O.x<750&O.y>-50&&O.y<650?k.push(O):O.destroy()}}catch(e){w=!0,M=e}finally{try{!x&&_.return&&_.return()}finally{if(w)throw M}}this.enemies=k}}]),t}(Phaser.Scene),h=function(e){function t(){return i(this,t),r(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,{key:"Menu"}))}return a(t,e),n(t,[{key:"preload",value:function(){this.load.image("start","assets/start.png")}},{key:"create",value:function(){var e=this;this.add.sprite(350,300,"start").setInteractive().on("pointerdown",function(){e.scene.start("Game")})}}]),t}(Phaser.Scene),l={type:Phaser.AUTO,parent:"game",width:700,height:600,physics:{default:"arcade",arcade:{debug:!1}},scene:[h,o]};new Phaser.Game(l)}},[434]);
\ No newline at end of file
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>game</title>
<title>Deathworld</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
......@@ -23,7 +23,7 @@
body {
margin: 50px auto;
width: 300px;
width: 700px;
}
#game {
......@@ -35,6 +35,6 @@
<body>
<div id="game" style=""></div>
<script type="text/javascript" src="vendors.js"></script>
<script type="text/javascript" src="game.js"></script>
<script type="text/javascript" src="deathworld-game.js"></script>
</body>
</html>
......@@ -30,21 +30,28 @@ class Game extends Phaser.Scene {
this.load.image(this.assets.bg, 'assets/bg.png');
this.load.image(this.assets.enemy, 'assets/enemy.png');
this.load.spritesheet(this.assets.enemy, 'assets/enemy.png',
{frameWidth: 32, frameHeight: 32});
}
create() {
this.add.image(350, 300, this.assets.bg);
this.anims.create({
key: 'top',
key: this.assets.hero,
frames: this.anims.generateFrameNumbers(this.assets.hero, {start: 0, end: 2}),
frameRate: 8,
repeat: -1
});
//this.hero = this.physics.add.sprite(350, 300, this.assets.hero);
this.anims.create({
key: this.assets.enemy,
frames: this.anims.generateFrameNumbers(this.assets.enemy, {start: 0, end: 2}),
frameRate: 8,
repeat: -1
});
this.hero = this.physics.add.sprite(350, 300, this.assets.hero);
this.hero.play('top', true);
this.hero.play(this.assets.hero, true);
this.input.on('pointerdown', (event) => {
this.fire = true;
......@@ -62,7 +69,7 @@ class Game extends Phaser.Scene {
}, this);
this.time.addEvent({
delay: 6000,
delay: 500,
callback: this.createEnemy,
callbackScope: this,
loop: true
......@@ -71,12 +78,29 @@ class Game extends Phaser.Scene {
}
createEnemy() {
let enemy = this.physics.add.sprite(100, 100, this.assets.enemy);
const x = Phaser.Math.Between(-50, 750);
const y = x > 0 && x < 750
? Phaser.Math.RND.pick([-25, 625])
: Phaser.Math.Between(0, 600);
let enemy = this.physics.add.sprite(x, y, this.assets.enemy);
enemy.play(this.assets.enemy, true);
enemy.rotation = Phaser.Math.Angle.Between(enemy.x, enemy.y, this.hero.x, this.hero.y);
this.physics.moveTo(enemy, this.hero.x, this.hero.y);
enemy.body.velocity.x = 100 * Math.cos(enemy.rotation);
enemy.body.velocity.y = 100 * Math.sin(enemy.rotation);
this.physics.add.collider(this.hero, enemy, (hero, enemy) => this.killHero(hero, enemy));
for (let b of this.bullets) {
this.physics.add.collider(enemy, b, (enemy, bullet) => this.killEnemy(enemy, bullet));
}
this.enemies.push(enemy);
}
killHero(hero, enemy) {
this.scene.start('Menu');
}
console.log('add enemy');
killEnemy(enemy, bullet) {
enemy.destroy();
bullet.destroy();
}
update(time, delta) {
......@@ -88,9 +112,8 @@ class Game extends Phaser.Scene {
this.hero.body.velocity.y = 0;
}
else {
this.physics.moveTo(this.hero, this.mx, this.my);
this.hero.body.velocity.x = 100 * Math.cos(angle);
this.hero.body.velocity.y = 100 * Math.sin(angle);
this.hero.body.velocity.x = 130 * Math.cos(angle);
this.hero.body.velocity.y = 130 * Math.sin(angle);
}
this.tick += delta;
......@@ -109,11 +132,11 @@ class Game extends Phaser.Scene {
this.hero.y + D * Math.sin(A),
this.assets.bullet
);
for (let e of this.enemies) {
this.physics.add.collider(e, b, (enemy, bullet) => this.killEnemy(enemy, bullet));
}
this.bullets.push(b);
b.rotation = angle;
//this.physics.moveTo(b, this.mx, this.my);
//b.body.velocity.x *= 7;
//b.body.velocity.y *= 7;
b.body.velocity.x = 400 * Math.cos(angle);
b.body.velocity.y = 400 * Math.sin(angle);
}
......@@ -130,12 +153,32 @@ class Game extends Phaser.Scene {
}
this.bullets = bullets;
//for (let e of this.enemies) {
// this.physics.moveTo(e, this.hero.x, this.hero.y);
// e.body.velocity.x *= 0.7;
// e.body.velocity.y *= 0.7;
//}
let enemies = [];
for (let enemy of this.enemies) {
if (enemy.x > -50 && enemy.x < 750 & enemy.y > -50 && enemy.y < 650) {
enemies.push(enemy);
}
else{
enemy.destroy();
}
}
this.enemies = enemies;
}
}
class Menu extends Phaser.Scene {
constructor() {
super({key: 'Menu'});
}
preload() {
this.load.image('start', 'assets/start.png');
}
create() {
let btn = this.add.sprite(350, 300, 'start').setInteractive();
btn.on('pointerdown', () => { this.scene.start('Game'); });
}
}
......@@ -151,6 +194,7 @@ const config = {
}
},
scene: [
Menu,
Game,
]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment