this.fightingRange = 32;
this.chasingMode = 0;
this.lastCollidedTick = 0;
- //メインキャラクターに与えるダメージの設定
+ //他のキャラクターに与えるダメージの設定
this.touchDamage = 10;
this.damagePerTickBase = 60;
this.damagePerTickCount = this.damagePerTickBase;
//
this.max_HP = 20;
this.HP = this.max_HP;
+ this.isWeaponed = false;
}.extend(OperatedCharacterClass, {
className: "EnemyCharacterClass",
tick : function()
{
- //追跡処理
var main = this.ownerStage.userControlledCharacter;
var distX = main.origin.x - this.origin.x - ((this.chasingMode == 0) ? this.fightingRange : -this.fightingRange);
if(this.chasing && Math.abs(distX) <= this.chasingRange && Math.abs(this.origin.y - main.origin.y) <= this.chasingRange){
+ //追跡処理
if(distX > 0){
this.goRight();
if(this.chasingMode == 0){
this.chasingMode = 0;
}
}
+ //攻撃処理
+ if(this.isWeaponed){
+ this.fire();
+ }
}
//メインキャラへのダメージ
if(this.damaging){
if(this.damagePerTickCount == this.damagePerTickBase){
- this.ownerStage.manager.userManager.damage(this.touchDamage);
+ main.damage(this.touchDamage);
this.damagePerTickCount--;
} else{
this.damagePerTickCount--;
//自分自身のダメージ
if(this.hurting){
if(this.hurtPerTickCount == this.hurtPerTickBase){
- this.HP -= this.hurt;
+ this.damage(this.hurt);
this.hurtPerTickCount--;
- if(this.HP <= 0){
- this.ownerStage.removeStageObject(this);
- }
} else{
this.hurtPerTickCount--;
if(this.hurtPerTickCount <= 0){
EnemyCharacterClass.base.prototype.tick.apply(this);
},
- objectAttacked : function(obj, obj_x, obj_y)
+ damage: function(d){
+ //自分自身へのダメージ
+ this.HP -= d;
+ if(this.HP <= 0){
+ this.ownerStage.removeStageObject(this);
+ }
+ },
+ objectAttacked : function(obj, obj_x, obj_y, direction)
{
if(obj instanceof MainCharacterClass)
{
//メインキャラクターに衝突された
//ダメージの開始・終了処理
- //console.log(this.collidingDirection.toString(2));
- //if(this.collidingDirection & CollideBody){
- // console.log("b");
- //}
- if(this.collidingDirection & CollideTop){
+ if(direction & CollideTop){
if(!this.hurting){
//自分自身のダメージ有効
this.hurting = true;
this.hurtPerTickCount = this.hurtPerTickBase;
}
} else{
- if(this.collidingDirection & (CollideLeft | CollideRight)){
+ if(direction & (CollideLeft | CollideRight)){
if(!this.damaging){
//メインキャラクタへのダメージ有効
this.damaging = true;
}
}
}
- this.lastCollidedTick = this.ownerStage.manager.tickCount;;
+ this.lastCollidedTick = this.ownerStage.manager.tickCount;
}
},
draw: function(x, y){
EnemyCharacterClass.base.prototype.draw.apply(this, arguments);
- this.ownerStage.mainContext.save();
- this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
- this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
- this.ownerStage.mainContext.font = "normal 12px sans-serif";
- drawText(this.ownerStage.mainContext, this.HP, x, y - 20);
- this.ownerStage.mainContext.restore();
+ if(this.hurt > 0)
+ {
+ this.ownerStage.mainContext.save();
+ var backColor = "gray";
+ var thickness = 4;
+ var barWidth = this.max_HP;
+ if(barWidth < 16) barWidth = 16;
+ var barPerHP = this.HP / this.max_HP;
+ var color = "green";
+
+ if(barPerHP < 0.2)
+ {
+ var backColor = "red";
+ }else if(barPerHP < 0.4)
+ {
+ var backColor = "yellow";
+ }
+
+ this.ownerStage.mainContext.fillStyle = backColor;
+ this.ownerStage.mainContext.fillRect(x + (this.size.x - barWidth) / 2, y - thickness, barWidth, thickness);
+ this.ownerStage.mainContext.fillStyle = color;
+ this.ownerStage.mainContext.fillRect(x + (this.size.x - barWidth) / 2, y - thickness, barWidth * barPerHP, thickness);
+
+ this.ownerStage.mainContext.restore();
+ }
},
});