this.chasing = true;
//メインキャラクターを感知する範囲(原点距離がこれ以内の場合に追跡をする。)
this.chasingRange = 200;
-
+
+ this.touchDamage = 10;
+ this.damagePerTickBase = 60;
+ this.damagePerTickCount = this.damagePerTickBase;
+ this.damaging = false;
}.extend(OperatedCharacterClass, {
className: "EnemyCharacterClass",
tick : function()
this.goLeft();
}
}
-
+ if(this.damaging){
+ console.log("s");
+ if(this.damagePerTickCount == this.damagePerTickBase){
+ this.ownerStage.manager.userManager.damage(this.touchDamage);
+ } else{
+ this.damagePerTickCount--;
+ if(this.damagePerTickCount <= 0){
+ this.damagePerTickCount = this.damagePerTickBase;
+ }
+ }
+ }
EnemyCharacterClass.base.prototype.tick.apply(this);
- }
+ },
+ isCollided : function(obj, x, y)
+ {
+ //MovableStageObjectが(x, y)のとき相手のobjと衝突するか判定
+ var retv = OperatedCharacterClass.prototype.isCollided.apply(this, arguments);
+ if(obj == this.ownerStage.userControlledCharacter){
+ if(retv){
+ this.damaging = true;
+ } else{
+ this.damaging = false;
+ this.damagePerTickCount = this.damagePerTickBase;
+ }
+ }
+ return retv
+ },
});
//\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.debugMode = false;
}.extend(ItemClass, {
draw: function(x, y){
this.ownerStage.mainContext.globalAlpha = this.opacity;
this.ownerStage.mainContext.drawImage(this.image, x, y, 32, 32);
this.ownerStage.mainContext.globalAlpha = 1.0;
+ if(this.debugMode){
+ //\8ec\82è\8eæ\93¾\89ñ\90\94\82ð\95\\8e¦
+ 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.times, x, y - 20);
+ this.ownerStage.mainContext.restore();
+ }
},
debugDraw: function(x, y){
//\8fÕ\93Ë\83}\83b\83v\82É\95`\89æ
},
draw: function(){
this.drawBackground();
-
this.drawAsPoint(0, 0);
},
drawAsPoint: function(x, y){
return true;
},
collideJudge: function(obj, x, y, items){
+ //obj\82Ì\8fÕ\93Ë\8fó\91Ô\82ð\92²\82×\82é\81B
+ //\83A\83C\83e\83\80\82ð\8eæ\93¾\82·\82é\82©\94Û\82©
var gainItem = items instanceof Array;
var retv = false;
this.eachStageObject(function(f){
{
if(obj.isCollided(f, 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(gainItem)
{
+ //\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) return true;
}
items.push(f);
}
- }else
- {
+ } else{
+ //\8fÕ\93Ë\82µ\82½
retv = true;
return true;
- //return false;
}
}
}
return retv;
},
moveTo : function(obj, x, y){
+ //(x,y)\82Éobj\82ð\88Ú\93®\82µ\82æ\82¤\82Æ\8e\8e\82Ý\82é
//\93\96\82½\82è\94»\92è\8f\88\97\9d
var sx = obj.origin.x, sy = obj.origin.y;
var lx = x - sx, ly = y - sy;
- if(lx == 0 && ly == 0) return;
- var dx, dy, ct;
- var collideDirection = 0; //\89º\88Ê4bit : \8fã \89º \8d¶ \89E
- ct = Math.max(Math.abs(lx), Math.abs(ly));
- dx = lx / ct; dy = ly / ct;
- var fx = dx == 0, fy = dy == 0;
- var ex = sx, ey = sy;
+ if(lx == 0 && ly == 0){
+ //\88Ú\93®\8b\97\97£\82ª0\82Å\82 \82ê\82Î\82Ç\82±\82É\82à\8fÕ\93Ë\82µ\82È\82¢\82Ì\82Å\81A\88Ú\93®\82¹\82¸\82É\95Ô\82é
+ return 0;
+ }
+ var collideDirection = 0;//\89º\88Ê4bit : \8fã \89º \8d¶ \89E
+ var ct = Math.max(Math.abs(lx), Math.abs(ly));
+ var dx = lx / ct;
+ var dy = ly / ct;
+ var fx = (dx == 0);
+ var fy = (dy == 0);
+ var ex = sx;
+ var ey = sy;
var gotItems = [];
var caterpillar = Math.abs(obj.caterpillar * dx);
- for(var i = 0; i < ct && !(fx && fy); i++)
- {
- //\89¼\82É\82¨\82¢\82Ä\82Ý\82é\8dÀ\95W
- //var ex = fx ? rx : sx + dx * i, ey = fy ? ry : sy + dy * i;
-
- if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems))
- {
- if(this.collideJudge(obj, ex + dx, ey - caterpillar, gotItems))
- {
+ for(var i = 0; i < ct; i++){
+ if(!fx && this.collideJudge(obj, ex + dx, ey, gotItems)){
+ if(this.collideJudge(obj, ex + dx, ey - caterpillar, gotItems)){
fx = true;
collideDirection |= (dx > 0 ? 1 : 2);
- }else
- {
+ } else{
ey -= caterpillar;
}
}
-
- if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems))
- {
+ if(!fy && this.collideJudge(obj, ex, ey + dy, gotItems)){
fy = true;
collideDirection |= (dy > 0 ? 4 : 8);
}
-
- if(!fx) ex += dx;
- if(!fy) ey += dy;
- if(fx && fy) break;
+ if(!fx){
+ ex += dx;
+ }
+ if(!fy){
+ ey += dy;
+ }
+ if(fx && fy){
+ break;
+ }
}
+ //\88Ú\93®
obj.origin.x = ex;
obj.origin.y = ey;
var item = gotItems[i];
if(item.itemAttacked)
{
- //\83A\83C\83e\83\80\82ð\8eæ\93¾\82µ\82½\82Æ\82«\82Ì\8f\88\97\9d\82ð\8cÄ\82Ô(\92N\82ª\8eæ\93¾\82µ\82½\82©\81A\8eæ\93¾\82µ\82½\93z\82Ì\8c»\8dÝ\88Ê\92u\82ð\93n\82·\81j
+ //\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);
}
}
}.extend(BlockClass, {
judgeCollideRange: function(x1, y1, x2, y2){
-
+ //isPhantom\82É\8aÖ\8cW\82È\82\81A\8fÕ\93Ë\94Í\88Í\82ª\8fd\82È\82é\82©\82Ç\82¤\82©\82ð\92²\82×\82é\81B
+ // 1 - - +
+ // | |
+ // | |
+ // + - - 2
//\83f\83o\83b\83O\8fî\95ñ
this.x1 = x1;
this.y2 = y2;
if(this.collisionLeftHeight != this.collisionRightHeight)
{
- return this.crossLineJudge(x1,y2,x2,y2,this.origin.x, this.origin.y + this.collisionLeftHeight, this.origin.x + this.size.x + 1, this.origin.y + this.collisionRightHeight);
- }else
- {
- //\8d\82\82³\82ª\93\99\82µ\82¢(\82©\82Ù\82Ú\93\99\82µ\82¢)\8e\9e\82Í\95Ó\82è\94»\92è\82É\98R\82ê\82Ä\82µ\82Ü\82¢\90³\8fí\82É\94»\92è\82Å\82«\82È\82¢
- //\82·\82È\82í\82¿\81A\82±\82Ì\83v\83\8d\83O\83\89\83\80\82¾\82ÆLH\82ÆRH\82Ì\92l\82ª\8bß\82¢\82¯\82Ç\93\99\82µ\82\82È\82¢\82Æ\82«\82É\83o\83O\82é\81B
- return x2 >= this.origin.x && x1 < this.origin.x + this.size.x && y2 >= this.origin.y + this.collisionLeftHeight && y1 < this.origin.y + this.size.y;
+ return this.crossLineJudge(x1, y2 - 1, x2, y2 - 1,
+ this.origin.x, this.origin.y + this.collisionLeftHeight,
+ this.origin.x + this.size.x - 1, this.origin.y + this.collisionRightHeight);
+ } else{
+ //\83`\83F\83b\83N\82·\82é\93ñ\82Â\82Ì\90ü\95ª\82ª\95½\8ds\82¾\82Æ\93\96\82½\82è\94»\92è\82É\98R\82ê\82é\82Ì\82Å\81A\93\96\82½\82è\94»\92è\82ª\90\85\95½\82È\8fê\8d\87\82Í\95Ê\82Ì\8e®\82ð\97\98\97p\82·\82é\81B
+ return x2 >= this.origin.x &&
+ x1 < this.origin.x + this.size.x - 1 &&
+ y2 >= this.origin.y + this.collisionLeftHeight &&
+ y1 < this.origin.y + this.size.y - 1;
}
},
crossLineJudge: function(p1x, p1y, p2x, p2y, q1x, q1y, q2x, q2y){
if(p1x >= p2x)
{
- if((p1x < q1x && p1x < q2x) || (p2x > q1x && p2x > q2x)) return false;
- }else
- {
- if((p2x < q1x && p2x < q2x) || (p1x > q1x && p1x > q2x)) return false;
+ if((p1x < q1x && p1x < q2x) || (p2x > q1x && p2x > q2x)){
+ return false;
+ }
+ } else{
+ if((p2x < q1x && p2x < q2x) || (p1x > q1x && p1x > q2x)){
+ return false;
+ }
}
if(p1y >= p2y)
{
- if((p1y < q1y && p1y < q2y) || (p2y > q1y && p2y > q2y)) return false;
- }else
- {
- if((p2y < q1y && p2y < q2y) || (p1y > q1y && p1y > q2y)) return false;
+ if((p1y < q1y && p1y < q2y) || (p2y > q1y && p2y > q2y)){
+ return false;
+ }
+ } else{
+ if((p2y < q1y && p2y < q2y) || (p1y > q1y && p1y > q2y)){
+ return false;
+ }
}
- return !((((p1x - p2x)*(q1y-p1y)+(p1y-p2y)*(p1x-q1x))*
- ((p1x-p2x)*(q2y-p1y)+(p1y-p2y)*(p1x-q2x))>0) ||
- (((q1x - q2x)*(p1y-q1y)+(q1y-q2y)*(q1x-p1x))*
- ((q1x-q2x)*(p2y-q1y)+(q1y-q2y)*(q1x-p2x))>0));
-
+ return !((((p1x - p2x)*(q1y-p1y)+(p1y-p2y)*(p1x-q1x))*((p1x-p2x)*(q2y-p1y)+(p1y-p2y)*(p1x-q2x))>0) ||
+ (((q1x - q2x)*(p1y-q1y)+(q1y-q2y)*(q1x-p1x))*((q1x-q2x)*(p2y-q1y)+(q1y-q2y)*(q1x-p2x))>0));
//\8eQ\8dl http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/IntersectionEX.htm
},
draw : function(x, y){
this.ownerStage.collisionMapContext.stroke();
this.ownerStage.collisionMapContext.restore();
},
+ isCollided : function(obj, x, y)
+ {
+ //\8e©\95ª\82ª(x, y)\82Ì\82Æ\82«\81A\91\8a\8eèobj\82Æ\8fÕ\93Ë\82·\82é\82©\94»\92è
+ if(!this.isPhantom && obj.judgeCollideRange){
+ return obj.judgeCollideRange(x + this.collisionMarginLeft,
+ y + this.collisionMarginTop,
+ x + this.size.x - 1 - this.collisionMarginRight,
+ y + this.size.y - 1 - this.collisionMarginBottom);
+ }
+ return false;
+ },
//\83u\83\8d\83b\83N\82Ì\93\96\82½\82è\94»\92è\97Ì\88æ\82ð\95Ï\8dX\82·\82é\82½\82ß\82É\82Í\82±\82Ì\8aÖ\90\94\82ð\83I\81[\83o\81[\83\89\83C\83h\82·\82é
//\88ø\90\94\82É\82Í\81A\93\96\82½\82è\82ð\8am\82©\82ß\82é\97v\91f\82Ì\93\96\82½\82è\94»\92è\97Ì\88æ\82Ì 1:\8d¶\8fã\8b÷ 2: \89E\89º\8b÷\82Ì\8dÀ\95W\82ð\8ew\92è
- //MovableStageObject.isCollided\82©\82ç\8cÄ\82Î\82ê\82é
+ //isCollided\82©\82ç\8cÄ\82Î\82ê\82é
// 1 - - +
// | |
// | |
// + - - 2
judgeCollideRange: function(x1, y1, x2, y2){
- return !this.isPhantom &&
- x2 >= this.origin.x + this.collisionMarginLeft &&
+ //isPhantom\82É\8aÖ\8cW\82È\82\81A\8fÕ\93Ë\94Í\88Í\82ª\8fd\82È\82é\82©\82Ç\82¤\82©\82ð\92²\82×\82é\81B
+ return x2 >= this.origin.x + this.collisionMarginLeft &&
x1 <= this.origin.x + this.size.x - 1 - this.collisionMarginRight &&
y2 >= this.origin.y + this.collisionMarginTop &&
y1 <= this.origin.y + this.size.y - 1 - this.collisionMarginBottom;
draw : function(){
this.gContext.fillStyle = "rgba(255,255,255,0.25)";
+ this.gContext.clearRect(this.gContext, 0, 0, this.wCanvas.width, this.wCanvas.height);
strokeRect(this.gContext, 0, 0, this.wCanvas.width, this.wCanvas.height);
fillRect(this.gContext, 0, 0, this.wCanvas.width, this.wCanvas.height);
drawText(this.gContext, this.manager.userManager.getUserNameByUID(this.manager.userID), 4, 4);
drawText(this.gContext, "HP :", 24, 24);
- this.gContext.fillStyle = "rgba(255,200,200,0.5)";
+ this.gContext.fillStyle = "rgba(255,200,200,1)";
fillRect(this.gContext, 70, 32, (this.wCanvas.width - 100) * (this.manager.userManager.HP / this.manager.userManager.max_HP), 10);
strokeRect(this.gContext, 70, 32, this.wCanvas.width - 100, 10);
},
margin-bottom: -36px;
overflow: hidden;
}
-
+textarea {
+ font-family: Consolas, 'Courier New', Courier, Monaco, monospace;
+ font-size: 12px;
+ line-height: 1.2;
+}
+
</style>
<script type="text/javascript">