2 つの fill.Rect 関数間の衝突を検出します。
P粉145543872
P粉145543872 2023-09-15 13:26:06
0
1
758

1 人のプレイヤーが矢印キーで制御され、もう 1 人のプレイヤーが WSAD キーで制御されるゲームがあります。 600x600 のキャンバスにマップを設定しており、ゲームの塗りつぶしに 2 人のプレイヤー間の衝突を追加したいと考えています。2 人のプレイヤーが特定の半径内にいるときにプログラムを終了するか、「ゲーム終了」のようなテキストを表示します。

以下は私の js、HTML、Css コードです (コード スニペットを表示するには、「全画面表示」に移動する必要があります):

リーリー リーリー リーリー

P粉145543872
P粉145543872

全員に返信(1)
P粉752812853

I've wrote you a function that checks the collision.

We do that by first checking if the left edge of rect1 is further to the right than the right edge of rect2. We also check if the right edge of rect1 is further to the left than the left edge of rect2.

Same thing for bottom edge.

if all of those are false, the rectangles must be overlapping.

const checkCollision = (rect1, rect2) => {
  return rect1.x < rect2.x + rect2.w &&rect1.x + rect1.w > rect2.x &&rect1.y < rect2.y + rect2.h &&rect1.y + rect1.h > rect2.y 
}
いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!