Ich versuche, zwei Arten von Feinden zu schaffen, der erste ist ein Roboter, der 2 Methoden hat: Schlaf und Patrouille.JavaScript Spiel Feindvererbung - Phaser-Framework
Mein zweiter Feind ist ein fliegenden Feind. Ziel ist es, die Schlafmethode vom Roboter zu erben, aber die Patrouillenmethode zu ändern.
Kann jemand mir zeigen, wie mein fliegendenEnemy vom Roboter erben kann, während er die Patrouillemethode ändert?
Unten ist mein Code. Wenn ich den fliegenden Feind erstelle, überschreibt seine Patrouillemethode die Patrouillenmethode des Roboters und ALLE Gegner verhalten sich gleich.
//-------------------------- ROBOT ENEMY
var SuperSmash = SuperSmash || {};
SuperSmash.Enemy = function(game, x, y, key, velocity, tilemap, player) {
Phaser.Sprite.call(this, game, x, y, key);
this.game = game;
this.tilemap = tilemap;
this.player = player;
};
SuperSmash.Enemy.prototype = Object.create(Phaser.Sprite.prototype);
SuperSmash.Enemy.prototype.constructor = SuperSmash.Enemy;
SuperSmash.Enemy.prototype.update = function() {
this.currentstate();
};
SuperSmash.Enemy.prototype.sleep = function() {
};
SuperSmash.flyingEnemy.prototype.patrol = function() {
var direction
if (this.body.velocity.x > 0) {
this.scale.setTo(1, 1);
direction = 1;
} else {
this.scale.setTo(-1, 1);
direction = -1;
}
var nextX = this.x + direction * (Math.abs(this.width)/2 + 1);
var nextY = this.bottom + 1;
var nextTile = this.tilemap.getTileWorldXY(nextX, nextY, this.tilemap.tileWidth, this.tilemap.tileHeight, 'collisionlayer');
if (!nextTile) {
this.body.velocity.x *= -1;
}
};
// --------------------------- FLYING ENEMY
var SuperSmash = SuperSmash || {};
SuperSmash.flyingEnemy = function(game, x, y, key, velocity, tilemap, player) {
SuperSmash.Enemy.call(this, game, x, y, key);
this.game = game;
this.tilemap = tilemap;
this.player = player;
this.animations.add("fly", [0]);
};
SuperSmash.flyingEnemy.prototype = Object.create(SuperSmash.Enemy.prototype);
SuperSmash.flyingEnemy.prototype.constructor = SuperSmash.flyingEnemy;
SuperSmash.Enemy.prototype.patrol = function() {
"use strict";
SuperSmash.game.physics.arcade.moveToObject(this, this.player, 200);
};