/// <summary> /// 地形との衝突など簡易な判定 /// </summary> public static void CDatTerrain(Object myObject, Block targetObject) { targetObject.isHit = false; if (targetObject.position.X + targetObject.width < myObject.position.X) { } else if (myObject.position.X + myObject.width < targetObject.position.X) { } else if (targetObject.position.Y + targetObject.height < myObject.position.Y) { } else if (myObject.position.Y + myObject.height < targetObject.position.Y) { } else { // 当たりあり targetObject.isHit = true; // 当たり判定処理 // 下に移動中 if (myObject.speed.Y > 0 && !targetObject.isUnder) { if (targetObject.position.X + targetObject.width > myObject.position.X && targetObject.position.X < myObject.position.X + myObject.width) { //座標を指定しないとBlockに接してジャンプしたときにギリギリで乗ってしまう // ブロックの上端 if (targetObject.position.Y + targetObject.height - myObject.position.Y < targetObject.maxLength) { myObject.speed.Y = 0; targetObject.position.Y = myObject.position.Y - targetObject.height; // 上に補正 myObject.jumpCount = 0; //myObject.isJumping = false; // 着地したらJumpできるように targetObject.ontop = true; } } }// 上に移動中 else if (myObject.speed.Y < 0 && !targetObject.isOn) { if (targetObject.position.X + targetObject.width > myObject.position.X && targetObject.position.X < myObject.position.X + myObject.width) { // ブロックの下端 if (myObject.position.Y + myObject.height - targetObject.position.Y < targetObject.maxLength) { myObject.speed.Y = 0; targetObject.position.Y = myObject.position.Y + myObject.height; // 下に補正 } } } // 右に移動中 //if (myObject.scalarSpeed/* + System.Math.Abs(speed.X)*/ > 0) if (myObject.speed.X /*- (game.isScrolled ? targetObject.scalarSpeed : 0)*/ > 0) {//(stage.game.isScrolled ? 0 : this.scalarSpeed)) if (targetObject.position.Y > myObject.position.Y - targetObject.height && targetObject.position.Y < myObject.position.Y + myObject.height) { // ブロックの左端 if ((targetObject.position.X + targetObject.width) - myObject.position.X < targetObject.maxLength) { targetObject.position.X = myObject.position.X - targetObject.width; // 左に補正 targetObject.onleft = true; } } } // 左に移動中 else { //if (myObject.scalarSpeed < 0) if (targetObject.position.Y + targetObject.height > myObject.position.Y && targetObject.position.Y < myObject.position.Y + myObject.height) { // ブロックの右端 if ((myObject.position.X + myObject.width) - targetObject.position.X < targetObject.maxLength) { targetObject.position.X = myObject.position.X + myObject.width; // 右に補正 targetObject.onright = true; } } } } }
public static void Square(Block myObject, Object targetObject) { }
public static void CalculateVectors4(Block myObject, Object targetObject) { // targetObjectの矩形の判定に使う点を求める defPositionVector[0] = targetObject.position; defPositionVector[1] = defPositionVector[0] + new Vector2(targetObject.width, 0); defPositionVector[2] = defPositionVector[0] + new Vector2(targetObject.width, targetObject.height); defPositionVector[3] = defPositionVector[0] + new Vector2(targetObject.width / 2, targetObject.height); defPositionVector[4] = defPositionVector[0] + new Vector2(0, targetObject.height); // 直角三角形の辺ベクトルを計算(時計回り) /* __________ [0]End * [0]Start([3]End) | | * | | * | | * | | * | | * [2]End |__________|[1]End */ myObject.sideVectorStart[0] = myObject.position + new Vector2(0, myObject.height); // 斜面下側 myObject.sideVectorEnd[0] = myObject.position + new Vector2(myObject.width, 0); // 斜面上側 myObject.sideVectorStart[1] = myObject.sideVectorEnd[0]; // 右端上側 myObject.sideVectorEnd[1] = myObject.position + new Vector2(myObject.width, myObject.height); // 右端下側 myObject.sideVectorStart[2] = myObject.sideVectorEnd[1]; // 下端右側 myObject.sideVectorEnd[2] = myObject.sideVectorStart[0]; // 下端左側 // foreachは割り当てには使えない for (int i = 0; i < myObject.sideVector.Length; i++) myObject.sideVector[i] = myObject.sideVectorEnd[i] - myObject.sideVectorStart[i]; }