this.chasing = true;
//メインキャラクターを感知する範囲(原点距離がこれ以内の場合に追跡をする。)
this.chasingRange = 200;
+ this.fightingRange = 32;
+ this.chasingMode = 0;
+ this.lastCollidedTick = 0;
//メインキャラクターに与えるダメージの設定
this.touchDamage = 10;
this.damagePerTickBase = 60;
{
//追跡処理
var main = this.ownerStage.userControlledCharacter;
- var distX = main.origin.x - this.origin.x;
+ 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 = 1;
+ }
} else{
this.goLeft();
+ if(this.chasingMode == 1){
+ this.chasingMode = 0;
+ }
}
}
- //ダメージの開始・終了処理
- if(this.collidingDirection & CollideTop){
- if(!this.hurting){
- //自分自身のダメージ有効
- this.hurting = true;
- this.hurtPerTickCount = this.hurtPerTickBase;
- }
- //if(this.damaging){
- // //メインキャラクタへのダメージ無効
- // this.damaging = false;
- //}
- } else{
- if(this.hurting){
- //自分自身のダメージ無効
- this.hurting = false;
- }
- if(this.collidingDirection & (CollideLeft | CollideRight)){
- //if(!this.damaging){
- // //メインキャラクタへのダメージ有効
- // this.damaging = true;
- // this.damagePerTickCount = this.damagePerTickBase;
- //}
- }
- }
-
//メインキャラへのダメージ
if(this.damaging){
if(this.damagePerTickCount == this.damagePerTickBase){
}
}
}
+ if(this.lastCollidedTick + 10 < this.ownerStage.manager.tickCount){
+ if(this.hurting){
+ //自分自身のダメージ無効
+ this.hurting = false;
+ }
+ if(this.damaging){
+ //キャラクターへのダメージ無効
+ this.damaging = false;
+ }
+ }
//落下後の死亡処理
if(this.origin.y > 1000)
{
EnemyCharacterClass.base.prototype.tick.apply(this);
},
+ objectAttacked : function(obj, obj_x, obj_y)
+ {
+ if(obj instanceof MainCharacterClass)
+ {
+ //メインキャラクターに衝突された
+ //ダメージの開始・終了処理
+ //console.log(this.collidingDirection.toString(2));
+ //if(this.collidingDirection & CollideBody){
+ // console.log("b");
+ //}
+ if(this.collidingDirection & CollideTop){
+ if(!this.hurting){
+ //自分自身のダメージ有効
+ this.hurting = true;
+ this.hurtPerTickCount = this.hurtPerTickBase;
+ }
+ } else{
+ if(this.collidingDirection & (CollideLeft | CollideRight)){
+ if(!this.damaging){
+ //メインキャラクタへのダメージ有効
+ this.damaging = true;
+ this.damagePerTickCount = this.damagePerTickBase;
+ }
+ }
+ }
+ this.lastCollidedTick = this.ownerStage.manager.tickCount;;
+ }
+ },
draw: function(x, y){
EnemyCharacterClass.base.prototype.draw.apply(this, arguments);
this.ownerStage.mainContext.save();
this.touchInterval = 0;
this.lastTouchedTickCount = -9999;
- //\8c»\8dÝ\8fÕ\93Ë\92\86\82Ì\81i\8fã\82É\82©\82Ô\82³\82Á\82Ä\82¢\82é\81j\83L\83\83\83\89\82ª\82¢\82é\82©
- this.isCollided = false;
-
//\8c»\8dÝ\8fã\82É\82©\82Ô\82³\82Á\82Ä\82¢\82é\89Â\94\\90«\82Ì\82 \82é\83L\83\83\83\89
this.collidedList = [];
-
+ this.isPhantom = true;
this.debugMode = false;
}.extend(ItemClass, {
tick: function(){
this.checkCollidingDirection();
},
- /*
- itemAttacked : function(obj, obj_x, obj_y)
+ objectAttacked : function(obj, obj_x, obj_y)
{
var tickCount = this.ownerStage.manager.tickCount;
- if(!this.isCollided)
+ if(tickCount - this.lastTouchedTickCount >= this.touchInterval)
{
- this.isCollided = true;
- if(tickCount - this.lastTouchedTickCount >= this.touchInterval)
+ if(this.callback)
{
- if(this.callback)
- {
- this.callback(obj, obj_x, obj_y);
- }
-
- if(this.times > 0)
+ this.callback(obj, obj_x, obj_y);
+ }
+
+ if(this.times > 0)
+ {
+ this.times--;
+ if(this.times == 0)
{
- this.times--;
- if(this.times == 0)
- {
- this.ownerStage.removeStageObject(this);
- }
+ this.ownerStage.removeStageObject(this);
}
}
}
+
//\8dÅ\8cã\82É\90G\82ç\82ê\82½\8e\9e\8aÔ\82ð\8bL\98^
this.lastTouchedTickCount = tickCount;
this.collidedList.push(obj);
}
- */
+
});
\ No newline at end of file
o.movingSpeed.x = 0;
}
}
-
-
}
+ }
+ //\82±\82±\82Í\83\8b\81[\83v\8fI\97¹\92l\82ðlength\82Å\92¼\90Ú\8eæ\93¾\82µ\82È\82¯\82ê\82Î\82¢\82¯\82È\82¢\81i\8dí\8f\9c\82³\82ê\82é\83I\83u\83W\83F\83N\83g\82ª\82 \82é\89Â\94\\90«\82ª\82 \82é\82½\82ß\81j
+ for(var i = 0; i < this.stageObjectList[sp].length; i++){
+ var o = this.stageObjectList[sp][i];
//\8ae\83I\83u\83W\83F\83N\83g\8f\88\97\9d
o.tick();
}
tick: function(){
},
- itemAttacked : function(obj, obj_x, obj_y){
+ objectAttacked : function(obj, obj_x, obj_y){
//\82±\82Ì\8f\88\97\9d\82ð\8eq\83N\83\89\83X\82Å\8fã\8f\91\82«\82µ\82Ä\83A\83C\83e\83\80\82Ì\93®\8dì\82ð\92è\8b`\82·\82é
//obj : \82±\82Ì\83A\83C\83e\83\80\82É\90G\82Á\82½\90l(MainCharacter\82È\82Ç)
//obj_x : obj\82Ì\90G\82ê\82½\92¼\8cã\82Ìx\8dÀ\95W
var MainCharacterClass = function(stage, args){
MainCharacterClass.base.apply(this, arguments);
+ this.isItemCollector = true;
+
}.extend(OperatedCharacterClass, {
className: "MainCharacterClass",
tick : function()
this.ownerStage.mainContext.globalAlpha = 1.0;
},
- itemAttacked : function(obj, obj_x, obj_y)
+ objectAttacked : function(obj, obj_x, obj_y)
{
if(obj instanceof MainCharacterClass) //\8c»\8dÝ\91\80\8dì\92\86\82Ì\83L\83\83\83\89\82Å\82 \82é
{
// \8fd\97Í\82ª\82È\82\82È\82Á\82½\82ç\82±\82Ì\95û\96@\82Å\82Í\90Ú\92n\82ð\8c\9f\8fo\82Å\82«\82È\82\82È\82é\82ª\82»\82ê\82Í
//this.collideFlag = 0;
// \82±\82Ì\95¨\91Ì\82É\93\82\8fd\97Í(\95¨\91Ì\95Ê\82É\82»\82ê\82¼\82ê\8ew\92è\89Â\81A\83}\83C\83i\83X\92l\8ew\92è\89Â)
- this.gravity = 800;
- //\93\96\82½\82è\94»\92è\82Ì\83}\81[\83W\83\93\82Ì\8ew\92è
- //this.collisionMarginTop = 2;
- //this.collisionMarginLeft = 6;
- //this.collisionMarginRight = 6;
- //this.collisionMarginBottom = 2;
-
+ this.gravity = 800;
//\92i\8d·\82â\8dâ\82ð\8fæ\82è\89z\82¦\82ç\82ê\82é\83\8c\83x\83\8b 0\82¾\82Æ\8dâ\82ð\91S\82\8fã\82ê\82È\82¢
this.caterpillar = 2.5;
this.isItemCollector = false;
this.inWater = false;
-
+ this.collectedItems = new Array();
}.extend(StageObject, {
className: "MovableStageObjectClass",
tick: function(){
//\92ï\8dR\8f\88\97\9d
- /*
- if(this.movingSpeed.x < -this.hysteresis){
- this.movingSpeed.x += this.movingFriction / this.ownerStage.manager.tickPerSecond;
- } else if(this.movingSpeed.x > this.hysteresis){
- this.movingSpeed.x -= this.movingFriction / this.ownerStage.manager.tickPerSecond;
- } else{
- this.movingSpeed.x = 0;
- }
- */
- //\8fd\97Í
- //this.movingSpeed.y += this.gravity / this.ownerStage.manager.tickPerSecond;
//\89^\93®\8f\88\97\9d
this.moveTo(
this.origin.x + (this.movingSpeed.x / this.ownerStage.manager.tickPerSecond),
//\8eæ\93¾
this.checkCollidingDirection();
- //\8fÕ\93Ë\8e\9e\82Ì\89^\93®\83G\83l\83\8b\83M\81[\8fÁ\96Å\90Ý\92è
- //if((this.collidingDirection & CollideRight) != 0 && this.movingSpeed.x > 0) this.movingSpeed.x = 0; //\89E\95û\8cü\82É\8fÕ\93Ë
- //if((this.collidingDirection & CollideLeft) != 0 && this.movingSpeed.x < 0) this.movingSpeed.x = 0; //\8d¶\95û\8cü\82É\8fÕ\93Ë
- if((this.collidingDirection & CollideBottom) != 0 && this.movingSpeed.y > 0) this.movingSpeed.y = 0; //\89º\95û\8cü\82É\8fÕ\93Ë
- if((this.collidingDirection & CollideTop) != 0 && this.movingSpeed.y < 0) this.movingSpeed.y = 0; //\8fã\95û\8cü\82É\8fÕ\93Ë
-
},
canMoveTo: function(x, y){
//\82·\82×\82Ä\82Ì\83I\83u\83W\83F\83N\83g\82É\91Î\82µ\82Ä(x, y)\82É\82 \82é\82Æ\82«\82Ì\8e©\95ª\82Ì\8fÕ\93Ë\8fó\91Ô\82ð\92²\82×\82é\81B
//\8e©\95ª\82Å\82È\82¢
if(f.isOverlappedWithLocatedObject(this, x, y)){
//\8fÕ\93Ë\90æf\82Ì\8fÕ\93Ë\94Í\88Í\93à\82É\82¢\82é
- if(f.isPhantom){
- //\8fÕ\93Ë\90æf\82ª\8fÕ\93Ë\94»\92è\96³\8e\8b\82¾\82Á\82½\82ç\81A\8fÕ\93Ë\82Í\82µ\82È\82¢
- /*
- if(this.isItemCollector){
- //\8fÕ\93Ë\90æf\82ð\8eæ\93¾\82µ\82½\83A\83C\83e\83\80\82É\89Á\82¦\82é\81B
- for(var titem in items){
- //\95¡\90\94\92Ç\89Á\82Ì\96h\8e~
- if(titem == f){
- continue;
- }
+ if(this.isItemCollector){
+ //\8fÕ\93Ë\90æf\82ð\8eæ\93¾\82µ\82½\83A\83C\83e\83\80\82É\89Á\82¦\82é\81B
+ var titem = null;
+ for(titem in this.collectedItems){
+ //\95¡\90\94\92Ç\89Á\82Ì\96h\8e~
+ if(titem == f){
+ break;
}
- items.push(f);
}
- */
-
+ if(titem != f){
+ this.collectedItems.push(f);
+ }
+ }
+ if(f.isPhantom){
+ //\8fÕ\93Ë\90æf\82ª\8fÕ\93Ë\94»\92è\96³\8e\8b\82¾\82Á\82½\82ç\81A\8fÕ\93Ë\82Í\82µ\82È\82¢
} else{
//\8fÕ\93Ë\82µ\82½
retv = true;
- break;
+ //break;
}
}
}
moveTo : function(x, y) {
//\8c»\8dÝ\82Ì\8dÀ\95W\82©\82ç(x,y)\82É\8cü\82¯\82Ä\81A\88Ú\93®\82Å\82«\82é\82¾\82¯\88Ú\93®\82·\82é\81B
//\8fÕ\93Ë\95û\8cü\83t\83\89\83O\82à\90Ý\92è\82·\82é\81B
+ this.collectedItems = new Array();
var sx = this.origin.x
var sy = this.origin.y;
var lx = x - sx
if(c != 0 && this.canMoveTo(ex + dx, ey - c)){
//\82»\82ê\82Å\82àx\8e²\82ª\8fÕ\93Ë\82µ\82½\82Ì\82Å\88Ú\93®\82ð\92â\8e~\82µ\83t\83\89\83O\82ð\83Z\83b\83g\82·\82é
fx = true;
+ this.movingSpeed.x = 0;
} else{
//\8d\82\82³\82ð\95Ï\82¦\82ê\82Î\88Ú\93®\82Å\82«\82é\82Ì\82Å\8d\82\82³\82ð\95Ï\82¦\82Ä\8cp\91±\82·\82é
ey -= c;
if(!fy && this.canMoveTo(ex, ey + dy)){
//y\8e²\82ª\8fÕ\93Ë\82µ\82½\82Ì\82Å\88Ú\93®\82ð\92â\8e~\82µ\83t\83\89\83O\82ð\83Z\83b\83g\82·\82é
fy = true;
+ this.movingSpeed.y = 0;
}
if(!fx){
ex += dx;
this.origin.x = ex;
this.origin.y = ey;
- /*
- for(var i in gotItems){
- var item = gotItems[i];
- if(item.itemAttacked){
+ for(var i in this.collectedItems){
+ var item = this.collectedItems[i];
+ if(item.objectAttacked){
//\83A\83C\83e\83\80\82É\91Î\82µ\82Ä\8eæ\93¾\82³\82ê\82½\82±\82Æ\82ð\92Ê\92m\82·\82é\81B(\8eæ\93¾\82µ\82½\83I\83u\83W\83F\83N\83g\82Ì\83C\83\93\83X\83^\83\93\83X\82¨\82æ\82Ñ\8dÀ\95W\81j
- item.itemAttacked(obj, ex, ey);
+ item.objectAttacked(this, ex, ey);
}
}
- */
+
return;
},
});
this.jumpPower_tickCount = 0;
this.jumpPower = 100;
this.jumpSound = createAudio("jump12.mp3");
- this.collisionMarginTop = 2;
- this.collisionMarginLeft = 10;
- this.collisionMarginRight = 10;
- this.collisionMarginBottom =2;
+ this.collisionMargin.top = 2;
+ this.collisionMargin.left = 10;
+ this.collisionMargin.right = 10;
+ this.collisionMargin.bottom = 2;
}.extend(CharacterClass, {
className: "OperatedCharacterClass",
var o = this.origin;
var c = this.collisionMargin;
var s = this.size;
- return (x2 > (o.x + c.left)) && (x1 <= (o.x + s.x - c.right)) && (y2 > (o.y + c.top)) && (y1 <= (o.y + s.y - c.bottom));
+ return (x2 >= (o.x + c.left)) && (x1 < (o.x + s.x - c.right)) && (y2 >= (o.y + c.top)) && (y1 < (o.y + s.y - c.bottom));
},
isOverlappedWithLocatedObject: function(obj, x, y){
//(x, y)\82Éobj\82ª\82 \82é\82Æ\82«\82Ì\83I\83u\83W\83F\83N\83g\96{\91Ì\94Í\88Í\82É\81A\8e©\95ª\82Ì\83I\83u\83W\83F\83N\83g\96{\91Ì\95\94\95ª\82É\8fd\82È\82é\82©\82Ç\82¤\82©\82ð\92²\82×\82é
- //\82±\82Ì\8aÖ\90\94\82ªfalse\82ð\95Ô\82µ\82½\8e\9e\82Ì\88ø\90\94\82Ì\94Í\88Í\82Ö\82Í\83I\83u\83W\83F\83N\83g\82ª\88Ú\93®\82Å\82«\82é\81B
- return this.isOverlappedWith(x, y, x + obj.size.x - 1, y + obj.size.y - 1);
+ //\82±\82Ì\8aÖ\90\94\82ªfalse\82ð\95Ô\82µ\82½\8e\9e\82Ì\88ø\90\94\82Ì\94Í\88Í\82Ö\82Í\83I\83u\83W\83F\83N\83g\82ª\88Ú\93®\82Å\82«\82é\81B]
+ var c = obj.collisionMargin;
+ var s = obj.size;
+ return this.isOverlappedWith(x + c.left, y + c.top, x + s.x - c.right - 1, y + s.y - c.bottom - 1);
},
// + - - +
// | |
//body
this.collidingDirection |= CollideBody;
}
- if(obj.isOverlappedWith(cbx0 + 1, cby0 - r, cbx1, cby0 - 1)){
+ if(obj.isOverlappedWith(cbx0, cby0 - r, cbx1, cby0 - 1)){
//top
this.collidingDirection |= CollideTop;
}