OSDN Git Service

当たり判定関連リニューアルの続き。
[h58pcdgame/GameScriptCoreLibrary.git] / www / corelib / classes / EnemyCharacterClass.js
1 var EnemyCharacterClass = function(stage, args){
2         EnemyCharacterClass.base.apply(this, arguments);
3         
4         this.movingVelocity = 150;
5         
6         //メインキャラクターを追跡する場合はtrue
7         this.chasing = true;
8         //メインキャラクターを感知する範囲(原点距離がこれ以内の場合に追跡をする。)
9         this.chasingRange = 200;
10         //メインキャラクターに与えるダメージの設定
11         this.touchDamage = 10;
12         this.damagePerTickBase = 60;
13         this.damagePerTickCount = this.damagePerTickBase;
14         this.damageLastTick = 0;
15         this.damaging = false;
16         //メインキャラクターから受けるダメージの設定
17         this.hurt = 10;
18         this.hurtPerTickBase = 60;
19         this.hurtPerTickCount = this.hurtPerTickBase;
20         this.hurtLastTick = 0;
21         this.hurting = false;
22         //
23         this.max_HP = 20;
24         this.HP = this.max_HP;
25 }.extend(OperatedCharacterClass, {
26         className: "EnemyCharacterClass",
27         tick : function()
28         {
29                 //追跡処理
30                 var main = this.ownerStage.userControlledCharacter;
31                 var distX = main.origin.x - this.origin.x;
32                 if(this.chasing && Math.abs(distX) <= this.chasingRange && Math.abs(this.origin.y - main.origin.y) <= this.chasingRange){
33                         if(distX > 0){
34                                 this.goRight();
35                         } else{
36                                 this.goLeft();
37                         }
38                 }
39                 //ダメージの開始・終了処理
40                 if(this.collidingDirection & CollideTop){
41                         if(!this.hurting){
42                                 //自分自身のダメージ有効
43                                 this.hurting = true;
44                                 this.hurtPerTickCount = this.hurtPerTickBase;
45                         }
46                         //if(this.damaging){
47                         //      //メインキャラクタへのダメージ無効
48                         //      this.damaging = false;
49                         //}
50                 } else{
51                         if(this.hurting){
52                                 //自分自身のダメージ無効
53                                 this.hurting = false;
54                         }
55                         if(this.collidingDirection & (CollideLeft | CollideRight)){
56                                 //if(!this.damaging){
57                                 //      //メインキャラクタへのダメージ有効
58                                 //      this.damaging = true;
59                                 //      this.damagePerTickCount = this.damagePerTickBase;
60                                 //}
61                         }
62                 }
63                 
64                 //メインキャラへのダメージ
65                 if(this.damaging){
66                         if(this.damagePerTickCount == this.damagePerTickBase){
67                                 this.ownerStage.manager.userManager.damage(this.touchDamage);
68                                 this.damagePerTickCount--;
69                         } else{
70                                 this.damagePerTickCount--;
71                                 if(this.damagePerTickCount <= 0){
72                                         this.damagePerTickCount = this.damagePerTickBase;
73                                 }
74                         }
75                 }
76                 //自分自身のダメージ
77                 if(this.hurting){
78                         if(this.hurtPerTickCount == this.hurtPerTickBase){
79                                 this.HP -= this.hurt;
80                                 this.hurtPerTickCount--;
81                                 if(this.HP <= 0){
82                                         this.ownerStage.removeStageObject(this);
83                                 }
84                         } else{
85                                 this.hurtPerTickCount--;
86                                 if(this.hurtPerTickCount <= 0){
87                                         this.hurtPerTickCount = this.hurtPerTickBase;
88                                 }
89                         }
90                 }
91                 //落下後の死亡処理
92                 if(this.origin.y > 1000)
93                 {
94                         this.ownerStage.removeStageObject(this);
95                 }
96                 
97                 EnemyCharacterClass.base.prototype.tick.apply(this);
98         },
99         draw: function(x, y){
100                 EnemyCharacterClass.base.prototype.draw.apply(this, arguments);
101                 this.ownerStage.mainContext.save();
102                 this.ownerStage.mainContext.fillStyle = "rgba(255,255,255,0.5)";
103                 this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
104                 this.ownerStage.mainContext.font = "normal 12px sans-serif";
105                 drawText(this.ownerStage.mainContext, this.HP, x, y - 20);
106                 this.ownerStage.mainContext.restore();
107         },
108 });