第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

碰撞僅適用于西側(cè)和北側(cè)

碰撞僅適用于西側(cè)和北側(cè)

富國滬深 2021-06-28 09:59:53
基本上我有一個(gè)需要與外星人相撞的宇宙飛船的圖像。然而,外星人只檢測到西側(cè)和北側(cè)的碰撞。我希望它在圖像的所有側(cè)面碰撞。if (ay >= spy && ay <= spy + spaceshipImage.height // North side    ||  spy >= ay && spy <= ay + alienImage.height // South side) {  if (spx + alienImage.width >= ax && spx + alienImage.height <= ax + alienImage.height // West side _+    ||    spx >= ax && spx <= ax + alienImage.width // East side _+  ) {    slives = slives - 1;    ax = Math.floor(Math.random() * (canvasWidth2 - alienImage.width));    ay = -100  }}
查看完整描述

1 回答

?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

您的算法沒有考慮 shaceship 圖像尺寸的尺寸。至少不是所有情況。


這是一個(gè)修改了檢測程序的示例:


spaceshipImage = {};

spaceshipImage.height = 10;

spaceshipImage.width = 10;

alienImage = {};

alienImage.width = 20;

alienImage.height = 20;

ay = 50;

ax = 50;

spx = 70;

spy = 60;


var canvas = document.getElementById("canvas")

var context = canvas.getContext("2d");

context.fillStyle = "#ff0000"

context.fillRect(spx, spy, spaceshipImage.width, spaceshipImage.height)

context.fillStyle = "#00ff00"

context.fillRect(ax, ay, alienImage.width, alienImage.height)

if (spx + spaceshipImage.width >= ax && spx <= ax + alienImage.width && spy + spaceshipImage.height >= ay && spy <= ay + alienImage.height) {

  console.log("hit");

}

<canvas id="canvas"></canvas>


查看完整回答
反對 回復(fù) 2021-07-08
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)